Skip to content

Commit

Permalink
fix compilation for Linux <5.11 headers
Browse files Browse the repository at this point in the history
This fixes compilation on Ubuntu 20.04
  • Loading branch information
samuelsadok committed Jan 5, 2024
1 parent c2a97d5 commit 887fb60
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/odrive_can_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void ODriveCanNode::recv_callback(const can_frame& frame) {

switch(frame.can_id & 0x1F) {
case CmdId::kHeartbeat: {
if (!verify_length("kHeartbeat", 8, frame.len)) break;
if (!verify_length("kHeartbeat", 8, frame.can_dlc)) break;
std::lock_guard<std::mutex> guard(ctrl_stat_mutex_);
ctrl_stat_.active_errors = read_le<uint32_t>(frame.data + 0);
ctrl_stat_.axis_state = read_le<uint8_t>(frame.data + 4);
Expand All @@ -89,47 +89,47 @@ void ODriveCanNode::recv_callback(const can_frame& frame) {
break;
}
case CmdId::kGetError: {
if (!verify_length("kGetError", 8, frame.len)) break;
if (!verify_length("kGetError", 8, frame.can_dlc)) break;
std::lock_guard<std::mutex> guard(odrv_stat_mutex_);
odrv_stat_.active_errors = read_le<uint32_t>(frame.data + 0);
odrv_stat_.disarm_reason = read_le<uint32_t>(frame.data + 4);
odrv_pub_flag_ |= 0b001;
break;
}
case CmdId::kGetEncoderEstimates: {
if (!verify_length("kGetEncoderEstimates", 8, frame.len)) break;
if (!verify_length("kGetEncoderEstimates", 8, frame.can_dlc)) break;
std::lock_guard<std::mutex> guard(ctrl_stat_mutex_);
ctrl_stat_.pos_estimate = read_le<float>(frame.data + 0);
ctrl_stat_.vel_estimate = read_le<float>(frame.data + 4);
ctrl_pub_flag_ |= 0b0010;
break;
}
case CmdId::kGetIq: {
if (!verify_length("kGetIq", 8, frame.len)) break;
if (!verify_length("kGetIq", 8, frame.can_dlc)) break;
std::lock_guard<std::mutex> guard(ctrl_stat_mutex_);
ctrl_stat_.iq_setpoint = read_le<float>(frame.data + 0);
ctrl_stat_.iq_measured = read_le<float>(frame.data + 4);
ctrl_pub_flag_ |= 0b0100;
break;
}
case CmdId::kGetTemp: {
if (!verify_length("kGetTemp", 8, frame.len)) break;
if (!verify_length("kGetTemp", 8, frame.can_dlc)) break;
std::lock_guard<std::mutex> guard(odrv_stat_mutex_);
odrv_stat_.fet_temperature = read_le<float>(frame.data + 0);
odrv_stat_.motor_temperature = read_le<float>(frame.data + 4);
odrv_pub_flag_ |= 0b010;
break;
}
case CmdId::kGetBusVoltageCurrent: {
if (!verify_length("kGetBusVoltageCurrent", 8, frame.len)) break;
if (!verify_length("kGetBusVoltageCurrent", 8, frame.can_dlc)) break;
std::lock_guard<std::mutex> guard(odrv_stat_mutex_);
odrv_stat_.bus_voltage = read_le<float>(frame.data + 0);
odrv_stat_.bus_current = read_le<float>(frame.data + 4);
odrv_pub_flag_ |= 0b100;
break;
}
case CmdId::kGetTorques: {
if (!verify_length("kGetTorques", 8, frame.len)) break;
if (!verify_length("kGetTorques", 8, frame.can_dlc)) break;
std::lock_guard<std::mutex> guard(ctrl_stat_mutex_);
ctrl_stat_.torque_target = read_le<float>(frame.data + 0);
ctrl_stat_.torque_estimate = read_le<float>(frame.data + 4);
Expand Down Expand Up @@ -187,7 +187,7 @@ void ODriveCanNode::request_state_callback() {
std::unique_lock<std::mutex> guard(axis_state_mutex_);
write_le<uint32_t>(axis_state_, frame.data);
}
frame.len = 4;
frame.can_dlc = 4;
can_intf_.send_can_frame(frame);
}

Expand All @@ -202,7 +202,7 @@ void ODriveCanNode::ctrl_msg_callback() {
write_le<uint32_t>(ctrl_msg_.input_mode, frame.data + 4);
control_mode = ctrl_msg_.control_mode;
}
frame.len = 8;
frame.can_dlc = 8;
can_intf_.send_can_frame(frame);

frame = can_frame{};
Expand All @@ -216,7 +216,7 @@ void ODriveCanNode::ctrl_msg_callback() {
frame.can_id = node_id_ << 5 | kSetInputTorque;
std::lock_guard<std::mutex> guard(ctrl_msg_mutex_);
write_le<float>(ctrl_msg_.input_torque, frame.data);
frame.len = 4;
frame.can_dlc = 4;
break;
}
case ControlMode::kVelocityControl: {
Expand All @@ -225,7 +225,7 @@ void ODriveCanNode::ctrl_msg_callback() {
std::lock_guard<std::mutex> guard(ctrl_msg_mutex_);
write_le<float>(ctrl_msg_.input_vel, frame.data);
write_le<float>(ctrl_msg_.input_torque, frame.data + 4);
frame.len = 8;
frame.can_dlc = 8;
break;
}
case ControlMode::kPositionControl: {
Expand All @@ -235,7 +235,7 @@ void ODriveCanNode::ctrl_msg_callback() {
write_le<float>(ctrl_msg_.input_pos, frame.data);
write_le<int8_t>(((int8_t)((ctrl_msg_.input_vel) * 1000)), frame.data + 4);
write_le<int8_t>(((int8_t)((ctrl_msg_.input_torque) * 1000)), frame.data + 6);
frame.len = 8;
frame.can_dlc = 8;
break;
}
default:
Expand Down

0 comments on commit 887fb60

Please sign in to comment.