2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2017-01-01 01:05:57 -07:00
|
|
|
/* Copyright (c) FIRST 2008-2017. All Rights Reserved. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
2016-01-02 03:02:34 -08:00
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2016-01-02 03:02:34 -08:00
|
|
|
|
2014-05-02 17:54:01 -04:00
|
|
|
#pragma once
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2017-06-25 09:05:49 -07:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
2016-05-25 22:38:11 -07:00
|
|
|
#include <memory>
|
2016-09-05 13:55:31 -07:00
|
|
|
#include <string>
|
2016-05-25 22:38:11 -07:00
|
|
|
|
2016-07-12 10:45:14 -07:00
|
|
|
#include "HAL/Types.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
#include "LiveWindow/LiveWindowSendable.h"
|
2016-05-20 17:30:37 -07:00
|
|
|
#include "SensorBase.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
#include "tables/ITableListener.h"
|
|
|
|
|
|
2016-11-01 22:33:12 -07:00
|
|
|
namespace frc {
|
|
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
/**
|
|
|
|
|
* Class implements the PWM generation in the FPGA.
|
2014-06-13 17:45:10 -04:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* The values supplied as arguments for PWM outputs range from -1.0 to 1.0. They
|
2016-05-20 17:30:37 -07:00
|
|
|
* are mapped to the hardware dependent values, in this case 0-2000 for the
|
|
|
|
|
* FPGA. Changes are immediately sent to the FPGA, and the update occurs at the
|
|
|
|
|
* next FPGA cycle. There is no delay.
|
2014-06-13 17:45:10 -04:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* As of revision 0.1.10 of the FPGA, the FPGA interprets the 0-2000 values as
|
|
|
|
|
* follows:
|
2014-12-29 14:09:37 -05:00
|
|
|
* - 2000 = maximum pulse width
|
|
|
|
|
* - 1999 to 1001 = linear scaling from "full forward" to "center"
|
|
|
|
|
* - 1000 = center value
|
|
|
|
|
* - 999 to 2 = linear scaling from "center" to "full reverse"
|
|
|
|
|
* - 1 = minimum pulse width (currently .5ms)
|
2013-12-15 18:30:16 -05:00
|
|
|
* - 0 = disabled (i.e. PWM output is held low)
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
class PWM : public SensorBase,
|
|
|
|
|
public ITableListener,
|
|
|
|
|
public LiveWindowSendable {
|
|
|
|
|
public:
|
|
|
|
|
enum PeriodMultiplier {
|
|
|
|
|
kPeriodMultiplier_1X = 1,
|
|
|
|
|
kPeriodMultiplier_2X = 2,
|
|
|
|
|
kPeriodMultiplier_4X = 4
|
|
|
|
|
};
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2016-09-06 00:01:45 -07:00
|
|
|
explicit PWM(int channel);
|
2015-06-25 15:07:55 -04:00
|
|
|
virtual ~PWM();
|
2016-07-10 17:47:44 -07:00
|
|
|
virtual void SetRaw(uint16_t value);
|
|
|
|
|
virtual uint16_t GetRaw() const;
|
2016-11-20 07:25:03 -08:00
|
|
|
virtual void SetPosition(double pos);
|
|
|
|
|
virtual double GetPosition() const;
|
|
|
|
|
virtual void SetSpeed(double speed);
|
|
|
|
|
virtual double GetSpeed() const;
|
2016-07-08 21:29:29 -07:00
|
|
|
virtual void SetDisabled();
|
2015-06-25 15:07:55 -04:00
|
|
|
void SetPeriodMultiplier(PeriodMultiplier mult);
|
|
|
|
|
void SetZeroLatch();
|
|
|
|
|
void EnableDeadbandElimination(bool eliminateDeadband);
|
2016-11-20 07:25:03 -08:00
|
|
|
void SetBounds(double max, double deadbandMax, double center,
|
|
|
|
|
double deadbandMin, double min);
|
2016-09-06 00:01:45 -07:00
|
|
|
void SetRawBounds(int max, int deadbandMax, int center, int deadbandMin,
|
|
|
|
|
int min);
|
2016-07-08 21:29:29 -07:00
|
|
|
void GetRawBounds(int32_t* max, int32_t* deadbandMax, int32_t* center,
|
|
|
|
|
int32_t* deadbandMin, int32_t* min);
|
2016-09-06 00:01:45 -07:00
|
|
|
int GetChannel() const { return m_channel; }
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
protected:
|
2015-08-13 23:17:19 -07:00
|
|
|
void ValueChanged(ITable* source, llvm::StringRef key,
|
|
|
|
|
std::shared_ptr<nt::Value> value, bool isNew) override;
|
2015-06-25 15:07:55 -04:00
|
|
|
void UpdateTable() override;
|
|
|
|
|
void StartLiveWindowMode() override;
|
|
|
|
|
void StopLiveWindowMode() override;
|
|
|
|
|
std::string GetSmartDashboardType() const override;
|
2015-07-29 16:48:04 -04:00
|
|
|
void InitTable(std::shared_ptr<ITable> subTable) override;
|
|
|
|
|
std::shared_ptr<ITable> GetTable() const override;
|
2014-05-02 17:54:01 -04:00
|
|
|
|
2015-11-23 00:46:05 -08:00
|
|
|
std::shared_ptr<ITable> m_table;
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
private:
|
2016-09-06 00:01:45 -07:00
|
|
|
int m_channel;
|
2016-07-09 00:24:26 -07:00
|
|
|
HAL_DigitalHandle m_handle;
|
2013-12-15 18:30:16 -05:00
|
|
|
};
|
2016-11-01 22:33:12 -07:00
|
|
|
|
|
|
|
|
} // namespace frc
|