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 bAlwaysProgressForward = false);
52 void SendDrive(const diffdrive::DrivePowers& stDrivePowers, const bool bEnableVariableDriveEffort = true);
53 void SendStop();
54 float VariableDriveEffort();
55
57 // Setters
59
60 void SetMaxDriveEffort(const float fMaxDriveEffortMultiplier);
61
63 // Getters
65
67
68 private:
70 // Declare private member variables.
72
73 diffdrive::DrivePowers m_stDrivePowers; // Struct used to store the left and right drive powers of the robot.
74 std::unique_ptr<controllers::PIDController> m_pPID; // The PID controller used for drive towards a heading.
75 float m_fMinDriveEffort; // The min power limit of the drive.
76 float m_fMaxDriveEffort; // The max power limit of the drive.
77 float m_fDriveEffortMultiplier; // The current drive effort multiplier. This is adjusted over RoveComm.
78 std::shared_mutex m_muDriveEffortMutex; // Mutex used for changing the drive efforts.
79 const float m_fMinSlope = constants::DRIVE_BOARD_MIN_SLOPE;
80 const float m_fMaxSlope = constants::DRIVE_BOARD_MAX_SLOPE;
81 const float m_fMinDamp = constants::DRIVE_BOARD_MIN_DAMP;
82 const float m_fMaxDamp = constants::DRIVE_BOARD_MAX_DAMP;
83 const float m_fRoll_w = constants::DRIVE_BOARD_ROLL_WEIGHT;
84 const float m_fPitch_w = constants::DRIVE_BOARD_PITCH_WEIGHT;
85 const float m_fYaw_w = constants::DRIVE_BOARD_YAW_WEIGHT;
86
88 // Declare private methods.
90
91
98 const std::function<void(const rovecomm::RoveCommPacket<float>&, const sockaddr_in&)> SetMaxSpeedCallback =
99 [this](const rovecomm::RoveCommPacket<float>& stPacket, const sockaddr_in& stdAddr)
100 {
101 // Not using this.
102 (void) stdAddr;
103
104 // Clamp the incoming multiplier to [0.0, 1.0].
105 float fClampedMultiplier = std::clamp(std::fabs(stPacket.vData[0]), 0.0f, 1.0f);
106 // Update member variable.
107 {
108 std::unique_lock<std::shared_mutex> lkDriveEffortLock(m_muDriveEffortMutex);
109 m_fDriveEffortMultiplier = fClampedMultiplier;
110 }
111
112 // Submit logger message.
113 LOG_NOTICE(logging::g_qSharedLogger, "Incoming SETMAXSPEED: {}", stPacket.vData[0]);
114 };
115};
116#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:68
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:118
diffdrive::DrivePowers GetDrivePowers() const
Accessor for the current drive powers of the robot.
Definition DriveBoard.cpp:295
void SetMaxDriveEffort(const float fMaxDriveEffortMultiplier)
Set the max power limits of the drive.
Definition DriveBoard.cpp:277
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:98
float VariableDriveEffort()
This method calculates a multiplier that is applied to SetMaxDriveEffort() to adjust the speed of the...
Definition DriveBoard.cpp:229
void SendStop()
Stop the drivetrain of the Rover.
Definition DriveBoard.cpp:195
diffdrive::DrivePowers CalculateMove(const double dGoalSpeed, const double dGoalHeading, const double dActualHeading, const diffdrive::DifferentialControlMethod eKinematicsMethod=diffdrive::DifferentialControlMethod::eArcadeDrive, const bool bAlwaysProgressForward=false)
This method determines drive powers to make the Rover drive towards a given heading at a given speed.
Definition DriveBoard.cpp:88
This struct is used to store the left and right drive powers for the robot. Storing these values in a...
Definition DifferentialDrive.hpp:73