5#include "ODriveFlexCAN.hpp"
14template<CAN_DEV_TABLE CAN>
26 FlexCAN_T4<CAN, RX_SIZE_256, TX_SIZE_256> & odrive_can,
30 odrv_(ODriveCAN(wrap_can_intf(odrive_can), CAN_ID)),
56 Serial.println(
"Setting parameters: ");
62 Serial.print(
"Setting param: ");
73 Serial.print(
"Setting param: ");
86 Serial.println(
"Starting Calibration");
87 odrv_.setState(ODriveAxisState::AXIS_STATE_FULL_CALIBRATION_SEQUENCE);
89 Serial.println(
"Calibration Done!");
96 odrv_.setControllerMode(
97 ODriveControlMode::CONTROL_MODE_POSITION_CONTROL,
98 ODriveInputMode::INPUT_MODE_PASSTHROUGH);
99 odrv_.setState(ODriveAxisState::AXIS_STATE_CLOSED_LOOP_CONTROL);
100 Serial.println(
"Moving to upper limit.");
103 Serial.println(
"Moving to lower limit.");
106 Serial.println(
"Done Checking Limits");
107 odrv_.setControllerMode(
108 ODriveControlMode::CONTROL_MODE_TORQUE_CONTROL,
109 ODriveInputMode::INPUT_MODE_PASSTHROUGH);
117 Serial.println(
"Attempting to turn on anticogging");
123 Serial.print(
"Setting param: ");
135 Serial.print(
"Setting param: ");
141 Serial.println(
"Successfully set anticogging configuration");
144 odrv_.setState(ODriveAxisState::AXIS_STATE_ANTICOGGING_CALIBRATION);
146 Serial.println(
"Starting anticogging calibration");
149 Serial.println(
"Finished anticogging calibration");
154 Serial.print(
"Setting param: ");
159 Serial.println(
"Enabled anticogging");
165 Serial.println(
"Reboot successful");
172 Serial.println(
"\nAttempting to set configuration and start torque mode!");
175 Serial.println(
"Configuration set");
177 Serial.println(
"Checking Temperature...");
179 odrv_.setControllerMode(
180 ODriveControlMode::CONTROL_MODE_TORQUE_CONTROL,
181 ODriveInputMode::INPUT_MODE_PASSTHROUGH);
182 Serial.println(
"Setting to Torque mode");
202 odrv_.setTorque(torque);
209 odrv_.setTorque(torque * gain);
215 odrv_.setTorque(torque * gain);
Class that abstracts operations with the ODrive/.
bool move_to_limits()
Move to the upper and lower limits of the joint.
OdriveController(FlexCAN_T4< CAN, RX_SIZE_256, TX_SIZE_256 > &odrive_can, int CAN_ID, ODriveUserData &odrv_user_data)
Constructor for the ODriveController.
Limits< float > motor_limits_
: Limits on motor torques
ODriveUserData & odrv_user_data_
struct to store user data in
bool startup_odrive_checks()
Set parameters and set the motor to torque control.
void set_torque(float torque)
Function to set the torque values based on the joint limits recorded from the startup_calibration.
bool set_params()
Set parameters on the ODrive.
FlexCAN_T4< CAN, RX_SIZE_256, TX_SIZE_256 > & odrive_can_
Address of canline for this odrive.
bool full_calibration()
Run the full calibration sequence given by ODrive.
ODriveCAN odrv_
Odrive object to control.
OdriveController()=default
bool enable_anticogging(bool doCalibration=false)
Set parameters for anticogging and enable it.
~OdriveController()=default
void onTemperature(Get_Temperature_msg_t &msg, void *user_data)
: Called every time a temperature message arrives from the ODrive
void onFeedback(Get_Encoder_Estimates_msg_t &msg, void *user_data)
: Called every time a feedback message arrives from the ODrive
void onHeartbeat(Heartbeat_msg_t &msg, void *user_data)
: Called every time a heartbeat message arrives from the ODrive
auto benable_config_param
std::vector< Param< float > > fanticogging_config_params({Param< float >{"spinout_mechanical_power_threshold", 420, -100.0}, Param< float >{"spinout_eletrical_power_threshold", 421, 100.0}, Param< float >{"max_regen_current", 139, 50.0}, Param< float >{"dc_max_negative_current", 143, -50.0}, Param< float >{"pos_gain", 400, 20.0}, Param< float >{"vel_gain", 401, 8.5e-3}, Param< float >{"vel_integrator_gain", 402, 0.0}, Param< float >{"torque_soft_min", 267, -150.0}, Param< float >{"torque_soft_max", 268, 150.0}, Param< float >{"anticogging.max_torque", 305, 0.15}, Param< float >{"anticogging.calib_start_vel", 306, 1}, Param< float >{"anticogging.calib_end_val", 307, 0.15}, Param< float >{"anticogging.calib_coarse_integrator_gain", 311, 1}})
std::vector< Param< float > > fconfig_params({ Param< float >{"spinout_mechanical_power_threshold", 420, -100.0}, Param< float >{"spinout_eletrical_power_threshold", 421, 100.0}, Param< float >{"max_regen_current", 139, 50.0}, Param< float >{"dc_max_negative_current", 143, -50.0}, Param< float >{"pos_gain", 400, 100}, Param< float >{"vel_gain", 401, 12}, Param< float >{"vel_integrator_gain", 402, 0.0}, Param< float >{"torque_soft_min", 267, -10.0}, Param< float >{"torque_soft_max", 268, 10.0}, Param< float >{"calib_scan_dist", 215, 4.0}, Param< float >{"motor_thermistor.config.r_ref", 352, 10000}, Param< float >{"motor_thermistor.config.t_ref", 353, 25}, Param< float >{"motor_thermistor.config.beta", 354, 3892}, Param< float >{"motor_thermistor.config.temp_limit_lower", 355, 60}, Param< float >{"motor_thermistor.config.temp_limit_upper", 356, 90}, Param< float >{"vel_limit", 404, 30.0}, Param< float >{"vel_limit_tolerance", 405, 1.5}, })
std::vector< Param< uint32_t > > bconfig_params({ Param< uint32_t >{"version_msg_rate_ms", 248, 0}, Param< uint32_t >{"iq_msg_rate_ms", 251, 0}, Param< uint32_t >{"bus_voltage_msg_rate_ms", 254, 0}, Param< uint32_t >{"powers_msg_rate_ms", 256, 0}, Param< uint32_t >{"gpio7_mode", 159, 3}, Param< uint32_t >{"motor_thermistor.config.enabled", 357, 0}, Param< uint32_t >{"can.temperature_msg_rate_ms", 253, 100}, Param< uint32_t >{"enable_vel_limit", 393, 1}, Param< uint32_t >{"enable_torque_mode_vel_limit", 394, 1}, })
std::vector< Param< uint32_t > > banticogging_config_params({Param< uint32_t >{"circular_setpoints", 408, true}, Param< uint32_t >{"offset_valid", 466, true}})
Limit struct to store upper and lower limits.
: The Struct to contain feedback from the ODrive
Get_Encoder_Estimates_msg_t last_feedback
Structure for setting ODrive Parameters Endpoint_ids can be found at the following link: https://odri...
Message struct for reboooting Odrive.