Hardware
Objects in the hardware module ‘own’ a specific piece of hardware on the Beaglebone, and use the RAII principle to handle initialization and cleanup tasks. They provide a simpler interface of how to get/send information using the hardware
Inertial Measurement Unit - IMU
-
class Imu
Singleton class to communicate with the IMU. We use singleton because there is only one imu in hardware. This class utilizes the DMP (digital motion processor) on the MPU-9250 as a way to calculate orientation.
Public Functions
-
int init(const YAML::Node &config, uint32_t loop_frq, std::function<void(StateData&)> &func)
Initialize the Imu class.
- Parameters:
config – YAML configuration for the Imu class
loop_frq – Desired sampling rate in Hz of the IMU
func – callback function to use when data is received
- Returns:
0 on sucess, -1 on failure
-
int init(const YAML::Node &config, uint32_t loop_frq, std::function<void(StateData&)> &func)
Programmable Realtime Unit - PRU
-
class PruRequester
The PruRequester is a class that helps handle the ownership of the programmable real-time unit (PRU) on the BeagleBone, which gives commands to ESCs/motors. It is critical that only one process is able to commands to the PRU at a time. Thus, this object creates a lockfile saved at ‘kPRU_LOCK_FILE’ to ensure that only one process can access the PRU at a time. On construction, the object will spawn a thread that continuously sends zero commands to the PRU. This prevents ESC’s from ‘chirping’ due to not receiving commands. The zero sender thread will run until ‘send_command’ is called, at which point it will stop the zero sender thread and send the new command. The zero sender thread can be restarted by calling ‘start_zero_sender’.
PruRequester::PruRequestor() - Construct the object and lock the PRU. Throw an exception if the lock fails.
PruRequester::send_command() - Sends a command to the PRU
Example usage is:
{ PruRequester pru_requester; // The motors will be receiving zero commands until send_command is called while (in_control_loop) { std::array<float, 4> motor_commands{0.0, 0.0, 0.0, 0.0}; if(!pru_requester.send_command(motor_commands)) { // handle error } } // Start the zero_sender thread again now the control loop is done pru_requester.start_zero_sender(); } // release the pru lock file on destruction
Public Functions
-
inline PruRequester()
Construct a new Pru Requester object.
-
inline bool send_command(const std::vector<float> &motor_commands)
Sends commands to ESCs, and stops the zero sender thread if it is running.
- Parameters:
motor_commands – commands in the range [0, 1] to send to the ESCs
- Returns:
true on success
- Returns:
false on failure
Setpoint Module
-
class Setpoint
Setpoint class. Communicates with the remote control (using robotics_cape rc_dsm interface) to receive commands. Commands are: throttle, roll, pitch, yaw, kill_switch, and Aux_switch. Switches have binary information.
Public Functions
-
Setpoint(FlightMode flight_mode, std::array<float, 3> max_setpts_stabilized, std::array<float, 3> max_setpts_acro, std::array<float, 2> throttle_limits)
Construct a new Setpoint object.
- Parameters:
flight_mode – flight mode: stabilized or acro
max_setpts_stabilized – max setpoints for stabilized mode (in RPW rad, rad, rad/s)
max_setpts_acro – max setpoints for acro mode (in RPW rad/s, rad/s, rad/s)
throttle_limits – The min (index 0) and max (index 1) throttle values between 0-1
-
Setpoint(FlightMode flight_mode, const YAML::Node &config_params)
Construct a new Setpoint object using a yaml node. The node must have all the parameters needed in the main constructor.
- Parameters:
config_params – The yaml node with config params
-
~Setpoint()
Destroy the Setpoint object.
-
Setpoint(Setpoint&&) = default
Construct a new Setpoint object using the move constructor.
-
Setpoint &operator=(Setpoint&&) = default
Construct a new Setpoint object using the move assignment operator.
- Returns:
Setpoint&
-
void set_yaw_ref(float ref)
Set the Yaw Setpoint value to a user defined offset.
- Parameters:
ref – the reference value to set
-
inline float get_min_throttle() const
Get the Min Throttle.
- Returns:
float
-
Setpoint(FlightMode flight_mode, std::array<float, 3> max_setpts_stabilized, std::array<float, 3> max_setpts_acro, std::array<float, 2> throttle_limits)