]> defiant.homedns.org Git - wt_open_manipulator.git/commitdiff
Added laserpointer /headpointer subscriber ros2_a4wd3
authorErik Andresen <erik@vontaene.de>
Sat, 21 Nov 2026 17:44:46 +0000 (18:44 +0100)
committerErik Andresen <erik@vontaene.de>
Sat, 21 Nov 2026 17:44:46 +0000 (18:44 +0100)
hardware/include/a4wd3_open_manipulator/a4wd3_open_manipulator_i2c.hpp
hardware/src/a4wd3_open_manipulator_i2c.cpp

index aa4b180e4ca1c20ef76325a077b51679c6434790..caa4169dab6b520d73e307049838d999b687da58 100644 (file)
@@ -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<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);
+       void laser_callback(const std_msgs::msg::Bool msg);
 
        bool torque_enable(bool enable);
 
@@ -125,6 +127,7 @@ private:
        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;
+       rclcpp::Subscription<std_msgs::msg::Bool>::SharedPtr sub_laser;
 
        double cmd[NUM_JOINTS] = {NAN, NAN, NAN, NAN, NAN};
        double cmd_pre[NUM_JOINTS] = {NAN, NAN, NAN, NAN, NAN};
index 1fb186a0a4c0ef7fac3696fa4b3395bfade1ecc2..ff122fec3557c875141d087a5b81977e767b52ba 100644 (file)
@@ -54,6 +54,7 @@ hardware_interface::CallbackReturn A4wd3OpenManipulatorI2C::on_configure(
        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));
+       sub_laser = get_node()->create_subscription<std_msgs::msg::Bool>("/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<uint8_t>(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)
 {