From 66703ec5fef459f9399f19bee5b2ae20b666f4c0 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Thu, 19 Nov 2026 21:00:19 +0100 Subject: [PATCH] open manipulator node: support MLX90614 --- CMakeLists.txt | 1 + .../a4wd3_open_manipulator_i2c.hpp | 12 +++---- hardware/src/a4wd3_open_manipulator_i2c.cpp | 34 ++++++++++--------- srv/IrTemp.srv | 2 ++ 4 files changed, 26 insertions(+), 23 deletions(-) create mode 100644 srv/IrTemp.srv diff --git a/CMakeLists.txt b/CMakeLists.txt index c0e0d61..1bfa355 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,7 @@ find_package(rosidl_default_generators REQUIRED) rosidl_generate_interfaces(${PROJECT_NAME} msg/HardwareError.msg srv/GetError.srv + srv/IrTemp.srv DEPENDENCIES std_msgs ) diff --git a/hardware/include/a4wd3_open_manipulator/a4wd3_open_manipulator_i2c.hpp b/hardware/include/a4wd3_open_manipulator/a4wd3_open_manipulator_i2c.hpp index 865d3e5..aa4b180 100644 --- a/hardware/include/a4wd3_open_manipulator/a4wd3_open_manipulator_i2c.hpp +++ b/hardware/include/a4wd3_open_manipulator/a4wd3_open_manipulator_i2c.hpp @@ -28,6 +28,7 @@ #include "std_srvs/srv/set_bool.hpp" #include "std_msgs/msg/u_int8.hpp" #include "a4wd3_open_manipulator/srv/get_error.hpp" +#include "a4wd3_open_manipulator/srv/ir_temp.hpp" #define I2C_FILE "/dev/i2c-7" #define I2C_ADDR (0x60 >> 1) @@ -93,13 +94,9 @@ private: }; static constexpr double kLimitTolerance = 1e-3; - void cbTorqueEnable( - const std::shared_ptr req, - std::shared_ptr res); - - void cbGetError( - const std::shared_ptr req, - std::shared_ptr res); + void cbTorqueEnable(const std::shared_ptr req, std::shared_ptr res); + void cbGetError(const std::shared_ptr req, std::shared_ptr res); + void cbGetIrTemp(const std::shared_ptr req, std::shared_ptr res); void light_callback(const std_msgs::msg::UInt8 msg); @@ -126,6 +123,7 @@ private: rclcpp::Service::SharedPtr torque_enable_service_; rclcpp::Service::SharedPtr get_error_service_; + rclcpp::Service::SharedPtr get_temp_service_; rclcpp::Subscription::SharedPtr sub_light; double cmd[NUM_JOINTS] = {NAN, NAN, NAN, NAN, NAN}; diff --git a/hardware/src/a4wd3_open_manipulator_i2c.cpp b/hardware/src/a4wd3_open_manipulator_i2c.cpp index 45b3f51..9eaba10 100644 --- a/hardware/src/a4wd3_open_manipulator_i2c.cpp +++ b/hardware/src/a4wd3_open_manipulator_i2c.cpp @@ -50,14 +50,9 @@ hardware_interface::CallbackReturn A4wd3OpenManipulatorI2C::on_configure( return hardware_interface::CallbackReturn::ERROR; } - torque_enable_service_ = get_node()->create_service( - "torque_enable", std::bind( - &A4wd3OpenManipulatorI2C::cbTorqueEnable, this, std::placeholders::_1, - std::placeholders::_2)); - get_error_service_ = get_node()->create_service( - "get_error", std::bind( - &A4wd3OpenManipulatorI2C::cbGetError, this, std::placeholders::_1, - std::placeholders::_2)); + torque_enable_service_ = get_node()->create_service("torque_enable", std::bind(&A4wd3OpenManipulatorI2C::cbTorqueEnable, this, std::placeholders::_1, std::placeholders::_2)); + get_error_service_ = get_node()->create_service("get_error", std::bind(&A4wd3OpenManipulatorI2C::cbGetError, this, std::placeholders::_1, std::placeholders::_2)); + get_temp_service_ = get_node()->create_service("get_ir_temp", std::bind(&A4wd3OpenManipulatorI2C::cbGetIrTemp, this, std::placeholders::_1, std::placeholders::_2)); sub_light = get_node()->create_subscription("/headlight", rclcpp::SystemDefaultsQoS(), std::bind(&A4wd3OpenManipulatorI2C::light_callback, this, std::placeholders::_1)); RCLCPP_INFO(get_logger(), "Configuration successful"); @@ -455,18 +450,12 @@ uint8_t A4wd3OpenManipulatorI2C::dynamixel_readdword(uint8_t id, uint8_t cmd, in return 255; } -void A4wd3OpenManipulatorI2C::cbTorqueEnable( - const std::shared_ptr req, - std::shared_ptr res) -{ +void A4wd3OpenManipulatorI2C::cbTorqueEnable(const std::shared_ptr req, std::shared_ptr res) { RCLCPP_INFO(get_logger(), "Setting torque enable=%d", (int)req->data); res->success = torque_enable(req->data); } -void A4wd3OpenManipulatorI2C::cbGetError( - const std::shared_ptr /*req*/, - std::shared_ptr res) -{ +void A4wd3OpenManipulatorI2C::cbGetError(const std::shared_ptr /*req*/, std::shared_ptr res) { RCLCPP_INFO(get_logger(), "Reading Hardware Error Status"); for (int id = 11, i = 0; id <= 15; id++, i++) { @@ -485,6 +474,19 @@ void A4wd3OpenManipulatorI2C::cbGetError( } } +// ros2 service call /get_ir_temp a4wd3_open_manipulator/srv/IrTemp +void A4wd3OpenManipulatorI2C::cbGetIrTemp(const std::shared_ptr /*req*/, std::shared_ptr res) { + int16_t val; + + RCLCPP_INFO(get_logger(), "Reading IR temperature"); + if (dynamixel_readword(0x21, 0x2, &val) != 1) { + RCLCPP_ERROR(get_logger(), "I2C dynamixel reading ir temperature"); + val = 0xffff; + } + res->temp = val; +} + + } // namespace a4wd3_open_manipulator #include "pluginlib/class_list_macros.hpp" diff --git a/srv/IrTemp.srv b/srv/IrTemp.srv new file mode 100644 index 0000000..4f17a4c --- /dev/null +++ b/srv/IrTemp.srv @@ -0,0 +1,2 @@ +--- +uint16 temp -- 2.39.5