Changed the way we communicate with the stepper driver #6
@ -66,14 +66,18 @@ hardware_interface::return_type mg::MgStepperInterface::read(const rclcpp::Time&
|
|||||||
}
|
}
|
||||||
|
|
||||||
hardware_interface::return_type mg::MgStepperInterface::write(const rclcpp::Time&, const rclcpp::Duration&) {
|
hardware_interface::return_type mg::MgStepperInterface::write(const rclcpp::Time&, const rclcpp::Duration&) {
|
||||||
std::string cmd_left;
|
union {
|
||||||
std::string cmd_right;
|
std::array<u_char, sizeof(double)> bytes;
|
||||||
|
double data;
|
||||||
cmd_left = std::to_string(left_wheel_vel_cmd / (2 * M_PI)) + " ";
|
} value{};
|
||||||
cmd_right = std::to_string(-right_wheel_vel_cmd / (2 * M_PI));
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
odrive_serial_interface.Write(cmd_left + cmd_right);
|
odrive_serial_interface.Write("s;");
|
||||||
|
value.data = left_wheel_vel_cmd / (2 * M_PI);
|
||||||
|
for (const auto& bt : value.bytes) { odrive_serial_interface.WriteByte(bt); }
|
||||||
|
value.data = -right_wheel_vel_cmd / (2 * M_PI);
|
||||||
|
for (const auto& bt : value.bytes) { odrive_serial_interface.WriteByte(bt); }
|
||||||
|
|
||||||
} catch (const std::runtime_error& e) { return hardware_interface::return_type::ERROR; }
|
} catch (const std::runtime_error& e) { return hardware_interface::return_type::ERROR; }
|
||||||
return hardware_interface::return_type::OK;
|
return hardware_interface::return_type::OK;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user