libPlayingWithFusion  2020.02.24
Playing With Fusion driver library for FRC roboRIO
CANVenom.h
1 #pragma once
2 
3 #include "frc/MotorSafety.h"
4 #include "frc/SpeedController.h"
5 #include "frc/smartdashboard/SendableBase.h"
6 #include "frc/smartdashboard/SendableBuilder.h"
7 #include "CANVenomApi.h"
8 
9 namespace frc {
10 class CANVenomImpl;
11 
21 class CANVenom : public MotorSafety, public SpeedController, public SendableBase {
22  public:
23  enum ControlMode {
27  kDisabled = 0,
28 
33 
38 
43 
48 
57 
71 
77  };
78 
84  kCoast = 0,
85 
90  kBrake = 1
91  };
92 
93  enum FaultFlag {
97  kNone = 0,
98 
104 
109 
115 
120 
125 
130  kBadMode = 32,
131 
137 
142 
147 
152  kReset = 512
153  };
154 
155 
160  kInit = 0,
161 
166  kRunning = 1,
167 
174 
183 
203 
209  kDone = 5
210  };
211 
212 
224  explicit CANVenom(uint8_t motorID);
228  virtual ~CANVenom();
229 
230  // Delete Copy constructor and assignment operator
231  CANVenom(const CANVenom&) =delete;
232  CANVenom& operator=(const CANVenom&) =delete;
233 
234  // Use default Move constructor and assignment operator
235  CANVenom(CANVenom&&) =default;
236  CANVenom& operator=(CANVenom&&) =default;
237 
238 
249  virtual void StopMotor() override;
250 
251 
257  virtual void GetDescription(wpi::raw_ostream& desc) const override;
258 
259 
270  virtual void Set(double command) override;
271 
272 
278  virtual double Get() const override;
279 
280 
296  virtual void SetInverted(bool isInverted) override;
297 
298 
304  virtual bool GetInverted() const override;
305 
306 
317  virtual void Disable() override;
318 
319 
323  void Enable();
324 
325 
337  virtual void PIDWrite(double output) override;
338 
339 
344  virtual void InitSendable (SendableBuilder &builder);
345 
346 
383  void SetCommand(ControlMode mode, double command);
384 
385 
428  void SetCommand(ControlMode mode, double command, double kF, double b);
429 
430 
438  void Follow(CANVenom &leadVenom);
439 
440 
450  bool GetFwdLimitSwitchActive() const;
451 
452 
462  bool GetRevLimitSwitchActive() const;
463 
464 
474  void EnableLimitSwitches(bool fwdLimitSwitchEnabled, bool revLimitSwitchEnabled);
475 
476 
484  void IdentifyMotor();
485 
486 
490  void ResetPosition();
491 
497  void SetPosition(double newPosition);
498 
508  uint16_t GetNumAvaliableMotionProfilePoints() const;
509 
510 
520  uint16_t GetCurrentMotionProfilePoint() const;
521 
522 
531  double GetMotionProfilePositionTarget() const;
532 
533 
542  double GetMotionProfileSpeedTarget() const;
543 
544 
553  bool GetMotionProfileIsValid() const;
554 
565 
573 
574 
591  void AddMotionProfilePoint(double time, double speed, double position);
592 
593 
603  void CompleteMotionProfilePath(double time, double position);
604 
605 
612  void ExecutePath();
613 
614 
621  uint32_t GetFirmwareVersion() const;
622 
623 
630  uint32_t GetSerialNumber() const;
631 
632 
638  double GetBusVoltage() const;
639 
640 
646  double GetOutputVoltage() const;
647 
648 
654  double GetDutyCycle() const;
655 
656 
667  double GetOutputCurrent() const;
668 
669 
675  double GetTemperature() const;
676 
677 
684  double GetAuxVoltage() const;
685 
686 
692  double GetSpeed() const;
693 
694 
700  double GetPosition() const;
701 
702 
716  double GetPIDTarget() const;
717 
718 
725  double GetKF() const;
726 
727 
734  double GetB() const;
735 
736 
743  double GetKP() const;
744 
745 
752  double GetKI() const;
753 
754 
761  double GetKD() const;
762 
763 
771  double GetMinPILimit() const;
772 
773 
781  double GetMaxPILimit() const;
782 
783 
790  double GetMaxSpeed() const;
791 
792 
805  double GetMaxAcceleration() const;
806 
807 
818  double GetMaxJerk() const;
819 
820 
826  ControlMode GetControlMode() const;
827 
828 
835 
836 
844 
845 
852  FaultFlag GetActiveFaults() const;
853 
863  FaultFlag GetLatchedFaults() const;
864 
868  void ClearLatchedFaults();
869 
886  void SetPID(double kP, double kI, double kD, double kF, double b);
887 
888 
894  void SetKF(double kF);
895 
896 
902  void SetB(double b);
903 
904 
910  void SetKP(double kP);
911 
912 
918  void SetKI(double kI);
919 
920 
926  void SetKD(double kD);
927 
928 
936  void SetMinPILimit(double limit);
937 
938 
946  void SetMaxPILimit(double limit);
947 
948 
955  void SetMaxSpeed(double limit);
956 
957 
970  void SetMaxAcceleration(double limit);
971 
972 
983  void SetMaxJerk(double limit);
984 
985 
998  void SetControlMode(ControlMode controlMode);
999 
1000 
1007  void SetBrakeCoastMode(BrakeCoastMode brakeCoastMode);
1008 
1009 
1010  private:
1011  CANVenom_t *m_canVenomHandle;
1012  int m_motorID;
1013 };
1014 
1015 }
frc::CANVenom::GetOutputVoltage
double GetOutputVoltage() const
Definition: CANVenom.cpp:179
frc::CANVenom::SetPID
void SetPID(double kP, double kI, double kD, double kF, double b)
Definition: CANVenom.cpp:275
frc::CANVenom::kHighTemperature
Definition: CANVenom.h:119
frc::CANVenom::GetFirmwareVersion
uint32_t GetFirmwareVersion() const
Definition: CANVenom.cpp:143
frc::CANVenom::GetLatchedFaults
FaultFlag GetLatchedFaults() const
Definition: CANVenom.cpp:267
frc::CANVenom::GetMaxAcceleration
double GetMaxAcceleration() const
Definition: CANVenom.cpp:243
frc::CANVenom::SetMaxPILimit
void SetMaxPILimit(double limit)
Definition: CANVenom.cpp:303
frc::CANVenom::GetPosition
double GetPosition() const
Definition: CANVenom.cpp:203
frc::CANVenom::SetInverted
virtual void SetInverted(bool isInverted) override
Definition: CANVenom.cpp:54
frc::CANVenom::kFollowTheLeader
Definition: CANVenom.h:70
frc::CANVenom::kVoltageControl
Definition: CANVenom.h:76
frc::CANVenom::SetMaxJerk
void SetMaxJerk(double limit)
Definition: CANVenom.cpp:315
frc::CANVenom::SetPosition
void SetPosition(double newPosition)
Definition: CANVenom.cpp:122
frc::CANVenom::kNone
Definition: CANVenom.h:97
frc::CANVenom::EnableLimitSwitches
void EnableLimitSwitches(bool fwdLimitSwitchEnabled, bool revLimitSwitchEnabled)
Definition: CANVenom.cpp:83
frc::CANVenom::Set
virtual void Set(double command) override
Definition: CANVenom.cpp:30
frc::CANVenom::GetSpeed
double GetSpeed() const
Definition: CANVenom.cpp:199
frc::CANVenom::ExecutePath
void ExecutePath()
Definition: CANVenom.cpp:139
frc::CANVenom::kPositionControl
Definition: CANVenom.h:47
frc::CANVenom::kBadLeaderID
Definition: CANVenom.h:114
frc::CANVenom::GetRevLimitSwitchActive
bool GetRevLimitSwitchActive() const
Definition: CANVenom.cpp:79
frc::CANVenom::GetMaxPILimit
double GetMaxPILimit() const
Definition: CANVenom.cpp:235
frc::CANVenom::GetMaxSpeed
double GetMaxSpeed() const
Definition: CANVenom.cpp:239
frc::CANVenom::GetBusVoltage
double GetBusVoltage() const
Definition: CANVenom.cpp:175
frc::CANVenom::ResetPosition
void ResetPosition()
Definition: CANVenom.cpp:118
frc::CANVenom::InitSendable
virtual void InitSendable(SendableBuilder &builder)
Definition: CANVenom.cpp:87
frc::CANVenom::BrakeCoastMode
BrakeCoastMode
Definition: CANVenom.h:79
frc::CANVenom::SetMinPILimit
void SetMinPILimit(double limit)
Definition: CANVenom.cpp:299
frc::CANVenom::kCoast
Definition: CANVenom.h:84
frc::CANVenom::SetControlMode
void SetControlMode(ControlMode controlMode)
Definition: CANVenom.cpp:319
frc::CANVenom::GetCurrentMotionProfilePoint
uint16_t GetCurrentMotionProfilePoint() const
Definition: CANVenom.cpp:155
frc::CANVenom::GetInverted
virtual bool GetInverted() const override
Definition: CANVenom.cpp:58
frc::CANVenom::kBadMode
Definition: CANVenom.h:130
frc::CANVenom::CANVenom
CANVenom(uint8_t motorID)
Definition: CANVenom.cpp:7
frc::CANVenom::GetBrakeCoastMode
BrakeCoastMode GetBrakeCoastMode() const
Definition: CANVenom.cpp:259
frc::CANVenom::GetMotionProfileState
MotionProfileState GetMotionProfileState() const
Definition: CANVenom.cpp:171
frc::CANVenom::kBrake
Definition: CANVenom.h:90
frc::CANVenom::GetTemperature
double GetTemperature() const
Definition: CANVenom.cpp:191
frc::CANVenom::GetMaxJerk
double GetMaxJerk() const
Definition: CANVenom.cpp:247
frc::CANVenom::SetKD
void SetKD(double kD)
Definition: CANVenom.cpp:295
frc::CANVenom::kErrBufferInvalid
Definition: CANVenom.h:202
frc::CANVenom::SetBrakeCoastMode
void SetBrakeCoastMode(BrakeCoastMode brakeCoastMode)
Definition: CANVenom.cpp:323
frc::CANVenom::SetCommand
void SetCommand(ControlMode mode, double command)
Definition: CANVenom.cpp:35
frc::CANVenom::kSpeedControl
Definition: CANVenom.h:42
frc::CANVenom::IdentifyMotor
void IdentifyMotor()
Definition: CANVenom.cpp:114
frc::CANVenom::GetKP
double GetKP() const
Definition: CANVenom.cpp:219
frc::CANVenom::GetMotionProfileIsValid
bool GetMotionProfileIsValid() const
Definition: CANVenom.cpp:167
frc::CANVenom::SetMaxSpeed
void SetMaxSpeed(double limit)
Definition: CANVenom.cpp:307
frc::CANVenom::SetKI
void SetKI(double kI)
Definition: CANVenom.cpp:291
frc::CANVenom::GetPIDTarget
double GetPIDTarget() const
Definition: CANVenom.cpp:207
frc::CANVenom::FaultFlag
FaultFlag
Definition: CANVenom.h:93
frc::CANVenom::GetActiveFaults
FaultFlag GetActiveFaults() const
Definition: CANVenom.cpp:263
frc::CANVenom::GetKI
double GetKI() const
Definition: CANVenom.cpp:223
frc::CANVenom::GetMinPILimit
double GetMinPILimit() const
Definition: CANVenom.cpp:231
frc::CANVenom::kProportional
Definition: CANVenom.h:32
frc::CANVenom::kNoLeaderHeartbeat
Definition: CANVenom.h:108
frc::CANVenom
Definition: CANVenom.h:21
frc::CANVenom::Follow
void Follow(CANVenom &leadVenom)
Definition: CANVenom.cpp:45
frc::CANVenom::GetAuxVoltage
double GetAuxVoltage() const
Definition: CANVenom.cpp:195
frc::CANVenom::kMotionProfile
Definition: CANVenom.h:56
frc::CANVenom::GetKF
double GetKF() const
Definition: CANVenom.cpp:211
frc::CANVenom::~CANVenom
virtual ~CANVenom()
Definition: CANVenom.cpp:16
frc::CANVenom::GetOutputCurrent
double GetOutputCurrent() const
Definition: CANVenom.cpp:187
frc::CANVenom::ClearLatchedFaults
void ClearLatchedFaults()
Definition: CANVenom.cpp:271
frc::CANVenom::kErrBufferCleared
Definition: CANVenom.h:173
frc::CANVenom::Disable
virtual void Disable() override
Definition: CANVenom.cpp:62
frc::CANVenom::ControlMode
ControlMode
Definition: CANVenom.h:23
frc::CANVenom::MotionProfileState
MotionProfileState
Definition: CANVenom.h:156
frc::CANVenom::GetMotionProfilePositionTarget
double GetMotionProfilePositionTarget() const
Definition: CANVenom.cpp:159
frc::CANVenom::kForwardLimit
Definition: CANVenom.h:141
frc::CANVenom::kHighCurrent
Definition: CANVenom.h:124
frc::CANVenom::kNoHeartbeat
Definition: CANVenom.h:103
frc::CANVenom::GetControlMode
ControlMode GetControlMode() const
Definition: CANVenom.cpp:251
frc::CANVenom::GetFwdLimitSwitchActive
bool GetFwdLimitSwitchActive() const
Definition: CANVenom.cpp:75
frc::CANVenom::kCurrentControl
Definition: CANVenom.h:37
frc::CANVenom::GetDescription
virtual void GetDescription(wpi::raw_ostream &desc) const override
Definition: CANVenom.cpp:25
frc::CANVenom::StopMotor
virtual void StopMotor() override
Definition: CANVenom.cpp:21
frc::CANVenom::PIDWrite
virtual void PIDWrite(double output) override
Definition: CANVenom.cpp:70
frc::CANVenom::SetMaxAcceleration
void SetMaxAcceleration(double limit)
Definition: CANVenom.cpp:311
frc::CANVenom::kReverseLimit
Definition: CANVenom.h:146
frc::CANVenom::GetB
double GetB() const
Definition: CANVenom.cpp:215
frc::CANVenom::kErrBufferUnderflow
Definition: CANVenom.h:182
frc::CANVenom::GetKD
double GetKD() const
Definition: CANVenom.cpp:227
frc::CANVenom::SetB
void SetB(double b)
Definition: CANVenom.cpp:283
frc::CANVenom::SetKF
void SetKF(double kF)
Definition: CANVenom.cpp:279
frc::CANVenom::AddMotionProfilePoint
void AddMotionProfilePoint(double time, double speed, double position)
Definition: CANVenom.cpp:131
frc::CANVenom::Enable
void Enable()
Definition: CANVenom.cpp:66
frc::CANVenom::ClearMotionProfilePoints
void ClearMotionProfilePoints()
Definition: CANVenom.cpp:126
frc::CANVenom::kDuplicateID
Definition: CANVenom.h:136
frc::CANVenom::kInit
Definition: CANVenom.h:160
frc::CANVenom::kRunning
Definition: CANVenom.h:166
frc::CANVenom::kDisabled
Definition: CANVenom.h:27
frc::CANVenom::GetActiveControlMode
ControlMode GetActiveControlMode() const
Definition: CANVenom.cpp:255
frc::CANVenom::kReset
Definition: CANVenom.h:152
frc::CANVenom::SetKP
void SetKP(double kP)
Definition: CANVenom.cpp:287
frc::CANVenom::GetMotionProfileSpeedTarget
double GetMotionProfileSpeedTarget() const
Definition: CANVenom.cpp:163
frc::CANVenom::Get
virtual double Get() const override
Definition: CANVenom.cpp:49
frc::CANVenom::GetDutyCycle
double GetDutyCycle() const
Definition: CANVenom.cpp:183
frc::CANVenom::GetSerialNumber
uint32_t GetSerialNumber() const
Definition: CANVenom.cpp:147
frc::CANVenom::GetNumAvaliableMotionProfilePoints
uint16_t GetNumAvaliableMotionProfilePoints() const
Definition: CANVenom.cpp:151
frc::CANVenom::kDone
Definition: CANVenom.h:209
frc::CANVenom::CompleteMotionProfilePath
void CompleteMotionProfilePath(double time, double position)
Definition: CANVenom.cpp:135