]> defiant.homedns.org Git - wt_open_manipulator.git/commitdiff
open manipulator node: support MLX90614
authorErik Andresen <erik@vontaene.de>
Thu, 19 Nov 2026 20:00:19 +0000 (21:00 +0100)
committerErik Andresen <erik@vontaene.de>
Thu, 19 Nov 2026 20:00:19 +0000 (21:00 +0100)
CMakeLists.txt
hardware/include/a4wd3_open_manipulator/a4wd3_open_manipulator_i2c.hpp
hardware/src/a4wd3_open_manipulator_i2c.cpp
srv/IrTemp.srv [new file with mode: 0644]

index c0e0d612471faea5389f6bf99d6c529ed82b0b60..1bfa3551d2ff12c96d532231ca914e936931e420 100644 (file)
@@ -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
 )
index 865d3e584c665d3e10bcb824751e449d9b0309b2..aa4b180e4ca1c20ef76325a077b51679c6434790 100644 (file)
@@ -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<std_srvs::srv::SetBool::Request> req,
-               std::shared_ptr<std_srvs::srv::SetBool::Response> res);
-
-       void cbGetError(
-               const std::shared_ptr<a4wd3_open_manipulator::srv::GetError::Request> req,
-               std::shared_ptr<a4wd3_open_manipulator::srv::GetError::Response> res);
+       void cbTorqueEnable(const std::shared_ptr<std_srvs::srv::SetBool::Request> req, std::shared_ptr<std_srvs::srv::SetBool::Response> res);
+       void cbGetError(const std::shared_ptr<a4wd3_open_manipulator::srv::GetError::Request> req, std::shared_ptr<a4wd3_open_manipulator::srv::GetError::Response> res);
+       void cbGetIrTemp(const std::shared_ptr<a4wd3_open_manipulator::srv::IrTemp::Request> req, std::shared_ptr<a4wd3_open_manipulator::srv::IrTemp::Response> res);
 
        void light_callback(const std_msgs::msg::UInt8 msg);
 
@@ -126,6 +123,7 @@ private:
 
        rclcpp::Service<std_srvs::srv::SetBool>::SharedPtr torque_enable_service_;
        rclcpp::Service<a4wd3_open_manipulator::srv::GetError>::SharedPtr get_error_service_;
+       rclcpp::Service<a4wd3_open_manipulator::srv::IrTemp>::SharedPtr get_temp_service_;
        rclcpp::Subscription<std_msgs::msg::UInt8>::SharedPtr sub_light;
 
        double cmd[NUM_JOINTS] = {NAN, NAN, NAN, NAN, NAN};
index 45b3f51540c37d5bbe6378679477f9fd8e2bd332..9eaba1094bfcb58a84701211fc7f0b81940027af 100644 (file)
@@ -50,14 +50,9 @@ hardware_interface::CallbackReturn A4wd3OpenManipulatorI2C::on_configure(
                return hardware_interface::CallbackReturn::ERROR;
        }
 
-       torque_enable_service_ = get_node()->create_service<std_srvs::srv::SetBool>(
-               "torque_enable", std::bind(
-                       &A4wd3OpenManipulatorI2C::cbTorqueEnable, this, std::placeholders::_1,
-                       std::placeholders::_2));
-       get_error_service_ = get_node()->create_service<a4wd3_open_manipulator::srv::GetError>(
-               "get_error", std::bind(
-                       &A4wd3OpenManipulatorI2C::cbGetError, this, std::placeholders::_1,
-                       std::placeholders::_2));
+       torque_enable_service_ = get_node()->create_service<std_srvs::srv::SetBool>("torque_enable", std::bind(&A4wd3OpenManipulatorI2C::cbTorqueEnable, this, std::placeholders::_1, std::placeholders::_2));
+       get_error_service_ = get_node()->create_service<a4wd3_open_manipulator::srv::GetError>("get_error", std::bind(&A4wd3OpenManipulatorI2C::cbGetError, this, std::placeholders::_1, std::placeholders::_2));
+       get_temp_service_ = get_node()->create_service<a4wd3_open_manipulator::srv::IrTemp>("get_ir_temp", std::bind(&A4wd3OpenManipulatorI2C::cbGetIrTemp, this, std::placeholders::_1, std::placeholders::_2));
        sub_light = get_node()->create_subscription<std_msgs::msg::UInt8>("/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<std_srvs::srv::SetBool::Request> req,
-       std::shared_ptr<std_srvs::srv::SetBool::Response> res)
-{
+void A4wd3OpenManipulatorI2C::cbTorqueEnable(const std::shared_ptr<std_srvs::srv::SetBool::Request> req, std::shared_ptr<std_srvs::srv::SetBool::Response> 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<a4wd3_open_manipulator::srv::GetError::Request> /*req*/,
-       std::shared_ptr<a4wd3_open_manipulator::srv::GetError::Response> res)
-{
+void A4wd3OpenManipulatorI2C::cbGetError(const std::shared_ptr<a4wd3_open_manipulator::srv::GetError::Request> /*req*/, std::shared_ptr<a4wd3_open_manipulator::srv::GetError::Response> 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<a4wd3_open_manipulator::srv::IrTemp::Request> /*req*/, std::shared_ptr<a4wd3_open_manipulator::srv::IrTemp::Response> 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 (file)
index 0000000..4f17a4c
--- /dev/null
@@ -0,0 +1,2 @@
+---
+uint16 temp