From: Erik Andresen Date: Sat, 21 Nov 2026 17:44:46 +0000 (+0100) Subject: Added laserpointer /headpointer subscriber X-Git-Url: https://defiant.homedns.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fros2_a4wd3;p=wt_open_manipulator.git Added laserpointer /headpointer subscriber --- 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 aa4b180..caa4169 100644 --- a/hardware/include/a4wd3_open_manipulator/a4wd3_open_manipulator_i2c.hpp +++ b/hardware/include/a4wd3_open_manipulator/a4wd3_open_manipulator_i2c.hpp @@ -27,6 +27,7 @@ #include "rclcpp_lifecycle/state.hpp" #include "std_srvs/srv/set_bool.hpp" #include "std_msgs/msg/u_int8.hpp" +#include "std_msgs/msg/bool.hpp" #include "a4wd3_open_manipulator/srv/get_error.hpp" #include "a4wd3_open_manipulator/srv/ir_temp.hpp" @@ -99,6 +100,7 @@ private: void cbGetIrTemp(const std::shared_ptr req, std::shared_ptr res); void light_callback(const std_msgs::msg::UInt8 msg); + void laser_callback(const std_msgs::msg::Bool msg); bool torque_enable(bool enable); @@ -125,6 +127,7 @@ private: rclcpp::Service::SharedPtr get_error_service_; rclcpp::Service::SharedPtr get_temp_service_; rclcpp::Subscription::SharedPtr sub_light; + rclcpp::Subscription::SharedPtr sub_laser; 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 1fb186a..ff122fe 100644 --- a/hardware/src/a4wd3_open_manipulator_i2c.cpp +++ b/hardware/src/a4wd3_open_manipulator_i2c.cpp @@ -54,6 +54,7 @@ hardware_interface::CallbackReturn A4wd3OpenManipulatorI2C::on_configure( 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)); + sub_laser = get_node()->create_subscription("/headpointer", rclcpp::SystemDefaultsQoS(), std::bind(&A4wd3OpenManipulatorI2C::laser_callback, this, std::placeholders::_1)); RCLCPP_INFO(get_logger(), "Configuration successful"); return hardware_interface::CallbackReturn::SUCCESS; @@ -330,6 +331,13 @@ void A4wd3OpenManipulatorI2C::light_callback(const std_msgs::msg::UInt8 msg) { } } +// ros2 topic pub -1 /headpointer std_msgs/msg/Bool "{data: true}" +void A4wd3OpenManipulatorI2C::laser_callback(const std_msgs::msg::Bool msg) { + if (dynamixel_writebyte(0x21, 0x3, static_cast(msg.data)) != 1) { + RCLCPP_ERROR(get_logger(), "I2C AVR id=0x21 Laser"); + } +} + int A4wd3OpenManipulatorI2C::dynamixel_write( uint8_t * write_data, int write_num, uint8_t * read_data, int read_num) {