Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
DriveBoard.h
Go to the documentation of this file.
1
12#ifndef DRIVEBOARD_H
13#define DRIVEBOARD_H
14
15#include "../algorithms/kinematics/DifferentialDrive.hpp"
16
18#include "../AutonomyConstants.h"
19#include <RoveComm/RoveComm.h>
20#include <RoveComm/RoveCommManifest.h>
21#include <array>
22#include <shared_mutex>
23
25
26
35{
36 public:
38 // Declare public enums that are specific to and used within this class.
40
42 // Declare public methods and member variables.
44
45 DriveBoard();
47 diffdrive::DrivePowers CalculateMove(const double dGoalSpeed,
48 const double dGoalHeading,
49 const double dActualHeading,
50 const diffdrive::DifferentialControlMethod eKinematicsMethod = diffdrive::DifferentialControlMethod::eArcadeDrive,
51 const bool bDriveBackwards = false,
52 const bool bAlwaysProgressForward = false,
53 const bool bSquareControlInput = false,
54 const bool bCurvatureDriveAllowTurningWhileStopped = true);
55 void SendDrive(const diffdrive::DrivePowers& stDrivePowers, const bool bEnableVariableDriveEffort = true);
56 void SendStop();
57 float VariableDriveEffort();
58
60 // Setters
62
63 void SetMaxDriveEffort(const float fMaxDriveEffortMultiplier);
64
66 // Getters
68
70 float GetMaxDriveEffort() const;
71
72 private:
74 // Declare private member variables.
76
77 diffdrive::DrivePowers m_stDrivePowers; // Struct used to store the left and right drive powers of the robot.
78 std::unique_ptr<controllers::PIDController> m_pPID; // The PID controller used for drive towards a heading.
79 float m_fDriveEffortMultiplier; // The current drive effort multiplier. This is adjusted over RoveComm.
80 mutable std::shared_mutex m_muDriveEffortMutex; // Mutex used for changing the drive efforts.
81 const float m_fMinSlope = constants::DRIVE_BOARD_MIN_SLOPE;
82 const float m_fMaxSlope = constants::DRIVE_BOARD_MAX_SLOPE;
83 const float m_fMinDamp = constants::DRIVE_BOARD_MIN_DAMP;
84 const float m_fMaxDamp = constants::DRIVE_BOARD_MAX_DAMP;
85 const float m_fRoll_w = constants::DRIVE_BOARD_ROLL_WEIGHT;
86 const float m_fPitch_w = constants::DRIVE_BOARD_PITCH_WEIGHT;
87 const float m_fYaw_w = constants::DRIVE_BOARD_YAW_WEIGHT;
88
90 // Declare private methods.
92
93
100 const std::function<void(const rovecomm::RoveCommPacket<float>&, const sockaddr_in&)> SetMaxSpeedCallback =
101 [this](const rovecomm::RoveCommPacket<float>& stPacket, const sockaddr_in& stdAddr)
102 {
103 // Not using this.
104 (void) stdAddr;
105
106 // Clamp the incoming multiplier to [0.0, 1.0].
107 float fClampedMultiplier = std::clamp(std::fabs(stPacket.vData[0]), 0.0f, 1.0f);
108 // Update member variable.
109 {
110 std::unique_lock<std::shared_mutex> lkDriveEffortLock(m_muDriveEffortMutex);
111 m_fDriveEffortMultiplier = fClampedMultiplier;
112 }
113
114 // Submit logger message.
115 LOG_NOTICE(logging::g_qSharedLogger, "Incoming SETMAXSPEED: {}", fClampedMultiplier);
116 };
117};
118#endif
This class handles communication with the drive board on the rover by sending RoveComm packets over t...
Definition DriveBoard.h:35
~DriveBoard()
Destroy the Drive Board::DriveBoard object.
Definition DriveBoard.cpp:66
DriveBoard()
Construct a new Drive Board::DriveBoard object.
Definition DriveBoard.cpp:31
void SendDrive(const diffdrive::DrivePowers &stDrivePowers, const bool bEnableVariableDriveEffort=true)
Sets the left and right drive powers of the drive board.
Definition DriveBoard.cpp:166
diffdrive::DrivePowers GetDrivePowers() const
Accessor for the current drive powers of the robot.
Definition DriveBoard.cpp:346
void SetMaxDriveEffort(const float fMaxDriveEffortMultiplier)
Set the max power limits of the drive.
Definition DriveBoard.cpp:328
diffdrive::DrivePowers CalculateMove(const double dGoalSpeed, const double dGoalHeading, const double dActualHeading, const diffdrive::DifferentialControlMethod eKinematicsMethod=diffdrive::DifferentialControlMethod::eArcadeDrive, const bool bDriveBackwards=false, const bool bAlwaysProgressForward=false, const bool bSquareControlInput=false, const bool bCurvatureDriveAllowTurningWhileStopped=true)
This method determines drive powers to make the Rover drive towards a given heading at a given speed.
Definition DriveBoard.cpp:89
float GetMaxDriveEffort() const
Accessor for the current max drive effort multiplier.
Definition DriveBoard.cpp:361
const std::function< void(const rovecomm::RoveCommPacket< float > &, const sockaddr_in &)> SetMaxSpeedCallback
Callback function that is called whenever RoveComm receives a new SETMAXSPEED packet.
Definition DriveBoard.h:100
float VariableDriveEffort()
This method calculates a multiplier that is applied to SetMaxDriveEffort() to adjust the speed of the...
Definition DriveBoard.cpp:280
void SendStop()
Stop the drivetrain of the Rover.
Definition DriveBoard.cpp:246
This struct is used to store the left and right drive powers for the robot. Storing these values in a...
Definition DifferentialDrive.hpp:73