libPlayingWithFusion 2022.01.12
Playing With Fusion driver library for FRC roboRIO
CANVenom.h
Go to the documentation of this file.
1#pragma once
2
3#include "frc/MotorSafety.h"
4#include "frc/motorcontrol/MotorController.h"
5#include "wpi/sendable/Sendable.h"
6#include "wpi/sendable/SendableHelper.h"
7#include "wpi/sendable/SendableBuilder.h"
8#include "CANVenomApi.h"
9
10namespace frc {
11class CANVenomImpl;
12
22class CANVenom : public MotorSafety, public MotorController, public wpi::Sendable, public wpi::SendableHelper<CANVenom> {
23 public:
29
34
39
44
49
58
72
78 };
79
85 kCoast = 0,
86
91 kBrake = 1
92 };
93
94 enum FaultFlag {
98 kNone = 0,
99
105
110
116
121
126
132
138
143
148
153 kReset = 512
154 };
155
156
161 kInit = 0,
162
168
175
184
204
210 kDone = 5
211 };
212
213
225 explicit CANVenom(uint8_t motorID);
229 virtual ~CANVenom();
230
231 // Delete Copy constructor and assignment operator
232 CANVenom(const CANVenom&) =delete;
233 CANVenom& operator=(const CANVenom&) =delete;
234
235 // Use default Move constructor and assignment operator
236 CANVenom(CANVenom&&) =default;
238
239
250 virtual void StopMotor() override;
251
252
258 virtual std::string GetDescription() const override;
259
260
271 virtual void Set(double command) override;
272
273
279 virtual double Get() const override;
280
281
297 virtual void SetInverted(bool isInverted) override;
298
299
305 virtual bool GetInverted() const override;
306
307
318 virtual void Disable() override;
319
320
324 void Enable();
325
326
338 virtual void PIDWrite(double output);
339
340
345 virtual void InitSendable (wpi::SendableBuilder &builder) override;
346
347
384 void SetCommand(ControlMode mode, double command);
385
386
429 void SetCommand(ControlMode mode, double command, double kF, double b);
430
431
439 void Follow(CANVenom &leadVenom);
440
441
451 bool GetFwdLimitSwitchActive() const;
452
453
463 bool GetRevLimitSwitchActive() const;
464
465
475 void EnableLimitSwitches(bool fwdLimitSwitchEnabled, bool revLimitSwitchEnabled);
476
477
485 void IdentifyMotor();
486
487
491 void ResetPosition();
492
498 void SetPosition(double newPosition);
499
509 uint16_t GetNumAvaliableMotionProfilePoints() const;
510
511
521 uint16_t GetCurrentMotionProfilePoint() const;
522
523
532 double GetMotionProfilePositionTarget() const;
533
534
543 double GetMotionProfileSpeedTarget() const;
544
545
554 bool GetMotionProfileIsValid() const;
555
566
574
575
592 void AddMotionProfilePoint(double time, double speed, double position);
593
594
604 void CompleteMotionProfilePath(double time, double position);
605
606
613 void ExecutePath();
614
615
622 uint32_t GetFirmwareVersion() const;
623
624
631 uint32_t GetSerialNumber() const;
632
633
639 double GetBusVoltage() const;
640
641
647 double GetOutputVoltage() const;
648
649
655 double GetDutyCycle() const;
656
657
668 double GetOutputCurrent() const;
669
670
676 double GetTemperature() const;
677
678
685 double GetAuxVoltage() const;
686
687
693 double GetSpeed() const;
694
695
701 double GetPosition() const;
702
703
717 double GetPIDTarget() const;
718
719
726 double GetKF() const;
727
728
735 double GetB() const;
736
737
744 double GetKP() const;
745
746
753 double GetKI() const;
754
755
762 double GetKD() const;
763
764
772 double GetMinPILimit() const;
773
774
782 double GetMaxPILimit() const;
783
784
791 double GetMaxSpeed() const;
792
793
806 double GetMaxAcceleration() const;
807
808
819 double GetMaxJerk() const;
820
821
828
829
836
837
845
846
854
865
869 void ClearLatchedFaults();
870
887 void SetPID(double kP, double kI, double kD, double kF, double b);
888
889
895 void SetKF(double kF);
896
897
903 void SetB(double b);
904
905
911 void SetKP(double kP);
912
913
919 void SetKI(double kI);
920
921
927 void SetKD(double kD);
928
929
937 void SetMinPILimit(double limit);
938
939
947 void SetMaxPILimit(double limit);
948
949
956 void SetMaxSpeed(double limit);
957
958
971 void SetMaxAcceleration(double limit);
972
973
984 void SetMaxJerk(double limit);
985
986
999 void SetControlMode(ControlMode controlMode);
1000
1001
1008 void SetBrakeCoastMode(BrakeCoastMode brakeCoastMode);
1009
1010
1011 private:
1012 CANVenom_t *m_canVenomHandle;
1013 int m_motorID;
1014};
1015
1016}
Definition: CANVenom.h:22
void ResetPosition()
Definition: CANVenom.cpp:118
virtual std::string GetDescription() const override
Definition: CANVenom.cpp:25
double GetPosition() const
Definition: CANVenom.cpp:203
void AddMotionProfilePoint(double time, double speed, double position)
Definition: CANVenom.cpp:131
CANVenom & operator=(const CANVenom &)=delete
FaultFlag GetActiveFaults() const
Definition: CANVenom.cpp:263
double GetKD() const
Definition: CANVenom.cpp:227
virtual void Disable() override
Definition: CANVenom.cpp:62
void Follow(CANVenom &leadVenom)
Definition: CANVenom.cpp:45
double GetAuxVoltage() const
Definition: CANVenom.cpp:195
virtual void InitSendable(wpi::SendableBuilder &builder) override
Definition: CANVenom.cpp:87
ControlMode GetActiveControlMode() const
Definition: CANVenom.cpp:255
uint16_t GetCurrentMotionProfilePoint() const
Definition: CANVenom.cpp:155
double GetBusVoltage() const
Definition: CANVenom.cpp:175
void SetB(double b)
Definition: CANVenom.cpp:283
FaultFlag GetLatchedFaults() const
Definition: CANVenom.cpp:267
void ClearLatchedFaults()
Definition: CANVenom.cpp:271
CANVenom(uint8_t motorID)
Definition: CANVenom.cpp:7
double GetOutputVoltage() const
Definition: CANVenom.cpp:179
double GetKI() const
Definition: CANVenom.cpp:223
void SetMaxJerk(double limit)
Definition: CANVenom.cpp:315
BrakeCoastMode GetBrakeCoastMode() const
Definition: CANVenom.cpp:259
MotionProfileState
Definition: CANVenom.h:157
@ kInit
Definition: CANVenom.h:161
@ kErrBufferUnderflow
Definition: CANVenom.h:183
@ kDone
Definition: CANVenom.h:210
@ kErrBufferCleared
Definition: CANVenom.h:174
@ kErrBufferInvalid
Definition: CANVenom.h:203
@ kRunning
Definition: CANVenom.h:167
void CompleteMotionProfilePath(double time, double position)
Definition: CANVenom.cpp:135
void SetPosition(double newPosition)
Definition: CANVenom.cpp:122
void SetPID(double kP, double kI, double kD, double kF, double b)
Definition: CANVenom.cpp:275
uint32_t GetFirmwareVersion() const
Definition: CANVenom.cpp:143
virtual void Set(double command) override
Definition: CANVenom.cpp:30
void SetKD(double kD)
Definition: CANVenom.cpp:295
double GetOutputCurrent() const
Definition: CANVenom.cpp:187
double GetMotionProfilePositionTarget() const
Definition: CANVenom.cpp:159
void ClearMotionProfilePoints()
Definition: CANVenom.cpp:126
bool GetRevLimitSwitchActive() const
Definition: CANVenom.cpp:79
void ExecutePath()
Definition: CANVenom.cpp:139
double GetKF() const
Definition: CANVenom.cpp:211
double GetMaxSpeed() const
Definition: CANVenom.cpp:239
bool GetFwdLimitSwitchActive() const
Definition: CANVenom.cpp:75
bool GetMotionProfileIsValid() const
Definition: CANVenom.cpp:167
FaultFlag
Definition: CANVenom.h:94
@ kBadMode
Definition: CANVenom.h:131
@ kHighTemperature
Definition: CANVenom.h:120
@ kNoLeaderHeartbeat
Definition: CANVenom.h:109
@ kNone
Definition: CANVenom.h:98
@ kDuplicateID
Definition: CANVenom.h:137
@ kNoHeartbeat
Definition: CANVenom.h:104
@ kForwardLimit
Definition: CANVenom.h:142
@ kHighCurrent
Definition: CANVenom.h:125
@ kReset
Definition: CANVenom.h:153
@ kReverseLimit
Definition: CANVenom.h:147
@ kBadLeaderID
Definition: CANVenom.h:115
double GetMaxAcceleration() const
Definition: CANVenom.cpp:243
virtual void StopMotor() override
Definition: CANVenom.cpp:21
double GetMinPILimit() const
Definition: CANVenom.cpp:231
void SetMinPILimit(double limit)
Definition: CANVenom.cpp:299
double GetSpeed() const
Definition: CANVenom.cpp:199
void SetControlMode(ControlMode controlMode)
Definition: CANVenom.cpp:319
void SetBrakeCoastMode(BrakeCoastMode brakeCoastMode)
Definition: CANVenom.cpp:323
CANVenom(CANVenom &&)=default
MotionProfileState GetMotionProfileState() const
Definition: CANVenom.cpp:171
CANVenom & operator=(CANVenom &&)=default
double GetB() const
Definition: CANVenom.cpp:215
void EnableLimitSwitches(bool fwdLimitSwitchEnabled, bool revLimitSwitchEnabled)
Definition: CANVenom.cpp:83
uint32_t GetSerialNumber() const
Definition: CANVenom.cpp:147
virtual void SetInverted(bool isInverted) override
Definition: CANVenom.cpp:54
void SetMaxSpeed(double limit)
Definition: CANVenom.cpp:307
uint16_t GetNumAvaliableMotionProfilePoints() const
Definition: CANVenom.cpp:151
double GetMotionProfileSpeedTarget() const
Definition: CANVenom.cpp:163
void SetKP(double kP)
Definition: CANVenom.cpp:287
void Enable()
Definition: CANVenom.cpp:66
BrakeCoastMode
Definition: CANVenom.h:80
@ kBrake
Definition: CANVenom.h:91
@ kCoast
Definition: CANVenom.h:85
void IdentifyMotor()
Definition: CANVenom.cpp:114
virtual double Get() const override
Definition: CANVenom.cpp:49
ControlMode GetControlMode() const
Definition: CANVenom.cpp:251
virtual ~CANVenom()
Definition: CANVenom.cpp:16
void SetMaxPILimit(double limit)
Definition: CANVenom.cpp:303
double GetPIDTarget() const
Definition: CANVenom.cpp:207
CANVenom(const CANVenom &)=delete
double GetDutyCycle() const
Definition: CANVenom.cpp:183
void SetKI(double kI)
Definition: CANVenom.cpp:291
void SetKF(double kF)
Definition: CANVenom.cpp:279
double GetMaxJerk() const
Definition: CANVenom.cpp:247
double GetMaxPILimit() const
Definition: CANVenom.cpp:235
double GetTemperature() const
Definition: CANVenom.cpp:191
void SetMaxAcceleration(double limit)
Definition: CANVenom.cpp:311
virtual void PIDWrite(double output)
Definition: CANVenom.cpp:70
virtual bool GetInverted() const override
Definition: CANVenom.cpp:58
double GetKP() const
Definition: CANVenom.cpp:219
ControlMode
Definition: CANVenom.h:24
@ kPositionControl
Definition: CANVenom.h:48
@ kDisabled
Definition: CANVenom.h:28
@ kCurrentControl
Definition: CANVenom.h:38
@ kSpeedControl
Definition: CANVenom.h:43
@ kVoltageControl
Definition: CANVenom.h:77
@ kProportional
Definition: CANVenom.h:33
@ kFollowTheLeader
Definition: CANVenom.h:71
@ kMotionProfile
Definition: CANVenom.h:57
void SetCommand(ControlMode mode, double command)
Definition: CANVenom.cpp:35
Definition: CANVenom.h:10