|
@@ -1,766 +0,0 @@
|
|
|
-#include <rcutils/logging_macros.h>
|
|
|
-
|
|
|
-#include <cinttypes>
|
|
|
-#include <functional>
|
|
|
-
|
|
|
-#include <map>
|
|
|
-#include <memory>
|
|
|
-#include <rclcpp/rclcpp.hpp>
|
|
|
-#include <rclcpp_components/register_node_macro.hpp>
|
|
|
-
|
|
|
-#include <set>
|
|
|
-#include <string>
|
|
|
-
|
|
|
-#include "saturn_controller_interface/saturn_controller_interface.hpp"
|
|
|
-
|
|
|
-#define ROS_INFO_NAMED RCUTILS_LOG_INFO_NAMED
|
|
|
-#define ROS_INFO_COND_NAMED RCUTILS_LOG_INFO_EXPRESSION_NAMED
|
|
|
-
|
|
|
-namespace saturn_controller_interface {
|
|
|
-
|
|
|
-/**
|
|
|
- * Constructs SaturnControllerInterface.
|
|
|
- */
|
|
|
-SaturnControllerInterface::SaturnControllerInterface(const rclcpp::NodeOptions& options)
|
|
|
- : Node("saturn_controller_interface_node", options)
|
|
|
-{
|
|
|
- this->declare_parameter<std::string>("remote_controller_ip", "192.168.100.103");
|
|
|
- this->get_parameter("remote_controller_ip",remote_ip);
|
|
|
- rcClientInterfaceInit(remote_ip);
|
|
|
-
|
|
|
- RCLCPP_WARN(this->get_logger(), "--SaturnControllerInterface 00 --ip=[%s] ", remote_ip.c_str());
|
|
|
-
|
|
|
- // subscription
|
|
|
- //1, 导航下发速度
|
|
|
- cmd_vel_sub = this->create_subscription<geometry_msgs::msg::Twist>(
|
|
|
- "cmd_vel", rclcpp::QoS(10),
|
|
|
- std::bind(&SaturnControllerInterface::cmdVelCallback, this,
|
|
|
- std::placeholders::_1));
|
|
|
-
|
|
|
- //2, tag_detected (std_msgs::msg::Bool)
|
|
|
- tag_detected_sub = this->create_subscription<std_msgs::msg::Bool>(
|
|
|
- "tag_detected", rclcpp::QoS(10),
|
|
|
- std::bind(&SaturnControllerInterface::tagDetectedCallback, this,
|
|
|
- std::placeholders::_1));
|
|
|
-
|
|
|
- //3, pose in tag (geometry_msgs::msg::PoseStamped)
|
|
|
- pose_in_tag_sub = this->create_subscription<geometry_msgs::msg::PoseStamped>(
|
|
|
- "pose_in_tag", rclcpp::QoS(10),
|
|
|
- std::bind(&SaturnControllerInterface::poseInTagCallback, this,
|
|
|
- std::placeholders::_1));
|
|
|
-
|
|
|
- guardian_sub = this->create_subscription<daystar_navigation_msgs::msg::Guardian>(
|
|
|
- "guardian", rclcpp::QoS(10),
|
|
|
- std::bind(&SaturnControllerInterface::guardianCallback, this,
|
|
|
- std::placeholders::_1));
|
|
|
-
|
|
|
- //4, task_mode (std_msgs::msg::Bool)
|
|
|
- //机器人是否处于任务模式,与机器人自身状态 (不支持)
|
|
|
- task_mode_sub = this->create_subscription<std_msgs::msg::Bool>(
|
|
|
- "task_mode", rclcpp::QoS(10),
|
|
|
- std::bind(&SaturnControllerInterface::taskModeCallback, this,
|
|
|
- std::placeholders::_1));
|
|
|
-
|
|
|
- // 1, 六足机器人腿部里程计
|
|
|
- leg_odom_publisher = this->create_publisher<nav_msgs::msg::Odometry>("leg_odom", 5);
|
|
|
-
|
|
|
- // 2, robot_state(std_msgs::msg::UInt32): 机器人基本状态
|
|
|
- // 0 -> standdown
|
|
|
- // 1 -> standingup
|
|
|
- // 2 -> standup
|
|
|
- // 3 -> enable forcecontrol
|
|
|
- // 4 -> motion
|
|
|
- // 5 -> sitting down
|
|
|
- // 6 -> fall down
|
|
|
- robot_state_publisher = this->create_publisher<std_msgs::msg::UInt32>("robot_state", 10);
|
|
|
-
|
|
|
- // 3, dock_state(std_msgs::msg::UInt32): 机器人上桩状态
|
|
|
- // 0 -> idle
|
|
|
- // 1 -> going to dock
|
|
|
- // 2 -> stand above dock
|
|
|
- // 3 -> adjust pose
|
|
|
- // 4 -> lie on dock
|
|
|
- // 5 -> standing after charging
|
|
|
- // 6 -> leaving dock
|
|
|
- // 7 -> leave dock
|
|
|
- dock_state_publisher = this->create_publisher<std_msgs::msg::UInt32>("dock_state", 10);
|
|
|
-
|
|
|
- // 4, 控制模式-手动、导航
|
|
|
- // control_mode(std_msgs::msg::UInt8):
|
|
|
- // 0 -> 手持遥控
|
|
|
- // 1 -> 自动(导航)
|
|
|
- nav_or_manual_publisher = this->create_publisher<std_msgs::msg::UInt8>("control_mode", 10);
|
|
|
-
|
|
|
- // 5, gait(std_msgs::msg::UInt8): 机器人当前步态
|
|
|
- // 0 -> 行走
|
|
|
- // 1 -> 楼梯
|
|
|
- // 2 -> 湿滑
|
|
|
- // 3 -> 跑步
|
|
|
- //saturn 设置六足机器人场景步态(1, 趴下, 2,行走步态, 3, 楼梯步态)
|
|
|
- gait_scene_publisher = this->create_publisher<std_msgs::msg::UInt8>("gait", 10);
|
|
|
-
|
|
|
- // 6, battery_state(sensor_msgs::msg::BatteryState):电池电量信息,目前只有percentage字段有意义,
|
|
|
- // 粗略代表机器人当前电量百分比
|
|
|
- battery_state_publisher = this->create_publisher<sensor_msgs::msg::BatteryState>("battery_state", 5);
|
|
|
-
|
|
|
- // 7, robot_mode 机器人模式,用于向巡检平台上报
|
|
|
- // 0->空闲(默认)
|
|
|
- // 1->手持遥控
|
|
|
- // 2->任务
|
|
|
- // 3->充电中
|
|
|
- robot_mode_publisher = this->create_publisher<std_msgs::msg::Int32>("robot_mode", 10);
|
|
|
-
|
|
|
- // 8,charge_state(std_msgs::msg::Bool)机器人在充电桩充电返回true,否则返回false
|
|
|
- charge_state_publisher = this->create_publisher<std_msgs::msg::Bool>("charge_state", 10);
|
|
|
-
|
|
|
- //9, 六足机器人IMU数据
|
|
|
- imu_publisher = this->create_publisher<sensor_msgs::msg::Imu>("imu", 5);
|
|
|
-
|
|
|
- // services
|
|
|
- // 1, robot_command (ysc_robot_msgs::srv::RobotCommand);
|
|
|
- // 对机器人的基本控制接口,如切换步态,上下桩,起立,趴下
|
|
|
- //当前电量、最高关节温度、最高驱动温度、六足机器人步态状态(趴下、行走步态、楼梯步态)
|
|
|
- robot_command_service = this->create_service<ysc_robot_msgs::srv::RobotCommand>("robot_command",
|
|
|
- std::bind(&SaturnControllerInterface::RobotCommandCallback, this,
|
|
|
- std::placeholders::_1, std::placeholders::_2));
|
|
|
-
|
|
|
- rc_version_service = this->create_service<saturn_msgs::srv::RcVersion>("rc_version",
|
|
|
- std::bind(&SaturnControllerInterface::RcVersionCallback, this,
|
|
|
- std::placeholders::_1, std::placeholders::_2));
|
|
|
-
|
|
|
- driver_enable_service = this->create_service<saturn_msgs::srv::DriverEnable>("rc_driver_enable",
|
|
|
- std::bind(&SaturnControllerInterface::DriverEnableCallback, this,
|
|
|
- std::placeholders::_1, std::placeholders::_2));
|
|
|
-
|
|
|
- height_scale_service = this->create_service<saturn_msgs::srv::HeightScale>("rc_height_scale",
|
|
|
- std::bind(&SaturnControllerInterface::HeightScaleCallback, this,
|
|
|
- std::placeholders::_1, std::placeholders::_2));
|
|
|
-
|
|
|
- velocity_scale_service = this->create_service<saturn_msgs::srv::VelocityScale>("rc_velocity_scale",
|
|
|
- std::bind(&SaturnControllerInterface::VelocityScaleCallback, this,
|
|
|
- std::placeholders::_1, std::placeholders::_2));
|
|
|
-
|
|
|
- //saturn 设置六足机器人场景步态(1, 趴下, 2,行走步态, 3, 楼梯步态)
|
|
|
- gait_scene_service = this->create_service<saturn_msgs::srv::GaitScene>("rc_gait_scene",
|
|
|
- std::bind(&SaturnControllerInterface::setGaitSceneCallback, this,
|
|
|
- std::placeholders::_1, std::placeholders::_2));
|
|
|
-
|
|
|
- auto_charge_service = this->create_service<saturn_msgs::srv::AutoCharge>("rc_auto_charge",
|
|
|
- std::bind(&SaturnControllerInterface::autoChargeCallback, this,
|
|
|
- std::placeholders::_1, std::placeholders::_2));
|
|
|
-
|
|
|
- nav_or_manual_service = this->create_service<saturn_msgs::srv::NavOrManual>("rc_nav_or_manual",
|
|
|
- std::bind(&SaturnControllerInterface::navOrManualControlCallback, this,
|
|
|
- std::placeholders::_1, std::placeholders::_2));
|
|
|
-
|
|
|
- guardian_switch_service = this->create_service<saturn_msgs::srv::GuardianSwitch>("guardian_switch",
|
|
|
- std::bind(&SaturnControllerInterface::guardianSwitchCallback, this,
|
|
|
- std::placeholders::_1, std::placeholders::_2));
|
|
|
-
|
|
|
- guardian_service = this->create_service<daystar_navigation_msgs::srv::Guardian>("guardian",
|
|
|
- std::bind(&SaturnControllerInterface::guardianServiceCallback, this,
|
|
|
- std::placeholders::_1, std::placeholders::_2));
|
|
|
-
|
|
|
- tip_position_wrt_hip_publisher =
|
|
|
- this->create_publisher<std_msgs::msg::Float32MultiArray>("tip_position_wrt_hip", 10);
|
|
|
- touch_detection_publisher =
|
|
|
- this->create_publisher<std_msgs::msg::Float32MultiArray>("touch_detection", 10);
|
|
|
-
|
|
|
- //当前电量、最高关节温度、最高驱动温度、六足机器人步态状态(趴下、行走步态、楼梯步态)
|
|
|
- common_status_publisher = this->create_publisher<saturn_msgs::msg::CommonStatus>("rc_common_status", 5);
|
|
|
- //yunshenchu 故障上报, 32位的数字,表示错误码
|
|
|
- error_state_publisher = this->create_publisher<std_msgs::msg::Int32>("rc_error_state", 5);
|
|
|
- //yunshenchu 六足机器人关节角度
|
|
|
- joint_state_publisher = this->create_publisher<sensor_msgs::msg::JointState>("joint_states", 5);
|
|
|
-
|
|
|
- //yunshenchu 六足机器人位姿 文档2.3 绝影四足机器人位姿调整(需要确认是发布还是订阅)
|
|
|
- pose_estimate_sub = this->create_subscription<geometry_msgs::msg::PoseWithCovarianceStamped>(
|
|
|
- "rc_pose_estimate", rclcpp::QoS(10),
|
|
|
- std::bind(&SaturnControllerInterface::poseEstimateCallback, this,
|
|
|
- std::placeholders::_1));
|
|
|
-
|
|
|
- this->declare_parameter<std::int32_t>("imu_sender_frequency", 1000);
|
|
|
- this->get_parameter("imu_sender_frequency",imu_frquency);
|
|
|
-
|
|
|
- this->declare_parameter<std::int32_t>("common_status_frequency", 20);
|
|
|
- this->get_parameter("common_status_frequency",com_frquency);
|
|
|
-
|
|
|
- RCLCPP_WARN(this->get_logger(), "SaturnControllerInterface timer --imu_frquency=[%d] com_frquency=[%d]-", imu_frquency, com_frquency);
|
|
|
-
|
|
|
- run_imu_thread_ = true;
|
|
|
- imu_thread_ = std::thread(&SaturnControllerInterface::ImuPublisherThread, this);
|
|
|
-
|
|
|
- run_legged_odom_thread = true;
|
|
|
- legged_odom_thread = std::thread(&SaturnControllerInterface::LeggedOdomPublisherThread, this);
|
|
|
-
|
|
|
- run_common_state_thread_ = true;
|
|
|
- common_state_thread_ = std::thread(&SaturnControllerInterface::CommonPublisherThread, this);
|
|
|
- robot_mode_backup = -1;
|
|
|
-}
|
|
|
-
|
|
|
-SaturnControllerInterface::~SaturnControllerInterface() {
|
|
|
- run_imu_thread_ = false;
|
|
|
- run_common_state_thread_ = false;
|
|
|
- run_legged_odom_thread = false;
|
|
|
- imu_thread_.join();
|
|
|
- common_state_thread_.join();
|
|
|
- legged_odom_thread.join();
|
|
|
-}
|
|
|
-
|
|
|
-void SaturnControllerInterface::ImuPublisherThread()
|
|
|
-{
|
|
|
- common::MC_MOTION_IMU_DATA imu_data;
|
|
|
- rclcpp::Rate rate(350); //200hz
|
|
|
- while(run_imu_thread_)
|
|
|
- {
|
|
|
- auto imu_message = sensor_msgs::msg::Imu();
|
|
|
- rcClientInterfaceGetImuData(&imu_data);
|
|
|
- // RCLCPP_WARN(this->get_logger(),
|
|
|
- // "ImuPublisherThread=[%f] [%f] [%f] [%f] -",
|
|
|
- // imu_data.orientation.x, imu_data.orientation.y,
|
|
|
- // imu_data.orientation.z, imu_data.orientation.w);
|
|
|
-
|
|
|
- imu_message.header.stamp = rclcpp::Clock().now();
|
|
|
- imu_message.header.frame_id = "imu";
|
|
|
-
|
|
|
- imu_message.orientation.x = imu_data.orientation.x;
|
|
|
- imu_message.orientation.y = imu_data.orientation.y;
|
|
|
- imu_message.orientation.z = imu_data.orientation.z;
|
|
|
- imu_message.orientation.w = imu_data.orientation.w;
|
|
|
-
|
|
|
- imu_message.angular_velocity.x = imu_data.angular_velocity.x;
|
|
|
- imu_message.angular_velocity.y = imu_data.angular_velocity.y;
|
|
|
- imu_message.angular_velocity.z = imu_data.angular_velocity.z;
|
|
|
-
|
|
|
- imu_message.linear_acceleration.x = imu_data.linear_acceleration.x;
|
|
|
- imu_message.linear_acceleration.y = imu_data.linear_acceleration.y;
|
|
|
- imu_message.linear_acceleration.z = imu_data.linear_acceleration.z;
|
|
|
-
|
|
|
- for(int i = 0; i < 9; i++){
|
|
|
- imu_message.orientation_covariance[i] = imu_data.orientation_covariance[i];
|
|
|
- imu_message.angular_velocity_covariance[i] = imu_data.angular_velocity_covariance[i];
|
|
|
- imu_message.linear_acceleration_covariance[i] = imu_data.linear_acceleration_covariance[i];
|
|
|
- }
|
|
|
- imu_publisher->publish(imu_message);
|
|
|
- rate.sleep();
|
|
|
- }
|
|
|
- return;
|
|
|
-}
|
|
|
-
|
|
|
-void SaturnControllerInterface::LeggedOdomPublisherThread()
|
|
|
-{
|
|
|
- rclcpp::Rate rate(200); //200hz
|
|
|
- while(run_legged_odom_thread)
|
|
|
- {
|
|
|
- common::JETSON_VISUAL_FOOTHOLD_STATE foothold_state;
|
|
|
- rcClientInterfaceGetVisualFootholdState(&foothold_state);
|
|
|
-
|
|
|
- // RCLCPP_INFO(rclcpp::get_logger("test"), "time GOT %ld odom %f ", foothold_state.timestamp, foothold_state.robot_odometry.point.x);
|
|
|
-
|
|
|
- //yunshenchu 六足机器人腿部里程计
|
|
|
- auto odometry_data = nav_msgs::msg::Odometry();
|
|
|
- // odometry_data.header.stamp = rclcpp::Clock().now();
|
|
|
- int sec = foothold_state.timestamp / 1000000000;
|
|
|
- int nanosec = foothold_state.timestamp % 1000000000;
|
|
|
- odometry_data.header.stamp.sec = sec;
|
|
|
- odometry_data.header.stamp.nanosec = nanosec;
|
|
|
- // RCLCPP_INFO(rclcpp::get_logger("test"), "time debug %ld %ld %ld", foothold_state.timestamp, odometry_data.header.stamp.sec, odometry_data.header.stamp.nanosec);
|
|
|
-
|
|
|
- odometry_data.header.frame_id = "odom";
|
|
|
- odometry_data.child_frame_id = "base_link";
|
|
|
- odometry_data.pose.pose.position.x = foothold_state.robot_odometry.point.x;
|
|
|
- odometry_data.pose.pose.position.y = foothold_state.robot_odometry.point.y;
|
|
|
- odometry_data.pose.pose.position.z = foothold_state.robot_odometry.point.z;
|
|
|
- // odometry_data.pose.pose.orientation.x = com_status_data.odometry.quaternion.x;
|
|
|
- // odometry_data.pose.pose.orientation.y = com_status_data.odometry.quaternion.y;
|
|
|
- // odometry_data.pose.pose.orientation.z = com_status_data.odometry.quaternion.z;
|
|
|
- // odometry_data.pose.pose.orientation.w = com_status_data.odometry.quaternion.w;
|
|
|
-
|
|
|
- // odometry_data.twist.twist.linear.x = com_status_data.odometry.twist.linear.x;
|
|
|
- // odometry_data.twist.twist.linear.y = com_status_data.odometry.twist.linear.y;
|
|
|
- // odometry_data.twist.twist.linear.z = com_status_data.odometry.twist.linear.z;
|
|
|
- // odometry_data.twist.twist.angular.x = com_status_data.odometry.twist.angular.x;
|
|
|
- // odometry_data.twist.twist.angular.y = com_status_data.odometry.twist.angular.y;
|
|
|
- // odometry_data.twist.twist.angular.z = com_status_data.odometry.twist.angular.z;
|
|
|
- leg_odom_publisher->publish(odometry_data);
|
|
|
- rate.sleep();
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-void SaturnControllerInterface::CommonPublisherThread()
|
|
|
-{
|
|
|
- rclcpp::Rate rate(50);
|
|
|
- while(run_common_state_thread_)
|
|
|
- {
|
|
|
- common::ROBOT_COMMON_STATUS com_status_data;
|
|
|
- // RCLCPP_WARN(this->get_logger(), "CommonPublisherThread 00 ");
|
|
|
- rcClientInterfaceGetCommonStatus(&com_status_data);
|
|
|
- //发布机器人状态信息。目前先和imu放在同一个线程中。
|
|
|
- auto common_message = saturn_msgs::msg::CommonStatus();
|
|
|
- common_message.network = com_status_data.network;
|
|
|
- common_message.belie_or_stand = com_status_data.belie_or_stand;
|
|
|
-
|
|
|
- auto pub_robot_state = std_msgs::msg::UInt32();
|
|
|
- if(common_message.belie_or_stand == robot_control::common::BODY_POSTURE_STATE::LIEDOWN)
|
|
|
- {
|
|
|
- pub_robot_state.data = 5;
|
|
|
- }
|
|
|
- else if(common_message.belie_or_stand == robot_control::common::BODY_POSTURE_STATE::STANDUP)
|
|
|
- {
|
|
|
- pub_robot_state.data = 2;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- pub_robot_state.data = -1;
|
|
|
- }
|
|
|
- robot_state_publisher->publish(pub_robot_state);
|
|
|
-
|
|
|
- //临时逻辑 todo
|
|
|
- auto pub_dock_state = std_msgs::msg::UInt32();
|
|
|
- if(common_message.belie_or_stand == robot_control::common::CHARGE_SWITCH_STATE::ENTER_SUCCEEDED)
|
|
|
- {
|
|
|
- pub_dock_state.data = 4;
|
|
|
- }
|
|
|
- else if((common_message.belie_or_stand == robot_control::common::CHARGE_SWITCH_STATE::ENTER_FAILED)
|
|
|
- || ((common_message.belie_or_stand == robot_control::common::CHARGE_SWITCH_STATE::EXIT_SUCCEEDED)))
|
|
|
- {
|
|
|
- pub_dock_state.data = 0;
|
|
|
- }
|
|
|
- dock_state_publisher->publish(pub_dock_state);
|
|
|
-
|
|
|
- common_message.emergency = com_status_data.emergency;
|
|
|
- common_message.avoidance = com_status_data.avoidance;
|
|
|
- common_message.heartbeat = com_status_data.heartbeat;
|
|
|
- robot_heartbeat = com_status_data.heartbeat;
|
|
|
- common_message.cur_speed = com_status_data.cur_speed;
|
|
|
- common_message.cur_height = com_status_data.cur_height;
|
|
|
- // common_message.position = com_status_data.position;
|
|
|
- common_message.max_height = com_status_data.max_height;
|
|
|
- common_message.max_speed = com_status_data.max_speed;
|
|
|
- common_message.cur_scene_switch_state = com_status_data.cur_scene_switch_state;
|
|
|
-
|
|
|
- common_message.joy_mode = com_status_data.joy_mode;
|
|
|
- auto nav_or_manual_state = std_msgs::msg::UInt8();
|
|
|
- if(common_message.joy_mode == robot_control::common::NAV_OR_JOY_MODE::nav_control)
|
|
|
- {
|
|
|
- nav_or_manual_state.data = 1;
|
|
|
- }else if(common_message.joy_mode == robot_control::common::NAV_OR_JOY_MODE::joy_control)
|
|
|
- {
|
|
|
- nav_or_manual_state.data = 0;
|
|
|
- }
|
|
|
- nav_or_manual_publisher->publish(nav_or_manual_state);
|
|
|
-
|
|
|
- common_message.cur_scene = com_status_data.cur_scene;
|
|
|
- robot_cur_scene = com_status_data.cur_scene;
|
|
|
- auto gait_scene_state = std_msgs::msg::UInt8();
|
|
|
- if((common_message.cur_scene == robot_control::common::SCENE_TYPE::WALKING)
|
|
|
- || (common_message.cur_scene == robot_control::common::SCENE_TYPE::CHARGE))
|
|
|
- {
|
|
|
- gait_scene_state.data = 0;
|
|
|
- }
|
|
|
- else if(common_message.cur_scene == robot_control::common::SCENE_TYPE::STAIRS)
|
|
|
- {
|
|
|
- gait_scene_state.data = 1;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- gait_scene_state.data = -1;
|
|
|
- }
|
|
|
- gait_scene_publisher->publish(gait_scene_state);
|
|
|
-
|
|
|
- auto tip_position_wrt_hip_message = std_msgs::msg::Float32MultiArray();
|
|
|
- for(int i = 0; i < LEG_NUMBER*3; i++)
|
|
|
- {
|
|
|
- // common_message.tip_position_wrt_hip[i] =com_status_data.tip_position_wrt_hip[i];
|
|
|
- // tip_position_wrt_hip_message.data[i] =com_status_data.tip_position_wrt_hip[i];
|
|
|
- }
|
|
|
-
|
|
|
- auto touch_detection_message = std_msgs::msg::Float32MultiArray();
|
|
|
- for(int i = 0; i < LEG_NUMBER; i++)
|
|
|
- {
|
|
|
- // common_message.touch_detection[i] =com_status_data.touch_detection[i];
|
|
|
- // touch_detection_message.data[i] =com_status_data.touch_detection[i];
|
|
|
- }
|
|
|
-
|
|
|
- // tip_position_wrt_hip_publisher->publish(tip_position_wrt_hip_message);
|
|
|
- // touch_detection_publisher->publish(touch_detection_message);
|
|
|
- // // common_message.charge_status.battery_info.power = com_status_data.charge_status.battery_info.power;
|
|
|
-
|
|
|
- float battery_power = 0.0;
|
|
|
- battery_power = com_status_data.charge_status.battery_info.level;
|
|
|
- if(battery_power < 0)
|
|
|
- {
|
|
|
- battery_power = 0;
|
|
|
- }
|
|
|
- else if(battery_power > 1)
|
|
|
- {
|
|
|
- battery_power = 1;
|
|
|
- }
|
|
|
- auto battery_state_state = sensor_msgs::msg::BatteryState();
|
|
|
- battery_state_state.percentage = battery_power;
|
|
|
- battery_state_publisher->publish(battery_state_state);
|
|
|
-
|
|
|
- auto robot_mode_state = std_msgs::msg::Int32();
|
|
|
-
|
|
|
- if((cur_robot_is_idle == true) && (nav_or_manual_state.data == 1))
|
|
|
- {
|
|
|
- robot_mode_state.data = 0;
|
|
|
- }
|
|
|
- else if(nav_or_manual_state.data == 0)
|
|
|
- {
|
|
|
- robot_mode_state.data = 1;
|
|
|
- }
|
|
|
- else if((cur_robot_is_idle == false) && (nav_or_manual_state.data == 1))
|
|
|
- {
|
|
|
- robot_mode_state.data = 2;
|
|
|
- }
|
|
|
- else if(common_message.cur_scene == robot_control::common::SCENE_TYPE::CHARGE)
|
|
|
- {
|
|
|
- robot_mode_state.data = 3;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- robot_mode_state.data = 0;
|
|
|
- }
|
|
|
- if(robot_mode_backup != robot_mode_state.data)
|
|
|
- {
|
|
|
- robot_mode_publisher->publish(robot_mode_state);
|
|
|
- }
|
|
|
- robot_mode_backup = robot_mode_state.data;
|
|
|
-
|
|
|
- auto pub_charge_state = std_msgs::msg::Bool();
|
|
|
- if(common_message.belie_or_stand == robot_control::common::AUTO_CHARGE_STATE::charging)
|
|
|
- {
|
|
|
- pub_charge_state.data = true;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- pub_charge_state.data = false;
|
|
|
- }
|
|
|
- charge_state_publisher->publish(pub_charge_state);
|
|
|
-
|
|
|
-
|
|
|
- common_status_publisher->publish(common_message);
|
|
|
-
|
|
|
- auto error_data = std_msgs::msg::Int32();
|
|
|
- error_data.data = com_status_data.error_code;
|
|
|
- //yunshenchu 故障上报, 32位的数字,表示错误码
|
|
|
- error_state_publisher->publish(error_data);
|
|
|
-
|
|
|
- common::ROBOT_JOINTS_STATUS joint_status_data;
|
|
|
- rcClientInterfaceGetJointsStatus(&joint_status_data);
|
|
|
- auto joints_state_message = sensor_msgs::msg::JointState();
|
|
|
- joints_state_message.header.stamp = rclcpp::Clock().now();
|
|
|
-
|
|
|
- joints_state_message.name.resize(18); //指定name数组长度
|
|
|
- joints_state_message.position.resize(18);//指定position数组长度
|
|
|
- joints_state_message.velocity.resize(18);//指定velocity数组长度
|
|
|
- joints_state_message.effort.resize(18);//指定effort数组长度
|
|
|
- for(int i = 0; i < 18; i++)
|
|
|
- {
|
|
|
- joints_state_message.name[i] ="joint" + std::to_string(i);//name数组的第一个元素赋值
|
|
|
- joints_state_message.position[i] = joint_status_data.joints[i].position;//position数组的第一个元素赋值
|
|
|
- joints_state_message.velocity[i] = joint_status_data.joints[i].velocity;//velocity数组的第一个元素赋值
|
|
|
- joints_state_message.effort[i] = joint_status_data.joints[i].effort;//effort数组的第一个元素赋值
|
|
|
- }
|
|
|
- //yunshenchu 六足机器人关节角度
|
|
|
- joint_state_publisher->publish(joints_state_message);
|
|
|
- rate.sleep();
|
|
|
- }
|
|
|
- return;
|
|
|
-}
|
|
|
-
|
|
|
-void SaturnControllerInterface::cmdVelCallback(
|
|
|
- const geometry_msgs::msg::Twist::SharedPtr vel_msg)
|
|
|
-{
|
|
|
- common::ROBOT_TWIST rc_direct;
|
|
|
- rc_direct.linear.x = vel_msg->linear.x * guardian_velocity_decay_ratio_;
|
|
|
- rc_direct.linear.y = vel_msg->linear.y;
|
|
|
- rc_direct.linear.z = vel_msg->linear.z;
|
|
|
- rc_direct.angular.x = vel_msg->angular.x;
|
|
|
- rc_direct.angular.y = vel_msg->angular.y;
|
|
|
- rc_direct.angular.z = vel_msg->angular.z;
|
|
|
- int64_t time_millis;
|
|
|
- rcClientInterfaceDirectionMovement(
|
|
|
- robot_control::common::NAV_OR_JOY_MODE::nav_control,
|
|
|
- rc_direct, robot_heartbeat);
|
|
|
- return;
|
|
|
-}
|
|
|
-
|
|
|
-void SaturnControllerInterface::tagDetectedCallback(
|
|
|
- const std_msgs::msg::Bool::SharedPtr tag_detected)
|
|
|
-{
|
|
|
- common::JETSON_CHARGE_COMMAND charge_command;
|
|
|
- if(tag_detected->data == true)
|
|
|
- {
|
|
|
- charge_command.tag_state = true;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- charge_command.tag_state = false;
|
|
|
- }
|
|
|
- rcClientInterfaceAutoRechargeCmd(robot_control::common::NAV_OR_JOY_MODE::nav_control, charge_command);
|
|
|
- return;
|
|
|
-}
|
|
|
-
|
|
|
-void SaturnControllerInterface::poseInTagCallback(
|
|
|
- const geometry_msgs::msg::PoseStamped::SharedPtr pose_in_tag)
|
|
|
-{
|
|
|
- common::JETSON_CHARGE_COMMAND charge_command;
|
|
|
- charge_command.position.x = pose_in_tag->pose.orientation.x;
|
|
|
- charge_command.position.y = pose_in_tag->pose.orientation.y;
|
|
|
- charge_command.position.z = pose_in_tag->pose.orientation.z;
|
|
|
- charge_command.position.w = pose_in_tag->pose.orientation.w;
|
|
|
- rcClientInterfaceAutoRechargeCmd(robot_control::common::NAV_OR_JOY_MODE::nav_control, charge_command);
|
|
|
- return;
|
|
|
-}
|
|
|
-
|
|
|
-void SaturnControllerInterface::guardianCallback(
|
|
|
- const daystar_navigation_msgs::msg::Guardian::SharedPtr guardian_msg)
|
|
|
-{
|
|
|
- float velocity_decay_ratio = guardian_msg->velocity_decay_ratio;
|
|
|
- std::string trigger_source = guardian_msg->trigger_source;
|
|
|
- rcClientInterfaceSetGuardian(robot_control::common::NAV_OR_JOY_MODE::nav_control, velocity_decay_ratio, trigger_source);
|
|
|
- // RCLCPP_INFO(rclcpp::get_logger("rclcpp"), "guardianCallback Incoming request: %f %s", guardian_msg->velocity_decay_ratio, guardian_msg->trigger_source.c_str());
|
|
|
- return;
|
|
|
-}
|
|
|
-
|
|
|
-void SaturnControllerInterface::taskModeCallback(
|
|
|
- const std_msgs::msg::Bool::SharedPtr task_mode)
|
|
|
-{
|
|
|
- //不支持
|
|
|
- if(task_mode->data == true)
|
|
|
- {
|
|
|
- cur_robot_is_idle = true;
|
|
|
- }else
|
|
|
- {
|
|
|
- cur_robot_is_idle = false;
|
|
|
- }
|
|
|
- return;
|
|
|
-}
|
|
|
-
|
|
|
-void SaturnControllerInterface::poseEstimateCallback(
|
|
|
- const geometry_msgs::msg::PoseWithCovarianceStamped::SharedPtr robot_pose)
|
|
|
-{
|
|
|
- // rcClientInterfaceBodyHighAdjust(high_scale->scale);
|
|
|
- common::ROBOT_POSE_ESTIMATE estimate;
|
|
|
- estimate.point.x = robot_pose->pose.pose.position.x;
|
|
|
- estimate.point.y = robot_pose->pose.pose.position.y;
|
|
|
- estimate.point.z = robot_pose->pose.pose.position.z;
|
|
|
- estimate.quaternion.x = robot_pose->pose.pose.orientation.x;
|
|
|
- estimate.quaternion.y = robot_pose->pose.pose.orientation.y;
|
|
|
- estimate.quaternion.z = robot_pose->pose.pose.orientation.z;
|
|
|
- estimate.quaternion.w = robot_pose->pose.pose.orientation.w;
|
|
|
- rcClientInterfaceSetPoseEstimate(robot_control::common::NAV_OR_JOY_MODE::nav_control, estimate);
|
|
|
- return;
|
|
|
-}
|
|
|
-
|
|
|
-//todo
|
|
|
-void SaturnControllerInterface::RobotCommandCallback(
|
|
|
- const ysc_robot_msgs::srv::RobotCommand::Request::SharedPtr request,
|
|
|
- ysc_robot_msgs::srv::RobotCommand::Response::SharedPtr response)
|
|
|
-{
|
|
|
-
|
|
|
- // RCLCPP_INFO(rclcpp::get_logger("rclcpp"), "Incoming request: %s", request->comamnd_name.c_str());
|
|
|
- bool result = true;
|
|
|
- std::string command = request->comamnd_name;
|
|
|
-
|
|
|
- if ("GoToDock" == request->comamnd_name)
|
|
|
- {
|
|
|
- result = rcClientInterfaceEnterOrExitCharge(robot_control::common::NAV_OR_JOY_MODE::nav_control, true);
|
|
|
- }
|
|
|
- else if ("LeaveDock" == request->comamnd_name)
|
|
|
- {
|
|
|
- result = rcClientInterfaceEnterOrExitCharge(robot_control::common::NAV_OR_JOY_MODE::nav_control, false);
|
|
|
- }
|
|
|
- else if ("HeartBeat" == request->comamnd_name)
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
- else if ("Stop" == request->comamnd_name)
|
|
|
- {
|
|
|
- common::ROBOT_TWIST rc_direct;
|
|
|
- rc_direct.linear.x = 0.0;
|
|
|
- rc_direct.linear.y = 0.0;
|
|
|
- rc_direct.linear.z = 0.0;
|
|
|
- rc_direct.angular.x = 0.0;
|
|
|
- rc_direct.angular.y = 0.0;
|
|
|
- rc_direct.angular.z = 0.0;
|
|
|
- result = rcClientInterfaceDirectionMovement(
|
|
|
- robot_control::common::NAV_OR_JOY_MODE::nav_control,
|
|
|
- rc_direct, robot_heartbeat);
|
|
|
- }
|
|
|
- else if ("StandUpDown" == request->comamnd_name)
|
|
|
- {
|
|
|
- if((robot_cur_scene == robot_control::common::SCENE_TYPE::WALKING)
|
|
|
- ||(robot_cur_scene == robot_control::common::SCENE_TYPE::STAIRS))
|
|
|
- {
|
|
|
- result = rcClientInterfaceSetScene(robot_control::common::NAV_OR_JOY_MODE::nav_control, common::SCENE_TYPE::LIE_DOWN);
|
|
|
- }else if (robot_cur_scene == robot_control::common::LIE_DOWN)
|
|
|
- {
|
|
|
- result = rcClientInterfaceSetScene(robot_control::common::NAV_OR_JOY_MODE::nav_control, common::SCENE_TYPE::WALKING);
|
|
|
- }
|
|
|
- }
|
|
|
- else if ("EnableNavigation" == request->comamnd_name)
|
|
|
- {
|
|
|
- common::NAV_OR_JOY_MODE nav_joy;
|
|
|
- nav_joy = common::NAV_OR_JOY_MODE::nav_control;
|
|
|
- result = rcClientInterfaceSetNavOrJoyControl(nav_joy);
|
|
|
- }
|
|
|
- else if ("EnableTeleoption" == request->comamnd_name)
|
|
|
- {
|
|
|
- common::NAV_OR_JOY_MODE nav_joy;
|
|
|
- nav_joy = common::NAV_OR_JOY_MODE::joy_control;
|
|
|
- result = rcClientInterfaceSetNavOrJoyControl(nav_joy);
|
|
|
- }
|
|
|
- else if ("StairsGait" == request->comamnd_name)
|
|
|
- {
|
|
|
- if(robot_cur_scene != robot_control::common::STAIRS)
|
|
|
- {
|
|
|
- result = rcClientInterfaceSetScene(robot_control::common::NAV_OR_JOY_MODE::nav_control, common::SCENE_TYPE::STAIRS);
|
|
|
- }
|
|
|
- }
|
|
|
- else if ("OrdinaryGait" == request->comamnd_name)
|
|
|
- {
|
|
|
- if (robot_cur_scene != robot_control::common::SCENE_TYPE::WALKING)
|
|
|
- {
|
|
|
- result = rcClientInterfaceSetScene(robot_control::common::NAV_OR_JOY_MODE::nav_control, common::SCENE_TYPE::WALKING);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- response->result = result;
|
|
|
- return;
|
|
|
-}
|
|
|
-
|
|
|
-void SaturnControllerInterface::RcVersionCallback(const saturn_msgs::srv::RcVersion::Request::SharedPtr request,
|
|
|
- saturn_msgs::srv::RcVersion::Response::SharedPtr response)
|
|
|
-{
|
|
|
- response->version = rcClientInterfaceGetMcVersion(request->type);
|
|
|
-
|
|
|
- // RCLCPP_INFO(rclcpp::get_logger("rclcpp"), "Incoming request---: %d", request->type);
|
|
|
- return;
|
|
|
-}
|
|
|
-
|
|
|
-void SaturnControllerInterface::DriverEnableCallback(const saturn_msgs::srv::DriverEnable::Request::SharedPtr request,
|
|
|
- saturn_msgs::srv::DriverEnable::Response::SharedPtr response)
|
|
|
-{
|
|
|
- response->res = rcClientInterfaceDriverEnable(robot_control::common::NAV_OR_JOY_MODE::nav_control, request->enable);
|
|
|
-
|
|
|
- // RCLCPP_INFO(rclcpp::get_logger("rclcpp"), "Incoming request-: %d", request->enable);
|
|
|
- return;
|
|
|
-}
|
|
|
-
|
|
|
-void SaturnControllerInterface::HeightScaleCallback(const saturn_msgs::srv::HeightScale::Request::SharedPtr request,
|
|
|
- saturn_msgs::srv::HeightScale::Response::SharedPtr response)
|
|
|
-{
|
|
|
- int scale = request->scale;
|
|
|
- if(scale < 0)
|
|
|
- {
|
|
|
- scale = 0;
|
|
|
- }
|
|
|
- else if(scale > 100)
|
|
|
- {
|
|
|
- scale = 100;
|
|
|
- }
|
|
|
- response->res = rcClientInterfaceBodyHighAdjust(robot_control::common::NAV_OR_JOY_MODE::nav_control, scale);
|
|
|
-
|
|
|
- // RCLCPP_INFO(rclcpp::get_logger("rclcpp"), "Incoming request: %d", request->scale);
|
|
|
- return;
|
|
|
-}
|
|
|
-
|
|
|
-void SaturnControllerInterface::VelocityScaleCallback(const saturn_msgs::srv::VelocityScale::Request::SharedPtr request,
|
|
|
- saturn_msgs::srv::VelocityScale::Response::SharedPtr response)
|
|
|
-{
|
|
|
- int scale = request->scale;
|
|
|
- if(scale < 0)
|
|
|
- {
|
|
|
- scale = 0;
|
|
|
- }
|
|
|
- else if(scale > 100)
|
|
|
- {
|
|
|
- scale = 100;
|
|
|
- }
|
|
|
- response->res = rcClientInterfaceSpeedAdjust(robot_control::common::NAV_OR_JOY_MODE::nav_control, scale);
|
|
|
-
|
|
|
- // RCLCPP_INFO(rclcpp::get_logger("rclcpp"), "Incoming request: %d", request->scale);
|
|
|
- return;
|
|
|
-}
|
|
|
-
|
|
|
-void SaturnControllerInterface::setGaitSceneCallback(const saturn_msgs::srv::GaitScene::Request::SharedPtr request,
|
|
|
- saturn_msgs::srv::GaitScene::Response::SharedPtr response)
|
|
|
-{
|
|
|
- int scene = request->scene;
|
|
|
-
|
|
|
- if((scene > common::SCENE_TYPE::NULL_SCENE) && (scene <= common::SCENE_TYPE::STAIRS))
|
|
|
- {
|
|
|
- response->res = rcClientInterfaceSetScene(robot_control::common::NAV_OR_JOY_MODE::nav_control, (common::SCENE_TYPE)scene);
|
|
|
- }
|
|
|
- // RCLCPP_INFO(rclcpp::get_logger("rclcpp"), "Incoming request: %d", request->scene);
|
|
|
- return;
|
|
|
-}
|
|
|
-
|
|
|
-void SaturnControllerInterface::autoChargeCallback(const saturn_msgs::srv::AutoCharge::Request::SharedPtr request,
|
|
|
- saturn_msgs::srv::AutoCharge::Response::SharedPtr response)
|
|
|
-{
|
|
|
- int auto_charge = request->method;
|
|
|
-
|
|
|
- if((auto_charge > 0) && (auto_charge <= common::AUTO_CHARGE_STATE::charge_finished))
|
|
|
- {
|
|
|
- response->res = rcClientInterfaceSetAutoCharge(robot_control::common::NAV_OR_JOY_MODE::nav_control, (common::AUTO_CHARGE_STATE)auto_charge);
|
|
|
- }
|
|
|
- // RCLCPP_INFO(rclcpp::get_logger("rclcpp"), "Incoming request: %d",request->method);
|
|
|
- return;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-void SaturnControllerInterface::navOrManualControlCallback(const saturn_msgs::srv::NavOrManual::Request::SharedPtr request,
|
|
|
- saturn_msgs::srv::NavOrManual::Response::SharedPtr response)
|
|
|
-{
|
|
|
- int control_mode = request->method;
|
|
|
-
|
|
|
- if((control_mode > 0) && (control_mode <= common::NAV_OR_JOY_MODE::joy_control))
|
|
|
- {
|
|
|
- response->res = rcClientInterfaceSetNavOrJoyControl((common::NAV_OR_JOY_MODE)control_mode);
|
|
|
- }
|
|
|
- // RCLCPP_INFO(rclcpp::get_logger("rclcpp"), "Incoming request: %d", request->method);
|
|
|
- return;
|
|
|
-}
|
|
|
-
|
|
|
-void SaturnControllerInterface::guardianSwitchCallback(const saturn_msgs::srv::GuardianSwitch::Request::SharedPtr request,
|
|
|
- saturn_msgs::srv::GuardianSwitch::Response::SharedPtr response)
|
|
|
-{
|
|
|
- bool enable = request->enable;
|
|
|
-
|
|
|
- response->res = rcClientInterfaceSetGuardianSwitch(robot_control::common::NAV_OR_JOY_MODE::nav_control, enable);
|
|
|
- // RCLCPP_INFO(rclcpp::get_logger("rclcpp"), "guardianSwitchCallback Incoming request: %d", request->enable);
|
|
|
- return;
|
|
|
-}
|
|
|
-
|
|
|
-void SaturnControllerInterface::guardianServiceCallback(const daystar_navigation_msgs::srv::Guardian::Request::SharedPtr request,
|
|
|
- daystar_navigation_msgs::srv::Guardian::Response::SharedPtr response)
|
|
|
-{
|
|
|
- if(request->velocity_decay_ratio <= 0)
|
|
|
- {
|
|
|
- this->guardian_velocity_decay_ratio_ = 0.0;
|
|
|
- //RCLCPP_INFO(rclcpp::get_logger("rclcpp"), "guardian robot stops");
|
|
|
- }
|
|
|
- else if(request->velocity_decay_ratio < 1.0 && request->velocity_decay_ratio > 0)
|
|
|
- {
|
|
|
- this->guardian_velocity_decay_ratio_ = request->velocity_decay_ratio;
|
|
|
- //RCLCPP_INFO(rclcpp::get_logger("rclcpp"), "guardian robot slows down");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- this->guardian_velocity_decay_ratio_ = 1.0;
|
|
|
- //RCLCPP_INFO(rclcpp::get_logger("rclcpp"), "guardian deactivated");
|
|
|
- }
|
|
|
- // bool enable = request->enable;
|
|
|
-
|
|
|
- // response->res = rcClientInterfaceSetGuardianSwitch(robot_control::common::NAV_OR_JOY_MODE::nav_control, enable);
|
|
|
- // // RCLCPP_INFO(rclcpp::get_logger("rclcpp"), "guardianSwitchCallback Incoming request: %d", request->enable);
|
|
|
- return;
|
|
|
-}
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-RCLCPP_COMPONENTS_REGISTER_NODE(saturn_controller_interface::SaturnControllerInterface)
|