Haptic Controller
Loading...
Searching...
No Matches
odrive_msgs.hpp
Go to the documentation of this file.
1#ifndef ODRIVEMSGSHPP
2#define ODRIVEMSGSHPP
3#include <stdint.h>
4#include "can_helpers.hpp"
5#include <string>
6
9{
10 Heartbeat_msg_t last_heartbeat;
11 bool received_heartbeat = false;
12 Get_Encoder_Estimates_msg_t last_feedback;
13 bool received_feedback = false;
14 uint32_t node_id;
16 bool heartbeat_timeout = false;
17 uint32_t last_error;
18 Get_Temperature_msg_t last_temperature;
20};
21
24template<typename T>
25struct Set_Param_msg_t final
26{
27 constexpr Set_Param_msg_t() = default;
28
29#ifdef ODRIVE_CAN_MSG_TYPE
30 Set_Param_msg_t(const TBoard::TCanIntf::TMsg & msg)
31 {
32 decode_msg(msg);
33 }
34
35 void encode_msg(TBoard::TCanIntf::TMsg & msg)
36 {
37 encode_buf(can_msg_get_payload(msg).data());
38 }
39
40 void decode_msg(const TBoard::TCanIntf::TMsg & msg)
41 {
42 decode_buf(can_msg_get_payload(msg).data());
43 }
44#endif
45
48 void encode_buf(uint8_t * buf) const
49 {
50 can_set_signal_raw<uint8_t>(buf, Opcode, 0, 8, true);
51 can_set_signal_raw<uint16_t>(buf, Endpoint_ID, 8, 16, true);
52 can_set_signal_raw<uint8_t>(buf, Reserved, 24, 8, true);
53 can_set_signal_raw<T>(buf, Value, 32, 32, true);
54 }
55
58 void decode_buf(const uint8_t * buf)
59 {
60 Opcode = can_get_signal_raw<uint8_t>(buf, 0, 8, true);
61 Endpoint_ID = can_get_signal_raw<uint16_t>(buf, 8, 16, true);
62 Reserved = can_get_signal_raw<uint8_t>(buf, 24, 8, true);
63 Value = can_get_signal_raw<T>(buf, 32, 32, true);
64 }
65
66 static const uint8_t cmd_id = 0x04;
67 static const uint8_t msg_length = 8;
68
69 uint8_t Opcode = 1;
70 uint16_t Endpoint_ID = 0;
71 uint8_t Reserved = 0;
72 // This may need to become a class T? or have an extra variable that tracks what type it is
73 // then we set several value variables that change encode and decode based on the type
75};
76
78template<typename T>
79struct Param
80{
81 String name;
82 uint16_t endpoint_id;
84};
85
86// https://odrive-cdn.nyc3.digitaloceanspaces.com/releases/firmware/laZ44T35qb_uR6AW6S5RdTrOL9sqZlc2_FonY3vm21Q/flat_endpoints.json
87std::vector<Param<float>> fconfig_params({
88 Param<float>{"spinout_mechanical_power_threshold", 420, -100.0},
89 Param<float>{"spinout_eletrical_power_threshold", 421, 100.0},
90 Param<float>{"max_regen_current", 139, 50.0},
91 Param<float>{"dc_max_negative_current", 143, -50.0},
92 Param<float>{"pos_gain", 400, 100},
93 Param<float>{"vel_gain", 401, 12},
94 Param<float>{"vel_integrator_gain", 402, 0.0},
95 Param<float>{"torque_soft_min", 267, -10.0},
96 Param<float>{"torque_soft_max", 268, 10.0},
97 // Param<float>{"pos_vel_mapper.offset", 467, 0.0},
98 // Param<float>{"pos_vel_mapper.approx_init_pos", 469, 0.0},
99 Param<float>{"calib_scan_dist", 215, 4.0},
100 Param<float>{"motor_thermistor.config.r_ref", 352, 10000},
101 Param<float>{"motor_thermistor.config.t_ref", 353, 25},
102 Param<float>{"motor_thermistor.config.beta", 354, 3892},
103 Param<float>{"motor_thermistor.config.temp_limit_lower", 355, 60},
104 Param<float>{"motor_thermistor.config.temp_limit_upper", 356, 90},
105 Param<float>{"vel_limit", 404, 30.0},
106 Param<float>{"vel_limit_tolerance", 405, 1.5},
107});
108
109std::vector<Param<uint32_t>> bconfig_params({
110 // Param<uint32_t>{"anticogging.enabled", 304, 1},
111 // Param<uint32_t>{"pos_vel_mapper.offset_valid", 466, 1},
112 // Param<uint32_t>{"pos_vel_mapper.approx_init_pos_valid", 468, 1},
113 // Param<uint32_t>{"absolute_setpoints", 410, 1},
114 Param<uint32_t>{"version_msg_rate_ms", 248, 0},
115 Param<uint32_t>{"iq_msg_rate_ms", 251, 0},
116 Param<uint32_t>{"bus_voltage_msg_rate_ms", 254, 0},
117 Param<uint32_t>{"powers_msg_rate_ms", 256, 0},
118 Param<uint32_t>{"gpio7_mode", 159, 3}, // set gpio7 (them+) to analog input mode
119 Param<uint32_t>{"motor_thermistor.config.enabled", 357, 0}, // disable motor thermistor
120 Param<uint32_t>{"can.temperature_msg_rate_ms", 253, 100},
121 Param<uint32_t>{"enable_vel_limit", 393, 1},
122 Param<uint32_t>{"enable_torque_mode_vel_limit", 394, 1},
123});
124
125std::vector<Param<float>> fanticogging_config_params(
126 {Param<float>{"spinout_mechanical_power_threshold", 420, -100.0},
127 Param<float>{"spinout_eletrical_power_threshold", 421, 100.0},
128 Param<float>{"max_regen_current", 139, 50.0},
129 Param<float>{"dc_max_negative_current", 143, -50.0},
130 Param<float>{"pos_gain", 400, 20.0},
131 Param<float>{"vel_gain", 401, 8.5e-3},
132 Param<float>{"vel_integrator_gain", 402, 0.0},
133 Param<float>{"torque_soft_min", 267, -150.0},
134 Param<float>{"torque_soft_max", 268, 150.0},
135 Param<float>{"anticogging.max_torque", 305, 0.15},
136 Param<float>{"anticogging.calib_start_vel", 306, 1},
137 Param<float>{"anticogging.calib_end_val", 307, 0.15},
138 Param<float>{"anticogging.calib_coarse_integrator_gain", 311, 1}});
139
140std::vector<Param<uint32_t>> banticogging_config_params(
141 {Param<uint32_t>{"circular_setpoints", 408, true},
142 Param<uint32_t>{"offset_valid", 466, true}});
143
144auto benable_config_param = Param<uint32_t>{"anticogging.enabled", 304, true};
145
148{
149 constexpr Set_Reboot_msg_t() = default;
150
151#ifdef ODRIVE_CAN_MSG_TYPE
152 Set_Reboot_msg_t(const TBoard::TCanIntf::TMsg & msg)
153 {
154 decode_msg(msg);
155 }
156
157 void encode_msg(TBoard::TCanIntf::TMsg & msg)
158 {
159 encode_buf(can_msg_get_payload(msg).data());
160 }
161
162 void decode_msg(const TBoard::TCanIntf::TMsg & msg)
163 {
164 decode_buf(can_msg_get_payload(msg).data());
165 }
166#endif
167
170 void encode_buf(uint8_t * buf) const
171 {
172 can_set_signal_raw<uint8_t>(buf, Action, 0, 8, true);
173 }
174
177 void decode_buf(const uint8_t * buf)
178 {
179 Action = can_get_signal_raw<uint8_t>(buf, 0, 8, true);
180 }
181
182 static const uint8_t cmd_id = 0x16;
183 static const uint8_t msg_length = 8;
184
185 uint8_t Action = 0; // 0: Reboot, 1: Save Config, 2: Erase Config
186};
187
188#endif
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}})
: The Struct to contain feedback from the ODrive
Get_Encoder_Estimates_msg_t last_feedback
bool received_temperature
uint32_t last_heartbeat_time
uint32_t last_error
Get_Temperature_msg_t last_temperature
Heartbeat_msg_t last_heartbeat
Structure for storing information about parameters.
uint16_t endpoint_id
String name
Structure for setting ODrive Parameters Endpoint_ids can be found at the following link: https://odri...
void decode_msg(const TBoard::TCanIntf::TMsg &msg)
Set_Param_msg_t(const TBoard::TCanIntf::TMsg &msg)
static const uint8_t msg_length
static const uint8_t cmd_id
uint16_t Endpoint_ID
void encode_buf(uint8_t *buf) const
Encoders data to the buffer to send over CAN.
constexpr Set_Param_msg_t()=default
void encode_msg(TBoard::TCanIntf::TMsg &msg)
void decode_buf(const uint8_t *buf)
Decoders data from the buffer and saves to struct message.
Message struct for reboooting Odrive.
static const uint8_t cmd_id
void decode_msg(const TBoard::TCanIntf::TMsg &msg)
void encode_buf(uint8_t *buf) const
Encoders data to the buffer to send over CAN.
static const uint8_t msg_length
Set_Reboot_msg_t(const TBoard::TCanIntf::TMsg &msg)
void decode_buf(const uint8_t *buf)
Decoders data from the buffer and saves to struct message.
void encode_msg(TBoard::TCanIntf::TMsg &msg)
constexpr Set_Reboot_msg_t()=default