diff --git a/deploy/robot_ws/src/go2py_node/src/bridge.cpp b/deploy/robot_ws/src/go2py_node/src/bridge.cpp index b438a54..cc1f1fd 100644 --- a/deploy/robot_ws/src/go2py_node/src/bridge.cpp +++ b/deploy/robot_ws/src/go2py_node/src/bridge.cpp @@ -1,6 +1,7 @@ #include "unitree_go/msg/low_state.hpp" #include "unitree_go/msg/imu_state.hpp" #include "unitree_go/msg/motor_state.hpp" +#include "unitree_go/msg/go2py_status.hpp" #include "unitree_go/msg/go2py_low_cmd.hpp" #include "unitree_go/msg/low_cmd.hpp" @@ -54,6 +55,7 @@ class Custom: public rclcpp::Node lowcmd_puber = this->create_publisher("/lowcmd", 10); api_publisher = this->create_publisher("/api/robot_state/request", 10); + status_publisher = this->create_publisher("/go2py/status", 10); } private: @@ -91,6 +93,7 @@ class Custom: public rclcpp::Node uint64_t last_lowcmd_stamp = 0; xRockerBtnDataStruct _keyData; rclcpp::Publisher::SharedPtr api_publisher; + rclcpp::Publisher::SharedPtr status_publisher; void init_lowcmd() { @@ -125,6 +128,7 @@ class Custom: public rclcpp::Node float foot_force[4]; }highstate; int Estop = 0; + int sport_mode = 1; }; void Custom::lowstate_callback(unitree_go::msg::LowState::SharedPtr data) @@ -204,6 +208,7 @@ void Custom::lowstate_callback(unitree_go::msg::LowState::SharedPtr data) msg->header.identity.api_id = 1001; msg->parameter = "{\"name\":\"sport_mode\",\"switch\":0}"; api_publisher->publish(*msg); + sport_mode = 0; } if ((_keyData.btn.components.R2 == 1 && _keyData.btn.components.R1 == 1)) { @@ -213,6 +218,7 @@ void Custom::lowstate_callback(unitree_go::msg::LowState::SharedPtr data) msg->header.identity.api_id = 1001; msg->parameter = "{\"name\":\"sport_mode\",\"switch\":1}"; api_publisher->publish(*msg); + sport_mode = 1; } // std::cout << "Estop: " << Estop << std::endl; } @@ -340,6 +346,10 @@ void Custom::watchdog() } lowcmd_puber->publish(lowcmd_msg); } + auto msg = std::make_shared(); + msg->estop = Estop; + msg->sport_mode = sport_mode; + status_publisher->publish(*msg); } int main(int argc, char **argv) diff --git a/deploy/robot_ws/src/unitree/unitree_go/CMakeLists.txt b/deploy/robot_ws/src/unitree/unitree_go/CMakeLists.txt index 9621ad6..1ce1298 100755 --- a/deploy/robot_ws/src/unitree/unitree_go/CMakeLists.txt +++ b/deploy/robot_ws/src/unitree/unitree_go/CMakeLists.txt @@ -49,6 +49,7 @@ rosidl_generate_interfaces(${PROJECT_NAME} "msg/UwbSwitch.msg" "msg/WirelessController.msg" "msg/Go2pyLowCmd.msg" + "msg/Go2pyStatus.msg" DEPENDENCIES geometry_msgs ) diff --git a/deploy/robot_ws/src/unitree/unitree_go/msg/Go2pyStatus.msg b/deploy/robot_ws/src/unitree/unitree_go/msg/Go2pyStatus.msg new file mode 100644 index 0000000..c3ef32c --- /dev/null +++ b/deploy/robot_ws/src/unitree/unitree_go/msg/Go2pyStatus.msg @@ -0,0 +1,2 @@ +uint8 estop +uint8 sport_mode \ No newline at end of file