From a559bac74a6020df2c6d2346430d02c1386bbf49 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Thu, 22 Oct 2026 19:16:39 +0200 Subject: [PATCH] Add headlight subscription --- .../a4wd3_open_manipulator/a4wd3_open_manipulator_i2c.hpp | 4 ++++ hardware/src/a4wd3_open_manipulator_i2c.cpp | 8 ++++++++ 2 files changed, 12 insertions(+) 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 cbbc061..865d3e5 100644 --- a/hardware/include/a4wd3_open_manipulator/a4wd3_open_manipulator_i2c.hpp +++ b/hardware/include/a4wd3_open_manipulator/a4wd3_open_manipulator_i2c.hpp @@ -26,6 +26,7 @@ #include "rclcpp/rclcpp.hpp" #include "rclcpp_lifecycle/state.hpp" #include "std_srvs/srv/set_bool.hpp" +#include "std_msgs/msg/u_int8.hpp" #include "a4wd3_open_manipulator/srv/get_error.hpp" #define I2C_FILE "/dev/i2c-7" @@ -100,6 +101,8 @@ private: const std::shared_ptr req, std::shared_ptr res); + void light_callback(const std_msgs::msg::UInt8 msg); + bool torque_enable(bool enable); bool setup_dynamixels(); @@ -123,6 +126,7 @@ private: rclcpp::Service::SharedPtr torque_enable_service_; rclcpp::Service::SharedPtr get_error_service_; + rclcpp::Subscription::SharedPtr sub_light; double cmd[NUM_JOINTS] = {NAN, NAN, NAN, NAN, NAN}; double cmd_pre[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 9965b91..3e172ed 100644 --- a/hardware/src/a4wd3_open_manipulator_i2c.cpp +++ b/hardware/src/a4wd3_open_manipulator_i2c.cpp @@ -58,6 +58,7 @@ hardware_interface::CallbackReturn A4wd3OpenManipulatorI2C::on_configure( "get_error", std::bind( &A4wd3OpenManipulatorI2C::cbGetError, this, std::placeholders::_1, std::placeholders::_2)); + sub_light = get_node()->create_subscription("/headlight", 10, std::bind(&A4wd3OpenManipulatorI2C::light_callback, this, std::placeholders::_1)); RCLCPP_INFO(get_logger(), "Configuration successful"); return hardware_interface::CallbackReturn::SUCCESS; @@ -327,6 +328,13 @@ bool A4wd3OpenManipulatorI2C::torque_enable(bool enable) return ret; } +// ros2 topic pub -1 /headlight std_msgs/msg/UInt8 "{data: 1}" +void A4wd3OpenManipulatorI2C::light_callback(const std_msgs::msg::UInt8 msg) { + if (dynamixel_writebyte(0x21, 0x1, msg.data) != 1) { + RCLCPP_ERROR(get_logger(), "I2C AVR id=0x21 LED"); + } +} + int A4wd3OpenManipulatorI2C::dynamixel_write( uint8_t * write_data, int write_num, uint8_t * read_data, int read_num) { -- 2.39.5