]> defiant.homedns.org Git - wt_open_manipulator.git/commitdiff
Add headlight subscription
authorErik Andresen <erik@vontaene.de>
Thu, 22 Oct 2026 17:16:39 +0000 (19:16 +0200)
committerErik Andresen <erik@vontaene.de>
Thu, 22 Oct 2026 17:16:39 +0000 (19:16 +0200)
hardware/include/a4wd3_open_manipulator/a4wd3_open_manipulator_i2c.hpp
hardware/src/a4wd3_open_manipulator_i2c.cpp

index cbbc061d0b7fd617cab21f2be8cb9fcf73e9d63a..865d3e584c665d3e10bcb824751e449d9b0309b2 100644 (file)
@@ -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<a4wd3_open_manipulator::srv::GetError::Request> req,
                std::shared_ptr<a4wd3_open_manipulator::srv::GetError::Response> 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<std_srvs::srv::SetBool>::SharedPtr torque_enable_service_;
        rclcpp::Service<a4wd3_open_manipulator::srv::GetError>::SharedPtr get_error_service_;
+       rclcpp::Subscription<std_msgs::msg::UInt8>::SharedPtr sub_light;
 
        double cmd[NUM_JOINTS] = {NAN, NAN, NAN, NAN, NAN};
        double cmd_pre[NUM_JOINTS] = {NAN, NAN, NAN, NAN, NAN};
index 9965b918fcd216aad3511cdda759998308ece569..3e172edb3787e36bb56a2b702edc16191435df5a 100644 (file)
@@ -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<std_msgs::msg::UInt8>("/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)
 {