10 #include "ErrorBase.h"
14 #include "HAL/HAL.hpp"
15 #include "MotorSafety.h"
16 #include "MotorSafetyHelper.h"
45 RobotDrive(uint32_t leftMotorChannel, uint32_t rightMotorChannel);
46 RobotDrive(uint32_t frontLeftMotorChannel, uint32_t rearLeftMotorChannel,
47 uint32_t frontRightMotorChannel, uint32_t rearRightMotorChannel);
50 RobotDrive(std::shared_ptr<SpeedController> leftMotor,
51 std::shared_ptr<SpeedController> rightMotor);
56 RobotDrive(std::shared_ptr<SpeedController> frontLeftMotor,
57 std::shared_ptr<SpeedController> rearLeftMotor,
58 std::shared_ptr<SpeedController> frontRightMotor,
59 std::shared_ptr<SpeedController> rearRightMotor);
65 void Drive(
float outputMagnitude,
float curve);
67 bool squaredInputs =
true);
69 bool squaredInputs =
true);
72 bool squaredInputs =
true);
75 bool squaredInputs =
true);
76 void TankDrive(
float leftValue,
float rightValue,
bool squaredInputs =
true);
80 GenericHID *rotateStick, uint32_t rotateChannel,
81 bool squaredInputs =
true);
83 GenericHID &rotateStick, uint32_t rotateChannel,
84 bool squaredInputs =
true);
85 void ArcadeDrive(
float moveValue,
float rotateValue,
86 bool squaredInputs =
true);
88 float gyroAngle = 0.0);
90 void HolonomicDrive(
float magnitude,
float direction,
float rotation);
92 void SetInvertedMotor(MotorType motor,
bool isInverted);
97 void SetExpiration(
float timeout)
override;
98 float GetExpiration()
const override;
99 bool IsAlive()
const override;
100 void StopMotor()
override;
101 bool IsSafetyEnabled()
const override;
102 void SetSafetyEnabled(
bool enabled)
override;
103 void GetDescription(std::ostringstream& desc)
const override;
107 float Limit(
float num);
111 static const int32_t kMaxNumberOfMotors = 4;
112 float m_sensitivity = 0.5;
113 double m_maxOutput = 1.0;
114 std::shared_ptr<SpeedController> m_frontLeftMotor;
115 std::shared_ptr<SpeedController> m_frontRightMotor;
116 std::shared_ptr<SpeedController> m_rearLeftMotor;
117 std::shared_ptr<SpeedController> m_rearRightMotor;
118 std::unique_ptr<MotorSafetyHelper> m_safetyHelper;
119 uint8_t m_syncGroup = 0;
122 int32_t GetNumMotors() {
124 if (m_frontLeftMotor) motors++;
125 if (m_frontRightMotor) motors++;
126 if (m_rearLeftMotor) motors++;
127 if (m_rearRightMotor) motors++;
void SetCANJaguarSyncGroup(uint8_t syncGroup)
Set the number of the sync group for the motor controllers.
Definition: RobotDrive.cpp:721
void TankDrive(GenericHID *leftStick, GenericHID *rightStick, bool squaredInputs=true)
Provide tank steering using the stored robot configuration.
Definition: RobotDrive.cpp:242
Definition: MotorSafety.h:14
virtual void SetLeftRightMotorOutputs(float leftOutput, float rightOutput)
Set the speed of the right and left motors.
Definition: RobotDrive.cpp:604
void RotateVector(double &x, double &y, double angle)
Rotate a vector in Cartesian space.
Definition: RobotDrive.cpp:655
void SetMaxOutput(double maxOutput)
Configure the scaling factor for using RobotDrive with motor controllers in a mode other than Percent...
Definition: RobotDrive.cpp:711
void SetSensitivity(float sensitivity)
Set the turning sensitivity.
Definition: RobotDrive.cpp:701
Base class for most objects.
Definition: ErrorBase.h:66
float Limit(float num)
Limit motor values to the -1.0 to +1.0 range.
Definition: RobotDrive.cpp:625
void InitRobotDrive()
Common function to initialize all the robot drive constructors.
Definition: RobotDrive.cpp:42
Interface for speed controlling devices.
Definition: SpeedController.h:16
Utility class for handling Robot drive based on a definition of the motor configuration.
Definition: RobotDrive.h:36
void HolonomicDrive(float magnitude, float direction, float rotation)
Holonomic Drive method for Mecanum wheeled robots.
Definition: RobotDrive.cpp:592
void ArcadeDrive(GenericHID *stick, bool squaredInputs=true)
Arcade drive implements single stick driving.
Definition: RobotDrive.cpp:331
void Drive(float outputMagnitude, float curve)
Drive the motors at "outputMagnitude" and "curve".
Definition: RobotDrive.cpp:207
RobotDrive(uint32_t leftMotorChannel, uint32_t rightMotorChannel)
Constructor for RobotDrive with 2 motors specified with channel numbers.
Definition: RobotDrive.cpp:57
void MecanumDrive_Polar(float magnitude, float direction, float rotation)
Drive method for Mecanum wheeled robots.
Definition: RobotDrive.cpp:539
void Normalize(double *wheelSpeeds)
Normalize all wheel speeds if the magnitude of any wheel is greater than 1.0.
Definition: RobotDrive.cpp:638
void MecanumDrive_Cartesian(float x, float y, float rotation, float gyroAngle=0.0)
Drive method for Mecanum wheeled robots.
Definition: RobotDrive.cpp:482
GenericHID Interface.
Definition: GenericHID.h:14