Resurgence (PY2022)
Codebase for the Husky Robotics 2021-2022 rover Resurgence
Loading...
Searching...
No Matches
SwerveController.h
1#pragma once
2
3#include "../kinematics/DiffDriveKinematics.h"
4#include "../kinematics/SwerveDriveKinematics.h"
5
6#include <map>
7
8namespace control {
13enum class DriveMode {
18 Normal,
19
24 TurnInPlace,
25
30 Crab,
31};
32
37 int lfRot;
38 int rfRot;
39 int lbRot;
40 int rbRot;
41};
42
47 double lfPower;
48 double rfPower;
49 double lbPower;
50 double rbPower;
51};
52
57public:
68 SwerveController(double baseWidth, double baseLength, int epsilon);
69
78 const swerve_rots_t& wheel_rots) const;
79
90 drive_commands_t setTurnInPlaceCmdVel(double dtheta, const swerve_rots_t& wheel_rots,
91 double& scaleFactor) const;
92
102 drive_commands_t setCrabCmdVel(double dtheta, double dy,
103 const swerve_rots_t& wheel_rots) const;
104
117 drive_commands_t setCrabCmdVel(double dtheta, double dy, const swerve_rots_t& wheel_rots,
118 double& scaleFactor) const;
119
126
135 void setOverride(bool override);
136
142 bool isOverridden() const;
143
149 DriveMode getDriveMode() const;
150
157 swerve_rots_t setDriveMode(DriveMode mode);
158
167 bool checkWheelRotation(DriveMode mode, const swerve_rots_t& wheel_rots) const;
168
172 swerve_rots_t getSteerRots(DriveMode mode) const;
173
174private:
175 const kinematics::SwerveDriveKinematics swerve_kinematics;
176 const kinematics::DiffDriveKinematics crab_kinematics;
177 const double steer_epsilon;
178
182 DriveMode driveMode;
183
188 bool override_steer_check;
189};
190} // namespace control
191
192namespace util {
193std::string to_string(control::DriveMode mode);
194} // namespace util
_GLIBCXX_END_NAMESPACE_CXX11 typedef basic_string< char > string
SwerveController(double baseWidth, double baseLength, int epsilon)
Construct a new controller object.
Definition SwerveController.cpp:8
const kinematics::SwerveDriveKinematics & swerveKinematics() const
Get the SwerveDriveKinematics object used by the controller.
Definition SwerveController.cpp:124
void setOverride(bool override)
Set the override flag for wheel rotation checking.
Definition SwerveController.cpp:137
bool checkWheelRotation(DriveMode mode, const swerve_rots_t &wheel_rots) const
Check to see if all wheels are at their target position.
Definition SwerveController.cpp:86
swerve_rots_t getSteerRots(DriveMode mode) const
Get the wheel steer rotations for a given drive mode in millidegrees.
Definition SwerveController.cpp:104
swerve_rots_t setDriveMode(DriveMode mode)
Set the drive mode of the controller.
Definition SwerveController.cpp:132
drive_commands_t setTurnInPlaceCmdVel(double dtheta, const swerve_rots_t &wheel_rots) const
Request the robot to turn in place using swerve.
Definition SwerveController.cpp:13
bool isOverridden() const
Check the override flag for wheel rotation checking.
Definition SwerveController.cpp:141
DriveMode getDriveMode() const
Get the current drive mode of the controller.
Definition SwerveController.cpp:128
drive_commands_t setCrabCmdVel(double dtheta, double dy, const swerve_rots_t &wheel_rots) const
Request the robot to drive side to side and turn with given velocities using swerve.
Definition SwerveController.cpp:53
Represents the kinematics of a differential drive.
Definition DiffDriveKinematics.h:14
Calculates forward and inverse drivebase kinematics for a 4-wheel swerve drivebase with specifiable w...
Definition SwerveDriveKinematics.h:26
A collection of utility functions and classes with common use-cases.
Definition SwerveController.cpp:145
The power commands to all four drive motors.
Definition SwerveController.h:46
Represents the rotations of all four steer motors in in millidegrees.
Definition SwerveController.h:36