ros2 run tf2_ros static_transform_publisher

时间: 2024-12-22 15:12:16 浏览: 92
ROS2(Robot Operating System version 2)是一个开源的机器人操作系统,它提供了一组工具和服务用于创建复杂的机器人系统。`tf2_ros` 是 ROS2 中的一个包,主要用于处理机器人框架下的时空(transform)信息,如坐标系之间的转换。 `static_transform_publisher` 是 `tf2_ros` 包中的一款实用工具节点,它会在指定的时间间隔内持续发布一个静态(不变的)变换,比如将一个固定的坐标系 A 转换到另一个坐标系 B。当你需要在系统中设置一个固定的关系或者作为一个基准来进行其他节点的位置校准时,这个命令非常有用。 命令的基本语法通常是这样的: ```bash ros2 run tf2_ros static_transform_publisher <source_frame> <target_frame> <rotation>(x,y,z,w) [translation(x,y,z)] <duration> <rate> ``` - `<source_frame>`: 源坐标系名称。 - `<target_frame>`: 目标坐标系名称。 - `<rotation>` 和 `<translation>`: 分别是旋转矩阵(四元数形式)和位移向量,定义了从源到目标的变换。 - `<duration>`: 变换的有效时间,单位秒。 - `<rate>`: 发布变换消息的频率,单位赫兹。 运行此命令后,你会在 `/tf` 或 `/tf_static` 的话题上看到发布的静态变换数据。
相关问题

ros2 run tf2_ros static_transform_publisher --x 0 --y 0 --z 1 --yaw 0 --pitch 0 --roll 0 --frame-id world --child-frame-id mystaticturtle

`ros2 run tf2_ros static_transform_publisher`是ROS2中的一个命令行工具,用于发布静态的坐标变换。在这个命令中,我们使用了以下参数来定义坐标变换: --x 0:表示在x轴上的平移量为0 --y 0:表示在y轴上的平移量为0 --z 1:表示在z轴上的平移量为1 --yaw 0:表示绕z轴的旋转角度为0 --pitch 0:表示绕y轴的旋转角度为0 --roll 0:表示绕x轴的旋转角度为0 --frame-id world:表示父坐标系的名称为world --child-frame-id mystaticturtle:表示子坐标系的名称为mystaticturtle 这个命令的作用是将父坐标系world与子坐标系mystaticturtle之间的静态坐标变换发布出去,其他节点可以通过订阅这个坐标变换来获取两个坐标系之间的关系。

解释下面代码的意思from launch.exit_handler import ignore_exit_handler, restart_exit_handler from ros2run.api import get_executable_path def launch(launch_descriptor, argv): ld = launch_descriptor package = 'ydlidar_ros2_driver' ld.add_process( cmd=[get_executable_path(package_name=package, executable_name='ydlidar_ros2_driver_node')], name='ydlidar_ros2_driver_node', exit_handler=restart_exit_handler, ) package = 'tf2_ros' ld.add_process( # The XYZ/Quat numbers for base_link -> laser_frame are taken from the # turtlebot URDF in # https://github.com/turtlebot/turtlebot/blob/931d045/turtlebot_description/urdf/sensors/astra.urdf.xacro cmd=[distance get_executable_path( package_name=package, executable_name='static_transform_publisher'), '0', '0', '0.02', '0', '0', '0', '1', 'base_link', 'laser_frame' ], name='static_tf_pub_laser', exit_handler=restart_exit_handler, ) return ld

这段代码是一个ROS2的launch文件,用于启动两个节点,一个是ydlidar_ros2_driver_node节点,另一个是static_transform_publisher节点。其中,ydlidar_ros2_driver_node节点启动后会使用restart_exit_handler来处理它的退出,这意味着如果该节点因某种原因退出,它将被自动重启。static_transform_publisher节点也是类似的,它会通过restart_exit_handler处理退出并被自动重启。get_executable_path函数用于获取指定包中指定可执行文件的路径,这里用于获取ydlidar_ros2_driver_node和static_transform_publisher的路径。最后,launch函数返回一个launch描述符,用于启动ROS2节点。
阅读全文

相关推荐

def generate_launch_description(): # planning_context moveit_config = ( MoveItConfigsBuilder("moveit_resources_panda") .robot_description(file_path="config/panda.urdf.xacro") .trajectory_execution(file_path="config/gripper_moveit_controllers.yaml") .to_moveit_configs() ) # Load ExecuteTaskSolutionCapability so we can execute found solutions in simulation move_group_capabilities = { "capabilities": "move_group/ExecuteTaskSolutionCapability" } # Start the actual move_group node/action server run_move_group_node = Node( package="moveit_ros_move_group", executable="move_group", output="screen", parameters=[ moveit_config.to_dict(), move_group_capabilities, ], ) # RViz rviz_config_file = ( get_package_share_directory("moveit2_tutorials") + "/launch/mtc.rviz" ) rviz_node = Node( package="rviz2", executable="rviz2", name="rviz2", output="log", arguments=["-d", rviz_config_file], parameters=[ moveit_config.robot_description, moveit_config.robot_description_semantic, ], ) # Static TF static_tf = Node( package="tf2_ros", executable="static_transform_publisher", name="static_transform_publisher", output="log", arguments=["0.0", "0.0", "0.0", "0.0", "0.0", "0.0", "world", "panda_link0"], ) # Publish TF robot_state_publisher = Node( package="robot_state_publisher", executable="robot_state_publisher", name="robot_state_publisher", output="both", parameters=[ moveit_config.robot_description, ], ) # ros2_control using FakeSystem as hardware ros2_controllers_path = os.path.join( get_package_share_directory("moveit_resources_panda_moveit_config"), "config", "ros2_controllers.yaml", ) ros2_control_node = Node( package="controller_manager", executable="ros2_control_node", parameters=[moveit_config.to_dict(), ros2_controllers_path], output="both", ) # Load controllers load_controllers = [] for controller in [ "panda_arm_controller", "panda_hand_controller", "joint_state_broadcaster", ]: load_controllers += [ ExecuteProcess( cmd=["ros2 run controller_manager spawner {}".format(controller)], shell=True, output="screen", ) ] return LaunchDescription( [ rviz_node, static_tf, robot_state_publisher, run_move_group_node, ros2_control_node, ] + load_controllers )这是我的启动文件,有什么问题吗

#!/usr/bin/python3 # Copyright 2020, EAIBOT # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from ament_index_python.packages import get_package_share_directory from launch import LaunchDescription from launch_ros.actions import LifecycleNode from launch_ros.actions import Node from launch.actions import DeclareLaunchArgument from launch.substitutions import LaunchConfiguration from launch.actions import LogInfo import lifecycle_msgs.msg import os def generate_launch_description(): share_dir = get_package_share_directory('ydlidar_ros2_driver') parameter_file = LaunchConfiguration('params_file') node_name = 'ydlidar_ros2_driver_node' params_declare = DeclareLaunchArgument('params_file', default_value=os.path.join( share_dir, 'params', 'ydlidar_x3.yaml'), description='FPath to the ROS2 parameters file to use.') driver_node = LifecycleNode(name='ydlidar_ros2_driver_node',namespace='/') driver_node.node_package='ydlidar_ros2_driver', driver_node.output='screen', driver_node.emulate_tty=True, driver_node.parameters=[parameter_file], driver_node.node_executable='ydlidar_ros2_driver_node', # tf2_node = Node(node_executable='static_transform_publisher') # tf2_node.node_name='static_tf_pub_laser', # tf2_node.node_package='tf2_ros',

#ifndef ARS_RADAR_H_ #define ARS_RADAR_H_ #include <ros/ros.h> #include <string> #include <vector> #include <thread> //#include"gps_msgs/gpsUtm.h" #include <can_msgs/Object.h> #include <can_msgs/ObjectArray.h> #include <can_msgs/FrameArray.h> #include <jsk_recognition_msgs/BoundingBox.h> #include <jsk_recognition_msgs/BoundingBoxArray.h> #include #include #include <sensor_msgs/PointCloud2.h> #include <diagnostic_msgs/DiagnosticStatus.h> #include <cmath> #include <unordered_map> class ArsRadar { public: ArsRadar(); ~ArsRadar(){ pthread_rwlock_destroy(&egoSpeedLock); pthread_rwlock_destroy(&countLock); }; bool init(); void run(); private: void sendMsgToArs(const ros::TimerEvent&); void configArs(const ros::TimerEvent&); void canMsg_callback(const can_msgs::FrameArray::ConstPtr& msg); //void gps_callback(const gps_msgs::gpsUtm::ConstPtr& msg); void parse_msg(const can_msgs::Frame &frame, int index, int n); void pubBoundingBoxArray(); enum Cluster_DynProp { Target_Move = 0, //移动 Target_Static = 1, //静止 Target_Come = 2, //来向 Target_May_Static = 3, //可能静止 Target_Unknow = 4, //未知 Target_Across = 5, //横穿 Target_Across_Static = 6, //横穿静止 Target_Stop = 7 //停止 }; typedef struct _Info { std::string type; uint8_t r; uint8_t g; uint8_t b; _Info(const std::string& t, uint8_t _r, uint8_t _g, uint8_t _b) { type = t; r = _r; g = _g; b = _b; } }Info; std::vector<Info> Infos; private: ros::Subscriber sub_can_; // 订阅can分析仪消息 ros::Subscriber sub_gps_; ros::Publisher pub_can_; // 向can分析仪发布消息 ros::Publisher pub_can_config; // 向can分析仪发布配置消息 ros::Publisher pub_object_; // 发布离我最近的障碍物消息 ros::Publisher pub_objects_; // 发布所有障碍物消息 ros::Publisher pub_cloud_; // 发布点云消息 pcl::PointCloud cloud; pcl::PointXYZRGB point; sensor_msgs::PointCloud2 output; std::string from_can_topic_; std::string to_can_topic_; std::string gpsUtm_topic; can_msgs::ObjectArray ars_objects_; can_msgs::Object ars_object_; can_msgs::Object ars_object_car; bool is_sendMsgToArs_; ros::Timer timer_1, timer_2; std::unordered_map<int, int> MapObjectId2indexInObjectArray; double egoSpeed; // m/s double yawRate; // deg/s pthread_rwlock_t egoSpeedLock, countLock; int readCount; }; #endif 在此代码上推出上面引用的头文件中#include"gps_msgs/gpsUtm.h"的msgs文件

huayu@huayu-Dell-G16-7630:~/active_landing$ roslaunch aruco_localization aruco_detect.launch ... logging to /home/huayu/.ros/log/7ef657a4-0669-11f0-9ee7-1fabd4e25554/roslaunch-huayu-Dell-G16-7630-83628.log Checking log directory for disk usage. This may take a while. Press Ctrl-C to interrupt Done checking log file disk usage. Usage is <1GB. started roslaunch server http://huayu-Dell-G16-7630:40977/ SUMMARY ======== PARAMETERS * /EKF/predicted_time: 1.2 * /aruco/calibration_file: /home/huayu/activ... * /aruco/debug_image_path: /tmp/arucoimages * /aruco/debug_save_input_frames: False * /aruco/debug_save_output_frames: False * /aruco/k_SW2Real: 1.8 * /aruco/markermap_config: /home/huayu/activ... * /aruco/show_output_video: True * /rosdistro: noetic * /rosversion: 1.17.0 NODES / EKF (target_prediction/EKF_prediction.py) aruco (aruco_localization/aruco_localization) tf_baseLink_camera (tf/static_transform_publisher) auto-starting new master process[master]: started with pid [83638] ROS_MASTER_URI=http://localhost:11311 setting /run_id to 7ef657a4-0669-11f0-9ee7-1fabd4e25554 process[rosout-1]: started with pid [83649] started core service [/rosout] process[tf_baseLink_camera-2]: started with pid [83656] ERROR: cannot launch node of type [aruco_localization/aruco_localization]: Cannot locate node of type [aruco_localization] in package [aruco_localization]. Make sure file exists in package path and permission is set to executable (chmod +x) process[EKF-4]: started with pid [83657]

ros2中晃动imu,但是我的机器人模型不跟着晃动,而且里程计一开,里程计跑走,但是imu和机器人模型还在原地,以下是我的各个文件代码,情分析一下为什么:wheeltec_robot.cpp文件代码为: #include "turn_on_wheeltec_robot/wheeltec_robot.h" #include "turn_on_wheeltec_robot/Quaternion_Solution.h" #include "wheeltec_robot_msg/msg/data.hpp" sensor_msgs::msg::Imu Mpu6050;//Instantiate an IMU object //实例化IMU对象 using std::placeholders::_1; using namespace std; rclcpp::Node::SharedPtr node_handle = nullptr; //自动回充使用相关变量 bool check_AutoCharge_data = false; bool charge_set_state = false; /************************************** Date: January 28, 2021 Function: The main function, ROS initialization, creates the Robot_control object through the Turn_on_robot class and automatically calls the constructor initialization 功能: 主函数,ROS初始化,通过turn_on_robot类创建Robot_control对象并自动调用构造函数初始化 ***************************************/ int main(int argc, char** argv) { rclcpp::init(argc, argv); //ROS initializes and sets the node name //ROS初始化 并设置节点名称 turn_on_robot Robot_Control;//Instantiate an object //实例化一个对象 Robot_Control.Control();//Loop through data collection and publish the topic //循环执行数据采集和发布话题等操作 return 0; } /************************************** Date: January 28, 2021 Function: Data conversion function 功能: 数据转换函数 ***************************************/ short turn_on_robot::IMU_Trans(uint8_t Data_High,uint8_t Data_Low) { short transition_16; transition_16 = 0; transition_16 |= Data_High<<8; transition_16 |= Data_Low; return transition_16; } float turn_on_robot::Odom_Trans(uint8_t Data_High,uint8_t Data_Low) { float data_return; short transition_16; transition_16 = 0; transition_16 |= Data_High<<8; //Get the high 8 bits of data //获取数据的高8位 transition_16 |= Data_Low; //Get the lowest 8 bits of data //获取数据的低8位 data_return = (transition_16 / 1000)+(transition_16 % 1000)*0.001; // The speed unit is changed from mm/s to m/s //速度单位从mm/s转换为m/s return data_return; } /************************************** Date: January 28, 2021 Function: The speed topic subscription Callback function, according to the subscribed instructions through the serial port command control of the lower computer 功能: 速度话题订阅回调函数Callback,根据订阅的指令通过串口发指令控制下位机 ***************************************/ void turn_on_robot::Cmd_Vel_Callback(const geometry_msgs::msg::Twist::SharedPtr twist_aux) { short transition; //intermediate variable //中间变量 Send_Data.tx[0]= 0x06; //frame head 0x7B //帧头0X7B //Send_Data.tx[1] = AutoRecharge; //set aside //预留位 Send_Data.tx[1] = FRAME_HEADER; Send_Data.tx[2] = 0; //set aside //预留位 //The target velocity of the X-axis of the robot //机器人x轴的目标线速度 transition=0; transition = twist_aux->linear.x*1000; //将浮点数放大一千倍,简化传输 (mm/s) Send_Data.tx[4] = transition; //取数据的低8位 Send_Data.tx[3] = transition>>8; //取数据的高8位 //The target velocity of the Y-axis of the robot //机器人y轴的目标线速度 transition=0; transition = twist_aux->linear.y*1000; Send_Data.tx[6] = transition; Send_Data.tx[5] = transition>>8; //The target angular velocity of the robot's Z axis //机器人z轴的目标角速度 transition=0; transition = twist_aux->angular.z*1000; //(1000*rad/s) Send_Data.tx[8] = transition; Send_Data.tx[7] = transition>>8; Send_Data.tx[9]=Check_Sum(9,SEND_DATA_CHECK); //For the BCC check bits, see the Check_Sum function //BCC校验位,规则参见Check_Sum函数 Send_Data.tx[10]=0x0d; //frame tail 0x7D //帧尾0X7D Send_Data.tx[11]=0x0a; try { Stm32_Serial.write(Send_Data.tx,sizeof (Send_Data.tx)); //Sends data to the downloader via serial port //通过串口向下位机发送数据 } catch (serial::IOException& e) { RCLCPP_ERROR(this->get_logger(),("Unable to send data through serial port")); //If sending data fails, an error message is printed //如果发送数据失败,打印错误信息 } } /************************************** Date: January 28, 2021 Function: Publish the IMU data topic 功能: 发布IMU数据话题 ***************************************/ void turn_on_robot::Publish_ImuSensor() { sensor_msgs::msg::Imu Imu_Data_Pub; //Instantiate IMU topic data //实例化IMU话题数据 Imu_Data_Pub.header.stamp = rclcpp::Node::now(); Imu_Data_Pub.header.frame_id = gyro_frame_id; //IMU corresponds to TF coordinates, which is required to use the robot_pose_ekf feature pack //IMU对应TF坐标,使用robot_pose_ekf功能包需要设置此项 Imu_Data_Pub.orientation.x = Mpu6050.orientation.x; //A quaternion represents a three-axis attitude //四元数表达三轴姿态 Imu_Data_Pub.orientation.y = Mpu6050.orientation.y; Imu_Data_Pub.orientation.z = Mpu6050.orientation.z; Imu_Data_Pub.orientation.w = Mpu6050.orientation.w; Imu_Data_Pub.orientation_covariance[0] = 1e6; //Three-axis attitude covariance matrix //三轴姿态协方差矩阵 Imu_Data_Pub.orientation_covariance[4] = 1e6; Imu_Data_Pub.orientation_covariance[8] = 1e-6; Imu_Data_Pub.angular_velocity.x = Mpu6050.angular_velocity.x; //Triaxial angular velocity //三轴角速度 Imu_Data_Pub.angular_velocity.y = Mpu6050.angular_velocity.y; Imu_Data_Pub.angular_velocity.z = Mpu6050.angular_velocity.z; Imu_Data_Pub.angular_velocity_covariance[0] = 1e6; //Triaxial angular velocity covariance matrix //三轴角速度协方差矩阵 Imu_Data_Pub.angular_velocity_covariance[4] = 1e6; Imu_Data_Pub.angular_velocity_covariance[8] = 1e-6; Imu_Data_Pub.linear_acceleration.x = Mpu6050.linear_acceleration.x; //Triaxial acceleration //三轴线性加速度 Imu_Data_Pub.linear_acceleration.y = Mpu6050.linear_acceleration.y; Imu_Data_Pub.linear_acceleration.z = Mpu6050.linear_acceleration.z; imu_publisher->publish(Imu_Data_Pub); //Pub IMU topic //发布IMU话题 } /************************************** Date: January 28, 2021 Function: Publish the odometer topic, Contains position, attitude, triaxial velocity, angular velocity about triaxial, TF parent-child coordinates, and covariance matrix 功能: 发布里程计话题,包含位置、姿态、三轴速度、绕三轴角速度、TF父子坐标、协方差矩阵 ***************************************/ void turn_on_robot::Publish_Odom() { //Convert the Z-axis rotation Angle into a quaternion for expression //把Z轴转角转换为四元数进行表达 tf2::Quaternion q; q.setRPY(0,0,Mpu6050_Data.imu_yaw); geometry_msgs::msg::Quaternion odom_quat=tf2::toMsg(q); nav_msgs::msg::Odometry odom; //Instance the odometer topic data //实例化里程计话题数据 odom.header.stamp = rclcpp::Node::now(); ; odom.header.frame_id = odom_frame_id; // Odometer TF parent coordinates //里程计TF父坐标 odom.pose.pose.position.x = Robot_Pos.X; //Position //位置 odom.pose.pose.position.y = Robot_Pos.Y; //odom.pose.pose.position.z = Robot_Pos.Z; odom.pose.pose.orientation = odom_quat; //Posture, Quaternion converted by Z-axis rotation //姿态,通过Z轴转角转换的四元数 odom.child_frame_id = robot_frame_id; // Odometer TF subcoordinates //里程计TF子坐标 odom.twist.twist.linear.x = Robot_Vel.X; //Speed in the X direction //X方向速度 //odom.twist.twist.linear.y = Robot_Vel.Y; //Speed in the Y direction //Y方向速度 odom.twist.twist.angular.z = Mpu6050.angular_velocity.z; //Angular velocity around the Z axis //绕Z轴角速度 //There are two types of this matrix, which are used when the robot is at rest and when it is moving.Extended Kalman Filtering officially provides 2 matrices for the robot_pose_ekf feature pack //这个矩阵有两种,分别在机器人静止和运动的时候使用。扩展卡尔曼滤波官方提供的2个矩阵,用于robot_pose_ekf功能包 //if(Robot_Vel.X== 0&&Robot_Vel.Y== 0&&Robot_Vel.Z== 0) if(Robot_Vel.X== 0) //If the velocity is zero, it means that the error of the encoder will be relatively small, and the data of the encoder will be considered more reliable //如果velocity是零,说明编码器的误差会比较小,认为编码器数据更可靠 memcpy(&odom.pose.covariance, odom_pose_covariance2, sizeof(odom_pose_covariance2)), memcpy(&odom.twist.covariance, odom_twist_covariance2, sizeof(odom_twist_covariance2)); else //If the velocity of the trolley is non-zero, considering the sliding error that may be brought by the encoder in motion, the data of IMU is considered to be more reliable //如果小车velocity非零,考虑到运动中编码器可能带来的滑动误差,认为imu的数据更可靠 memcpy(&odom.pose.covariance, odom_pose_covariance, sizeof(odom_pose_covariance)), memcpy(&odom.twist.covariance, odom_twist_covariance, sizeof(odom_twist_covariance)); odom_publisher->publish(odom); //Pub odometer topic //发布里程计话题 } /************************************** Date: January 28, 2021 Function: Publish voltage-related information 功能: 发布电压相关信息 ***************************************/ void turn_on_robot::Publish_Voltage() { std_msgs::msg::Float32 voltage_msgs; //Define the data type of the power supply voltage publishing topic //定义电源电压发布话题的数据类型 static float Count_Voltage_Pub=0; if(Count_Voltage_Pub++>10) { Count_Voltage_Pub=0; voltage_msgs.data = Power_voltage; //The power supply voltage is obtained //电源供电的电压获取 voltage_publisher->publish(voltage_msgs); //Post the power supply voltage topic unit: V, volt //发布电源电压话题单位:V、伏特 } } ////////// 回充发布与回调 //////// /************************************** Date: January 17, 2022 Function: Pub the topic whether the robot finds the infrared signal (charging station) 功能: 发布机器人是否寻找到红外信号(充电桩)的话题 ***************************************/ void turn_on_robot::Publish_RED() { std_msgs::msg::UInt8 msg; msg.data=Red; RED_publisher->publish(msg); } /************************************** Date: January 14, 2022 Function: Publish a topic about whether the robot is charging 功能: 发布机器人是否在充电的话题 ***************************************/ void turn_on_robot::Publish_Charging() { static bool last_charging; std_msgs::msg::Bool msg; msg.data=Charging; Charging_publisher->publish(msg); if(last_charging==false && Charging==true)cout<<GREEN<<"Robot is charging."<<endl<<RESET; if(last_charging==true && Charging==false)cout<<RED <<"Robot charging has disconnected."<<endl<<RESET; last_charging=Charging; } /************************************** Date: January 28, 2021 Function: Publish charging current information 功能: 发布充电电流信息 ***************************************/ void turn_on_robot::Publish_ChargingCurrent() { std_msgs::msg::Float32 msg; msg.data=Charging_Current; Charging_current_publisher->publish(msg); } /************************************** Date: March 1, 2022 Function: Infrared connection speed topic subscription Callback function, according to the subscription command through the serial port to set the infrared connection speed 功能: 红外对接速度话题订阅回调函数Callback,根据订阅的指令通过串口发指令设置红外对接速度 ***************************************/ void turn_on_robot::Red_Vel_Callback(const geometry_msgs::msg::Twist::SharedPtr twist_aux) { short transition; //intermediate variable //中间变量 Send_Data.tx[0]=FRAME_HEADER; //frame head 0x7B //帧头0X7B Send_Data.tx[1] = 3; //Infrared docking speed setting flag bit = 3 //红外对接速度设置标志位=3 Send_Data.tx[2] = 0; //set aside //预留位 //The target velocity of the X-axis of the robot //机器人x轴的目标线速度 transition=0; transition = twist_aux->linear.x*1000; //将浮点数放大一千倍,简化传输 Send_Data.tx[4] = transition; //取数据的低8位 Send_Data.tx[3] = transition>>8; //取数据的高8位 //The target velocity of the Y-axis of the robot //机器人y轴的目标线速度 transition=0; transition = twist_aux->linear.y*1000; Send_Data.tx[6] = transition; Send_Data.tx[5] = transition>>8; //The target angular velocity of the robot's Z axis //机器人z轴的目标角速度 transition=0; transition = twist_aux->angular.z*1000; Send_Data.tx[8] = transition; Send_Data.tx[7] = transition>>8; Send_Data.tx[9]=Check_Sum(9,SEND_DATA_CHECK); //BCC check //BCC校验 Send_Data.tx[10]=FRAME_TAIL; //frame tail 0x7D //帧尾0X7D try { Stm32_Serial.write(Send_Data.tx,sizeof (Send_Data.tx)); //Sends data to the downloader via serial port //通过串口向下位机发送数据 } catch (serial::IOException& e) { RCLCPP_ERROR(this->get_logger(),("Unable to send data through serial port")); //If sending data fails, an error message is printed //如果发送数据失败,打印错误信息 } } /************************************** Date: January 14, 2022 Function: Subscription robot recharge flag bit topic, used to tell the lower machine speed command is normal command or recharge command 功能: 订阅机器人是否回充标志位话题,用于告诉下位机速度命令是正常命令还是回充命令 ***************************************/ void turn_on_robot::Recharge_Flag_Callback(const std_msgs::msg::Int8::SharedPtr Recharge_Flag) { AutoRecharge=Recharge_Flag->data; } //服务 void turn_on_robot::Set_Charge_Callback(const shared_ptr<turtlesim::srv::Spawn::Request> req,shared_ptr<turtlesim::srv::Spawn::Response> res) { Send_Data.tx[0]=FRAME_HEADER; //frame head 0x7B //֡ͷ0X7B if(round(req->x)==1) Send_Data.tx[1] = 1; else if(round(req->x)==2) Send_Data.tx[1] = 2; else if(round(req->x)==0) Send_Data.tx[1] = 0,AutoRecharge=0; Send_Data.tx[2] = 0; Send_Data.tx[3] = 0; Send_Data.tx[4] = 0; Send_Data.tx[5] = 0; Send_Data.tx[6] = 0; Send_Data.tx[7] = 0; Send_Data.tx[8] = 0; Send_Data.tx[9]=Check_Sum(9,SEND_DATA_CHECK); //For the BCC check bits, see the Check_Sum function //BCCУ��λ������μ�Check_Sum���� Send_Data.tx[10]=FRAME_TAIL; //frame tail 0x7D //֡β0X7D try { Stm32_Serial.write(Send_Data.tx,sizeof (Send_Data.tx)); //Sends data to the downloader via serial port //ͨ����������λ���������� } catch (serial::IOException& e) { res->name = "false"; } if( Send_Data.tx[1]==0 ) { if(charge_set_state==0) AutoRecharge=0,res->name = "true"; else res->name = "false"; } else { if(charge_set_state==1) res->name = "true"; else res->name = "false"; } return; } ////////// 回充发布与回调 //////// /************************************** Date: January 28, 2021 Function: Serial port communication check function, packet n has a byte, the NTH -1 byte is the check bit, the NTH byte bit frame end.Bit XOR results from byte 1 to byte n-2 are compared with byte n-1, which is a BCC check Input parameter: Count_Number: Check the first few bytes of the packet 功能: 串口通讯校验函数,数据包n有个字节,第n-1个字节为校验位,第n个字节位帧尾。第1个字节到第n-2个字节数据按位异或的结果与第n-1个字节对比,即为BCC校验 输入参数: Count_Number:数据包前几个字节加入校验 mode:对发送数据还是接收数据进行校验 ***************************************/ unsigned char turn_on_robot::Check_Sum(unsigned char Count_Number,unsigned char mode) { unsigned char check_sum=0,k; if(mode==0) //Receive data mode //接收数据模式 { for(k=0;k<Count_Number;k++) { check_sum=check_sum^Receive_Data.rx[k]; //By bit or by bit //按位异或 } } if(mode==1) //Send data mode //发送数据模式 { for(k=1;k<Count_Number;k++) { check_sum=check_sum^Send_Data.tx[k]; //By bit or by bit //按位异或 } } return check_sum; //Returns the bitwise XOR result //返回按位异或结果 } //自动回充专用校验位 unsigned char turn_on_robot::Check_Sum_AutoCharge(unsigned char Count_Number,unsigned char mode) { unsigned char check_sum=0,k; if(mode==0) //Receive data mode //接收数据模式 { for(k=0;k<Count_Number;k++) { check_sum=check_sum^Receive_AutoCharge_Data.rx[k]; //By bit or by bit //按位异或 } } return check_sum; } /************************************** Date: November 18, 2021 Function: Read and verify the data sent by the lower computer frame by frame through the serial port, and then convert the data into international units 功能: 通过串口读取并逐帧校验下位机发送过来的数据,然后数据转换为国际单位 ***************************************/ bool turn_on_robot::Get_Sensor_Data_New() { short transition_16=0; //Intermediate variable //中间变量 //uint8_t i=0; uint8_t check=0,check2=0, error=1,error2=1,Receive_Data_Pr[1]; //Temporary variable to save the data of the lower machine //临时变量,保存下位机数据 static int count,count2; //Static variable for counting //静态变量,用于计数 Stm32_Serial.read(Receive_Data_Pr,sizeof(Receive_Data_Pr)); //Read the data sent by the lower computer through the serial port //通过串口读取下位机发送过来的数据 /*//View the received raw data directly and debug it for use//直接查看接收到的原始数据,调试使用 ROS_INFO("%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x", Receive_Data_Pr[0],Receive_Data_Pr[1],Receive_Data_Pr[2],Receive_Data_Pr[3],Receive_Data_Pr[4],Receive_Data_Pr[5],Receive_Data_Pr[6],Receive_Data_Pr[7], Receive_Data_Pr[8],Receive_Data_Pr[9],Receive_Data_Pr[10],Receive_Data_Pr[11],Receive_Data_Pr[12],Receive_Data_Pr[13],Receive_Data_Pr[14],Receive_Data_Pr[15], Receive_Data_Pr[16],Receive_Data_Pr[17],Receive_Data_Pr[18],Receive_Data_Pr[19],Receive_Data_Pr[20],Receive_Data_Pr[21],Receive_Data_Pr[22],Receive_Data_Pr[23]); */ Receive_Data.rx[count] = Receive_Data_Pr[0]; //Fill the array with serial data //串口数据填入数组 Receive_AutoCharge_Data.rx[count2] = Receive_Data_Pr[0]; Receive_Data.Frame_Header = Receive_Data.rx[0]; //The first part of the data is the frame header 0X7B //数据的第一位是帧头0X7B Receive_Data.Frame_Tail = Receive_Data.rx[23]; //The last bit of data is frame tail 0X7D //数据的最后一位是帧尾0X7D //接收到自动回充数据的帧头、上一个数据是24字节的帧尾,表明自动回充数据开始到来 if((Receive_Data_Pr[0] == AutoCharge_HEADER )||count2>0) count2++; else count2=0; if(Receive_Data_Pr[0] == FRAME_HEADER || count>0) //Ensure that the first data in the array is FRAME_HEADER //确保数组第一个数据为FRAME_HEADER count++; else count=0; //自动回充数据处理 if(count2 == AutoCharge_DATA_SIZE) { count2=0; if(Receive_AutoCharge_Data.rx[AutoCharge_DATA_SIZE-1]==AutoCharge_TAIL) //确认帧尾 { check2 = Check_Sum_AutoCharge(6,0);//校验位计算 if(check2 == Receive_AutoCharge_Data.rx[AutoCharge_DATA_SIZE-2]) //校验正确 { error2=0; } if(error2 == 0) //校验正确开始赋值 { transition_16 = 0; transition_16 |= Receive_AutoCharge_Data.rx[1]<<8; transition_16 |= Receive_AutoCharge_Data.rx[2]; Charging_Current = transition_16/1000+(transition_16 % 1000)*0.001; //充电电流 Red = Receive_AutoCharge_Data.rx[3]; //红外接受状态 Charging = Receive_AutoCharge_Data.rx[4];//小车充电状态 charge_set_state = Receive_AutoCharge_Data.rx[5]; check_AutoCharge_data = true; //数据成功接收标志位 } } } if(count == 24) //Verify the length of the packet //验证数据包的长度 { count=0; //Prepare for the serial port data to be refill into the array //为串口数据重新填入数组做准备 if(Receive_Data.Frame_Tail == FRAME_TAIL) //Verify the frame tail of the packet //验证数据包的帧尾 { check=Check_Sum(22,READ_DATA_CHECK); //BCC check passes or two packets are interlaced //BCC校验通过或者两组数据包交错 if(check == Receive_Data.rx[22]) { error=0; //XOR bit check successful //异或位校验成功 } if(error == 0) { /*//Check receive_data.rx for debugging use //查看Receive_Data.rx,调试使用 ROS_INFO("%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x", Receive_Data.rx[0],Receive_Data.rx[1],Receive_Data.rx[2],Receive_Data.rx[3],Receive_Data.rx[4],Receive_Data.rx[5],Receive_Data.rx[6],Receive_Data.rx[7], Receive_Data.rx[8],Receive_Data.rx[9],Receive_Data.rx[10],Receive_Data.rx[11],Receive_Data.rx[12],Receive_Data.rx[13],Receive_Data.rx[14],Receive_Data.rx[15], Receive_Data.rx[16],Receive_Data.rx[17],Receive_Data.rx[18],Receive_Data.rx[19],Receive_Data.rx[20],Receive_Data.rx[21],Receive_Data.rx[22],Receive_Data.rx[23]); */ Receive_Data.Flag_Stop=Receive_Data.rx[1]; //set aside //预留位 Robot_Vel.X = Odom_Trans(Receive_Data.rx[2],Receive_Data.rx[3]); //Get the speed of the moving chassis in the X direction //获取运动底盘X方向速度 //Robot_Vel.Y = Odom_Trans(Receive_Data.rx[4],Receive_Data.rx[5]); //Get the speed of the moving chassis in the Y direction, The Y speed is only valid in the omnidirectional mobile robot chassis //获取运动底盘Y方向速度,Y速度仅在全向移动机器人底盘有效 //Robot_Vel.Z = Odom_Trans(Receive_Data.rx[6],Receive_Data.rx[7]); //Get the speed of the moving chassis in the Z direction //获取运动底盘Z方向速度 //MPU6050 stands for IMU only and does not refer to a specific model. It can be either MPU6050 or MPU9250 //Mpu6050仅代表IMU,不指代特定型号,既可以是MPU6050也可以是MPU9250 Mpu6050_Data.imu_rol = IMU_Trans(Receive_Data.rx[4],Receive_Data.rx[5]) * 0.01 * 3.14159/180; Mpu6050_Data.imu_yaw = IMU_Trans(Receive_Data.rx[6],Receive_Data.rx[7]) * 0.01 * 3.14159/180; Mpu6050_Data.accele_x_data = IMU_Trans(Receive_Data.rx[8],Receive_Data.rx[9]); //Get the X-axis acceleration of the IMU //获取IMU的X轴加速度 Mpu6050_Data.accele_y_data = IMU_Trans(Receive_Data.rx[10],Receive_Data.rx[11]); //Get the Y-axis acceleration of the IMU //获取IMU的Y轴加速度 Mpu6050_Data.accele_z_data = IMU_Trans(Receive_Data.rx[12],Receive_Data.rx[13]); //Get the Z-axis acceleration of the IMU //获取IMU的Z轴加速度 Mpu6050_Data.gyros_x_data = IMU_Trans(Receive_Data.rx[14],Receive_Data.rx[15]); //Get the X-axis angular velocity of the IMU //获取IMU的X轴角速度 Mpu6050_Data.gyros_y_data = IMU_Trans(Receive_Data.rx[16],Receive_Data.rx[17]); //Get the Y-axis angular velocity of the IMU //获取IMU的Y轴角速度 Mpu6050_Data.gyros_z_data = IMU_Trans(Receive_Data.rx[18],Receive_Data.rx[19]); //Get the Z-axis angular velocity of the IMU //获取IMU的Z轴角速度 //Linear acceleration unit conversion is related to the range of IMU initialization of STM32, where the range is ±2g=19.6m/s^2 //线性加速度单位转化,和STM32的IMU初始化的时候的量程有关,这里量程±2g=19.6m/s^2 Mpu6050.linear_acceleration.x = Mpu6050_Data.accele_x_data * 0.01 * 9.8; Mpu6050.linear_acceleration.y = Mpu6050_Data.accele_y_data * 0.01 * 9.8; Mpu6050.linear_acceleration.z = Mpu6050_Data.accele_z_data * 0.01 * 9.8; //The gyroscope unit conversion is related to the range of STM32's IMU when initialized. Here, the range of IMU's gyroscope is ±500°/s //Because the robot generally has a slow Z-axis speed, reducing the range can improve the accuracy //陀螺仪单位转化,和STM32的IMU初始化的时候的量程有关,这里IMU的陀螺仪的量程是±500°/s //因为机器人一般Z轴速度不快,降低量程可以提高精度 Mpu6050.angular_velocity.x = Mpu6050_Data.gyros_x_data * 0.01 *3.14159/180; Mpu6050.angular_velocity.y = Mpu6050_Data.gyros_y_data * 0.01 *3.14159/180; Mpu6050.angular_velocity.z = Mpu6050_Data.gyros_z_data * 0.01 *3.14159/180; //Get the battery voltage //获取电池电压 transition_16 = 0; transition_16 |= Receive_Data.rx[20]<<8; transition_16 |= Receive_Data.rx[21]; Power_voltage = transition_16/1000+(transition_16 % 1000)*0.001; //Unit conversion millivolt(mv)->volt(v) //单位转换毫伏(mv)->伏(v) return true; } } } return false; } /************************************** Date: January 28, 2021 Function: Loop access to the lower computer data and issue topics 功能: 循环获取下位机数据与发布话题 ***************************************/ void turn_on_robot::Control() { //_Last_Time = ros::Time::now(); _Last_Time = rclcpp::Node::now(); while(rclcpp::ok()) { try { //_Now = ros::Time::now(); _Now = rclcpp::Node::now(); Sampling_Time = (_Now - _Last_Time).seconds(); //Retrieves time interval, which is used to integrate velocity to obtain displacement (mileage) //获取时间间隔,用于积分速度获得位移(里程) if (true == Get_Sensor_Data_New()) //The serial port reads and verifies the data sent by the lower computer, and then the data is converted to international units //通过串口读取并校验下位机发送过来的数据,然后数据转换为国际单位 { //Robot_Pos.X+=(Robot_Vel.X * cos(Robot_Pos.Z) - Robot_Vel.Y * sin(Robot_Pos.Z)) * Sampling_Time; //Calculate the displacement in the X direction, unit: m //计算X方向的位移,单位:m //Robot_Pos.Y+=(Robot_Vel.X * sin(Robot_Pos.Z) + Robot_Vel.Y * cos(Robot_Pos.Z)) * Sampling_Time; //Calculate the displacement in the Y direction, unit: m //计算Y方向的位移,单位:m //Robot_Pos.Z+=Robot_Vel.Z * Sampling_Time; //The angular displacement about the Z axis, in rad //绕Z轴的角位移,单位:rad Robot_Pos.X+=(Robot_Vel.X * cos(Mpu6050_Data.imu_yaw)) * Sampling_Time; //Calculate the displacement in the X direction, unit: m //计算X方向的位移,单位:m Robot_Pos.Y+=(Robot_Vel.X * sin(Mpu6050_Data.imu_yaw)) * Sampling_Time; //Calculate the displacement in the Y direction, unit: m //计算Y方向的位移,单位:m //Robot_Pos.Z = 0 ; //Calculate the three-axis attitude from the IMU with the angular velocity around the three-axis and the three-axis acceleration //通过IMU绕三轴角速度与三轴加速度计算三轴姿态 Quaternion_Solution(Mpu6050.angular_velocity.x, Mpu6050.angular_velocity.y, Mpu6050.angular_velocity.z,\ Mpu6050.linear_acceleration.x, Mpu6050.linear_acceleration.y, Mpu6050.linear_acceleration.z); Publish_Odom(); //Pub the speedometer topic //发布里程计话题 Publish_ImuSensor(); //Pub the IMU topic //发布IMU话题 Publish_Voltage(); //Pub the topic of power supply voltage //发布电源电压话题 _Last_Time = _Now; //Record the time and use it to calculate the time interval //记录时间,用于计算时间间隔 } //自动回充数据话题 if(check_AutoCharge_data) { Publish_Charging(); //Pub a topic about whether the robot is charging //发布机器人是否在充电的话题 Publish_RED(); //Pub the topic whether the robot finds the infrared signal (charging station) //发布机器人是否寻找到红外信号(充电桩)的话题 Publish_ChargingCurrent(); //Pub the charging current topic //发布充电电流话题 check_AutoCharge_data = false; } rclcpp::spin_some(this->get_node_base_interface()); //The loop waits for the callback function //循环等待回调函数 } catch (const rclcpp::exceptions::RCLError & e ) { RCLCPP_ERROR(this->get_logger(),"unexpectedly failed whith %s",e.what()); } } } /************************************** Date: January 28, 2021 Function: Constructor, executed only once, for initialization 功能: 构造函数, 只执行一次,用于初始化 ***************************************/ turn_on_robot::turn_on_robot():rclcpp::Node ("wheeltec_robot") { Sampling_Time=0; Power_voltage=0; //Clear the data //清空数据 memset(&Robot_Pos, 0, sizeof(Robot_Pos)); memset(&Robot_Vel, 0, sizeof(Robot_Vel)); memset(&Receive_Data, 0, sizeof(Receive_Data)); memset(&Send_Data, 0, sizeof(Send_Data)); memset(&Mpu6050_Data, 0, sizeof(Mpu6050_Data)); //ros::NodeHandle private_nh("~"); //Create a node handle //创建节点句柄 //The private_nh.param() entry parameter corresponds to the initial value of the name of the parameter variable on the parameter server //private_nh.param()入口参数分别对应:参数服务器上的名称 参数变量名 初始值 this->declare_parameter<int>("serial_baud_rate",115200); this->declare_parameter<std::string>("usart_port_name", "/dev/ttyACM0"); this->declare_parameter<std::string>("odom_frame_id", "odom_combined"); this->declare_parameter<std::string>("robot_frame_id", "base_footprint"); this->declare_parameter<std::string>("gyro_frame_id", "gyro_link"); this->get_parameter("serial_baud_rate", serial_baud_rate);//Communicate baud rate 115200 to the lower machine //和下位机通信波特率115200 this->get_parameter("usart_port_name", usart_port_name);//Fixed serial port number //固定串口号 this->get_parameter("odom_frame_id", odom_frame_id);//The odometer topic corresponds to the parent TF coordinate //里程计话题对应父TF坐标 this->get_parameter("robot_frame_id", robot_frame_id);//The odometer topic corresponds to sub-TF coordinates //里程计话题对应子TF坐标 this->get_parameter("gyro_frame_id", gyro_frame_id);//IMU topics correspond to TF coordinates //IMU话题对应TF坐标 odom_publisher = create_publisher("odom", 2);//Create the odometer topic publisher //创建里程计话题发布者 imu_publisher = create_publisher<sensor_msgs::msg::Imu>("imu/data_raw", 2); //Create an IMU topic publisher //创建IMU话题发布者 voltage_publisher = create_publisher<std_msgs::msg::Float32>("PowerVoltage", 1);//Create a battery-voltage topic publisher //创建电池电压话题发布者 //回充发布者 Charging_publisher = create_publisher<std_msgs::msg::Bool>("robot_charging_flag", 10); Charging_current_publisher = create_publisher<std_msgs::msg::Float32>("robot_charging_current", 10); RED_publisher = create_publisher<std_msgs::msg::UInt8>("robot_red_flag", 10); //回充订阅者 Red_Vel_Sub = create_subscription<geometry_msgs::msg::Twist>( "red_vel", 10, std::bind(&turn_on_robot::Red_Vel_Callback, this, std::placeholders::_1)); Recharge_Flag_Sub = create_subscription<std_msgs::msg::Int8>( "robot_recharge_flag", 10, std::bind(&turn_on_robot::Recharge_Flag_Callback, this,std::placeholders::_1)); //回充服务提供 SetCharge_Service=this->create_service<turtlesim::srv::Spawn>\ ("/set_charge",std::bind(&turn_on_robot::Set_Charge_Callback,this, std::placeholders::_1 ,std::placeholders::_2)); //Set the velocity control command callback function //速度控制命令订阅回调函数设置 Cmd_Vel_Sub = create_subscription<geometry_msgs::msg::Twist>( "cmd_vel", 2, std::bind(&turn_on_robot::Cmd_Vel_Callback, this, _1)); RCLCPP_INFO(this->get_logger(),"wheeltec_robot Data ready"); //Prompt message //提示信息 try { //Attempts to initialize and open the serial port //尝试初始化与开启串口 Stm32_Serial.setPort(usart_port_name); //Select the serial port number to enable //选择要开启的串口号 Stm32_Serial.setBaudrate(serial_baud_rate); //Set the baud rate //设置波特率 serial::Timeout _time = serial::Timeout::simpleTimeout(2000); //Timeout //超时等待 Stm32_Serial.setTimeout(_time); Stm32_Serial.open(); //Open the serial port //开启串口 } catch (serial::IOException& e) { RCLCPP_ERROR(this->get_logger(),"wheeltec_robot can not open serial port,Please check the serial port cable! "); //If opening the serial port fails, an error message is printed //如果开启串口失败,打印错误信息 } if(Stm32_Serial.isOpen()) { RCLCPP_INFO(this->get_logger(),"wheeltec_robot serial port opened"); //Serial port opened successfully //串口开启成功提示 } } /************************************** Date: January 28, 2021 Function: Destructor, executed only once and called by the system when an object ends its life cycle 功能: 析构函数,只执行一次,当对象结束其生命周期时系统会调用这个函数 ***************************************/ turn_on_robot::~turn_on_robot() { //Sends the stop motion command to the lower machine before the turn_on_robot object ends //对象turn_on_robot结束前向下位机发送停止运动命令 Send_Data.tx[0]=0x06; Send_Data.tx[1] = FRAME_HEADER; Send_Data.tx[2] = 0; //The target velocity of the X-axis of the robot //机器人X轴的目标线速度 Send_Data.tx[4] = 0; Send_Data.tx[3] = 0; //The target velocity of the Y-axis of the robot //机器人Y轴的目标线速度 Send_Data.tx[6] = 0; Send_Data.tx[5] = 0; //The target velocity of the Z-axis of the robot //机器人Z轴的目标角速度 Send_Data.tx[8] = 0; Send_Data.tx[7] = 0; Send_Data.tx[9]=Check_Sum(9,SEND_DATA_CHECK); //Check the bits for the Check_Sum function //校验位,规则参见Check_Sum函数 Send_Data.tx[10]=0x0d; Send_Data.tx[11]=0x0a; try { Stm32_Serial.write(Send_Data.tx,sizeof (Send_Data.tx)); //Send data to the serial port //向串口发数据 } catch (serial::IOException& e) { RCLCPP_ERROR(this->get_logger(),"Unable to send data through serial port"); //If sending data fails, an error message is printed //如果发送数据失败,打印错误信息 } Stm32_Serial.close(); //Close the serial port //关闭串口 RCLCPP_INFO(this->get_logger(),"Shutting down"); //Prompt message //提示信息 } turn_on_wheeltec_robot.launch.py文件代码为: import os from pathlib import Path import launch from launch.actions import SetEnvironmentVariable from ament_index_python.packages import get_package_share_directory from launch import LaunchDescription from launch.actions import (DeclareLaunchArgument, GroupAction, IncludeLaunchDescription, SetEnvironmentVariable) from launch.launch_description_sources import PythonLaunchDescriptionSource from launch.substitutions import LaunchConfiguration, PythonExpression from launch_ros.actions import PushRosNamespace import launch_ros.actions from launch.conditions import IfCondition from launch.conditions import UnlessCondition def generate_launch_description(): # Get the launch directory bringup_dir = get_package_share_directory('turn_on_wheeltec_robot') launch_dir = os.path.join(bringup_dir, 'launch') ekf_config = Path(get_package_share_directory('turn_on_wheeltec_robot'), 'config', 'ekf.yaml') ekf_carto_config = Path(get_package_share_directory('turn_on_wheeltec_robot'), 'config', 'ekf_carto.yaml') imu_config = Path(get_package_share_directory('turn_on_wheeltec_robot'), 'config', 'imu.yaml') carto_slam = LaunchConfiguration('carto_slam', default='false') carto_slam_dec = DeclareLaunchArgument('carto_slam',default_value='false') wheeltec_robot = IncludeLaunchDescription( PythonLaunchDescriptionSource(os.path.join(launch_dir, 'base_serial.launch.py')), ) robot_ekf = IncludeLaunchDescription( PythonLaunchDescriptionSource(os.path.join(launch_dir, 'wheeltec_ekf.launch.py')), launch_arguments={'carto_slam':carto_slam}.items(), ) base_to_link = launch_ros.actions.Node( package='tf2_ros', executable='static_transform_publisher', name='base_to_link', arguments=['0', '0', '0','0', '0','0','base_footprint','base_link'], ) base_to_gyro = launch_ros.actions.Node( package='tf2_ros', executable='static_transform_publisher', name='base_to_gyro', arguments=['0', '0', '0','0', '0','0','base_link','gyro_link'], ) imu_filter_node = launch_ros.actions.Node( package='imu_filter_madgwick', executable='imu_filter_madgwick_node', parameters=[imu_config] ) # joint_state_publisher_node = launch_ros.actions.Node( # package='joint_state_publisher', # executable='joint_state_publisher', # name='joint_state_publisher', # ) #select a robot model,the default model is mini_mec #minibot.launch.py contains commonly used robot models #launch_arguments choices:mini_mec/mini_akm/mini_tank/mini_4wd/mini_diff/mini_omni/brushless_senior_diff #!!!At the same time, you need to modify ld.add_action(minibot_type) and #ld.add_action(flagship_type) minibot_type = IncludeLaunchDescription( PythonLaunchDescriptionSource(os.path.join(launch_dir, 'robot_mode_description_minibot.launch.py')), launch_arguments={'bike_robot': 'true'}.items(), ) #robot_mode_description.launch.py contains flagship products, usually larger chassis robots #launch_arguments choices: #senior_akm/top_akm_bs/top_akm_dl #senior_mec_bs/senior_mec_dl/top_mec_bs/top_mec_dl/ mec_EightDrive_robot/flagship_mec_bs_robot/flagship_mec_dl_robot�� #senior_omni/top_omni #senior_4wd_bs_robot/senior_4wd_dl_robot/flagship_4wd_bs_robot/flagship_4wd_dl_robot/top_4wd_bs_robot/top_4wd_dl_robot #senior_diff_robot/four_wheel_diff_bs/four_wheel_diff_dl/flagship_four_wheel_diff_bs_robot/flagship_four_wheel_diff_dl_robot #!!!At the same time, you need to modify ld.add_action(flagship_type) and #ld.add_action(minibot_type) flagship_type = IncludeLaunchDescription( PythonLaunchDescriptionSource(os.path.join(launch_dir, 'robot_mode_description.launch.py')), launch_arguments={'senior_akm': 'true'}.items(), ) ld = LaunchDescription() ld.add_action(minibot_type) #ld.add_action(flagship_type) ld.add_action(carto_slam_dec) ld.add_action(wheeltec_robot) ld.add_action(base_to_link) ld.add_action(base_to_gyro) # ld.add_action(joint_state_publisher_node) ld.add_action(imu_filter_node) ld.add_action(robot_ekf) return ld base_serial.launch.py文件代码为: from launch import LaunchDescription from launch.actions import DeclareLaunchArgument from launch.substitutions import LaunchConfiguration from launch.conditions import IfCondition from launch.conditions import UnlessCondition import launch_ros.actions #def launch(launch_descriptor, argv): def generate_launch_description(): return LaunchDescription([ launch_ros.actions.Node( package='turn_on_wheeltec_robot', executable='wheeltec_robot_node', output='screen', parameters=[{'usart_port_name': '/dev/ttyACM0', 'serial_baud_rate':115200, 'robot_frame_id': 'base_footprint', 'odom_frame_id': 'odom_combined', 'cmd_vel': 'cmd_vel',}], ) ]) robot_mode_description_minibot.launch.py文件代码为: import os from ament_index_python.packages import get_package_share_directory import launch_ros.actions from launch import LaunchDescription from launch.actions import DeclareLaunchArgument, GroupAction, SetEnvironmentVariable from launch.conditions import IfCondition from launch.substitutions import LaunchConfiguration, PythonExpression from launch_ros.actions import LoadComposableNodes from launch_ros.actions import Node from launch_ros.descriptions import ComposableNode from nav2_common.launch import RewrittenYaml def generate_robot_node(robot_urdf,child): return launch_ros.actions.Node( package='robot_state_publisher', executable='robot_state_publisher', name=f'robot_state_publisher_{child}', arguments=[os.path.join(get_package_share_directory('wheeltec_robot_urdf'), 'urdf', robot_urdf)], ) def generate_static_transform_publisher_node(translation, rotation, parent, child): return launch_ros.actions.Node( package='tf2_ros', executable='static_transform_publisher', name=f'base_to_{child}', arguments=[translation[0], translation[1], translation[2], rotation[0], rotation[1], rotation[2], parent, child], ) def generate_launch_description(): bike_robot = LaunchConfiguration('bike_robot', default='false') bike_robot_ = GroupAction( condition=IfCondition(bike_robot), actions=[ generate_robot_node('xuan_bike_robot.urdf','bike_robot'), generate_static_transform_publisher_node(['0.048', '0', '0.18'], ['0', '0', '0'], 'base_link', 'laser'), generate_static_transform_publisher_node(['0.048', '0', '0.18'], ['0', '0', '0'], 'base_link', 'camera_link'), ]) # Create the launch description and populate ld = LaunchDescription() # Set environment variables # Declare the launch options #ld.add_action(declare_use_composition_cmd) # Add the actions to launch all of the localiztion nodes ld.add_action(mini_mec_) ld.add_action(mini_akm_) ld.add_action(mini_tank_) ld.add_action(mini_4wd_) ld.add_action(mini_diff_) ld.add_action(brushless_senior_diff_) ld.add_action(bike_robot_) return ld xuan_bike_robot.urdf文件代码为: <?xml version="1.0"?> <robot name="wheeltec_robot"> <visual> <geometry> <mesh filename="file:///home/deepbot/ros-relate/wheeltec_ros2/src/wheeltec_robot_urdf/wheeltec_robot_urdf/meshes/Xuan-release.stl"scale="0.001 0.001 0.001"/> </geometry> <origin xyz="0 0 0" rpy="0 0 0"/> <material name="blue"> <color rgba="0 0 0.8 0.5"/> </material> </visual> </robot>

最新推荐

recommend-type

Linphone APK:适用于Android的SIP通信客户端

资源下载链接为: https://pan.quark.cn/s/c705392404e8 Linphone是一款功能强大的通信工具,支持高清音频和视频通话,适用于智能手机、平板电脑以及桌面平台。它遵循电信行业的开放标准,如SIP和RTP,因此能够与大多数PBX系统和SIP服务器实现无缝交互操作,并且可以与任何SIP VoIP运营商配合使用。此外,Linphone还提供了一套完整的即时消息传递和IP到IP呼叫解决方案,其中包括Linphone应用程序、Liblinphone跨平台VoIP软件开发工具包(SDK)以及Flexisip服务器等互补产品。
recommend-type

掌握C#.NET命令创建水晶报表实例技术

创建水晶报表源程序实例是.NET开发人员常见的任务之一,特别是在使用Visual Studio开发环境时。水晶报表是一种强大的报表生成工具,它允许开发者设计复杂的数据报告,并能很好地与C#和.NET环境集成。本篇知识点将围绕如何在Visual Studio .NET环境下使用C#编写源代码来命令式创建水晶报表实例进行详细阐述。 首先,要实现命令方式创建水晶报表,你需要熟悉以下几个方面: 1. **水晶报表的基本概念**:了解水晶报表的基本组成,包括报表头部、数据区域、分组、排序和汇总等元素。 2. **C#编程语言**:掌握C#语言的基本语法和面向对象编程的概念,为编写实例代码打下基础。 3. **Visual Studio .NET开发环境**:熟练使用Visual Studio .NET进行项目的创建、调试和编译。 4. **水晶报表设计器**:在Visual Studio中使用水晶报表设计器进行报表的设计,包括绑定数据源和定义报表格式。 5. **报表引擎和API**:理解水晶报表引擎的工作原理以及如何通过.NET API操作水晶报表对象模型。 接下来是创建水晶报表实例的具体步骤和知识点: ### 步骤一:安装和配置水晶报表 在开始编程之前,你需要确保已经安装了水晶报表组件,并且在Visual Studio中正确配置。水晶报表通常作为Visual Studio的一部分安装,或者你可以通过Visual Studio安装器来安装相应的水晶报表开发包。 ### 步骤二:创建项目并添加水晶报表文件 1. 打开Visual Studio,创建一个新的Windows窗体应用程序(.NET Framework)。 2. 在项目中添加一个新的水晶报表文件(.rpt)。可以通过在解决方案资源管理器中右键点击项目 -> 添加 -> 新项 -> 水晶报表。 3. 使用水晶报表设计器设计报表布局,例如添加文本字段、图表、数据区域等。 ### 步骤三:编写C#代码创建报表实例 在创建报表实例时,可以使用以下C#代码示例: ```csharp // 引入水晶报表命名空间 using CrystalDecisions.CrystalReports.Engine; namespace CrystalReportsDemo { class Program { static void Main(string[] args) { // 实例化报表文档 ReportDocument水晶报表实例 = new ReportDocument(); // 加载报表模板(.rpt文件) 水晶报表实例.Load("YourReportName.rpt"); // 设置报表数据源 水晶报表实例.SetDataSource(yourDataSource); // yourDataSource为你的数据源对象 // 如果需要导出报表,可使用以下代码 水晶报表实例.ExportToDisk(ExportFormatType.PortableDocFormat, "输出文件路径.pdf"); 水晶报表实例.ExportToDisk(ExportFormatType.Excel, "输出文件路径.xls"); // 如果是在Windows窗体应用程序中,还可以直接显示报表 FormViewer viewer = new FormViewer(); viewer.ReportSource = 水晶报表实例; viewer.ShowDialog(); } } } ``` 在上述代码中,使用`ReportDocument`类来操作水晶报表,通过`Load`方法加载报表模板,并通过`SetDataSource`方法将数据源绑定到报表实例。 ### 步骤四:命令行创建水晶报表实例(可选) 虽然上述步骤是在Windows窗体应用程序中创建和显示报表,但问题中特别提到了“命令方式”。在.NET中,通常意味着控制台应用程序或在不使用窗体的情况下执行操作。以下是一个简化的控制台应用程序示例,它演示了如何在控制台环境中创建报表实例: ```csharp using CrystalDecisions.CrystalReports.Engine; using System; using System.Data; using System.Data.SqlClient; namespace ConsoleCrystalReports { class Program { static void Main(string[] args) { // 实例化报表文档 ReportDocument水晶报表实例 = new ReportDocument(); // 加载报表模板(.rpt文件) 水晶报表实例.Load("YourReportName.rpt"); // 创建数据库连接字符串 string connectionString = "你的数据库连接字符串"; // 创建数据适配器和数据表,填充数据集 SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM YourDataTable", connectionString); DataSet dataSet = new DataSet(); adapter.Fill(dataSet, "YourDataTable"); // 设置报表数据源 水晶报表实例.SetDataSource(dataSet.Tables["YourDataTable"]); // 导出报表到文件 水晶报表实例.ExportToDisk(ExportFormatType.PortableDocFormat, "输出文件路径.pdf"); Console.WriteLine("报表导出完成!"); Console.ReadKey(); } } } ``` 这个控制台程序创建了一个报表实例,并将一个数据库表的数据绑定到报表上,然后将生成的PDF报表导出到指定的路径。 通过上述步骤,我们可以了解到在Visual Studio .NET环境中,如何使用C#编程语言通过命令方式创建水晶报表源程序实例。需要注意的是,实例中提及的`YourReportName.rpt`应替换为实际报表模板文件的名称,`yourDataSource`应替换为实际数据源对象,`输出文件路径.pdf`应替换为你希望保存报表的具体路径。 在学习过程中,开发者还需注意水晶报表的版本兼容性、不同数据库驱动的配置、异常处理机制、报表权限控制以及复杂的报表设计等高级主题,这些都是在实际开发过程中可能遇到的关键知识点。
recommend-type

【性能测试基准】:为RK3588选择合适的NVMe性能测试工具指南

# 1. NVMe性能测试基础 ## 1.1 NVMe协议简介 NVMe,全称为Non-Volatile Memory Express,是专为固态驱动器设计的逻辑设备接口规范。与传统的SATA接口相比,NVMe通过使用PCI Express(PCIe)总线,大大提高了存储设备的数据吞吐量和IOPS(每秒输入输出操作次数),特别适合于高速的固态存储设备。
recommend-type

SAR成像,RD算法通用模板,matlab

<think>我们正在讨论SAR成像中的距离多普勒(RD)算法,并需要提供一个通用的Matlab实现模板。RD算法是合成孔径雷达(SAR)成像处理中的一种经典算法,主要分为三个步骤:距离压缩、距离徙动校正和方位压缩。下面将提供一个简化的RD算法实现模板。注意:这是一个高度简化的版本,实际应用中需要考虑雷达参数、运动补偿、插值方法等多种因素。这里假设雷达是正侧视模式,且不考虑平台运动误差。###RD算法步骤1.**距离压缩**:对每个脉冲(即每一行)进行脉冲压缩(通常使用匹配滤波)。2.**距离徙动校正(RCMC)**:校正由于目标与雷达相对运动引起的距离徙动(这里主要考虑距离走动和距离弯曲,在
recommend-type

VBA Excel学习材料及补丁升级文件

VBA(Visual Basic for Applications)是微软公司推出的一种事件驱动编程语言,主要用于Office系列软件的自动化控制。它作为Excel中不可或缺的组成部分,使得用户可以创建宏来自动化重复任务,从而提高工作效率。以下针对提供的文件信息,详细阐述其关键知识点。 首先,【标题】中提到的“VBA 学习材料 4”可能指的是一个系列教程中的第四份学习材料,通常包含了一系列分步骤的学习内容。学习材料通常会涵盖VBA基础知识、Excel对象模型、编程逻辑与技巧、错误处理、以及特定Excel VBA应用实例。 【描述】与【标签】部分几乎一致,传达了文件为一个压缩包(.rar格式),内含四个部分:Excel参考模板、参考资料、本书范例、以及Excel补丁与升级文件。这些内容表明了所包含的材料旨在为学习者提供从基础知识到实操范例的全面学习资源。 1. **Excel 参考模板**:这部分内容可能包含了用于执行特定任务的预设Excel文件。这些模板中可能已经写入了VBA代码,用以展示如何通过VBA来处理数据、生成报表、创建用户交互界面等。通过这些模板,学习者可以直接观察代码是如何在实际应用中工作的,并且可以在此基础上进行修改和扩展,从而加深对VBA应用的理解。 2. **参考资料**:通常包含相关的电子文档或文本资料,可能是书本、在线文章、官方文档、技术博客的链接等。这些材料可能会对VBA的语法、结构、函数、对象模型和常用库进行说明,并提供理论知识以及实际应用案例。参考资料是学习者加深理解、扩大知识面的重要辅助材料。 3. **本书范例**:这部分可能包含了一本书中提到的所有VBA编程范例代码。通过范例,学习者可以学习到编写VBA代码的正确方法,理解不同场景下的编程思路以及如何实现特定功能。这些范例还可以作为学习者在实际编写代码时的参考。 4. **Excel补丁与升级文件**:这部分可能涉及了如何通过VBA对Excel程序本身进行补丁修复和功能升级。在实际使用Excel的过程中,可能会遇到软件的某些功能不够完善或存在bug,通过编写VBA代码可以定制化地增强Excel的功能,解决特定问题。这可能包括修复文件损坏、增加用户自定义功能、改善用户界面等。此外,这也可能涉及到Excel版本更新后,原有VBA代码的兼容性处理。 由于文件名称列表中仅提到了“Excel补丁与升级文件”,说明实际提供给学习者的压缩包中只包含了这一部分的内容。这可能意味着其他三个部分的内容是通过其他渠道或文件提供,或者在后续的学习材料中会陆续提供。 VBA是一种功能强大的工具,能够大幅提高办公效率。对于想深化Excel应用和提高工作效率的用户来说,学习并掌握VBA编程是一项极为有用的技能。在学习过程中,要注重理解VBA的编程逻辑、熟悉Excel对象模型、掌握各种常用对象和方法的使用,同时还需要不断实践和解决实际问题,从而逐步提升个人技能水平。
recommend-type

【固态硬盘寿命延长】:RK3588平台NVMe维护技巧大公开

# 1. 固态硬盘寿命延长的基础知识 ## 1.1 固态硬盘的基本概念 固态硬盘(SSD)是现代计算设备中不可或缺的存储设备之一。与传统的机械硬盘(HDD)相比,SSD拥有更快的读写速度、更小的体积和更低的功耗。但是,SSD也有其生命周期限制,主要受限于NAND闪存的写入次数。 ## 1.2 SSD的写入次数和寿命 每块SSD中的NAND闪存单元都有有限的写入次数。这意味着,随着时间的推移,SSD的
recommend-type

rviz内怎么配置topic

<think>我们正在讨论如何在RVIZ中配置topic。根据用户之前的问题,我们知道用户在使用轮趣科技ROS小车建图时遇到了"notfdata"问题,并已经了解了一些关键topic。现在用户想知道如何在RVIZ中配置和使用这些topic。参考引用[1]:rviz是ROS自带的图形化工具,可以很方便地通过图形界面开发调试ROS。界面主要分为上侧菜单区、左侧显示内容设置区、中间显示区、右侧显示视角设置区、下侧ROS状态区。因此,回答应该围绕如何在rviz的界面中配置topic,特别是与建图相关的topic(如/tf,/scan,/odom,/map等)。步骤应该包括:1.启动rviz2.添加显示
recommend-type

Report Machine 5.5发布:新版本增加统计功能并优化界面

根据提供的文件信息,可以提炼出如下IT知识点: 1. Report Machine 5.5版本特性: - Report Machine是一款报表软件,版本5.5相较于3.0版本增加了统计函数SUM(求和)、COUNT(计数)、MIN(最小值)、MAX(最大值)等。 - 新版本中还对用户界面进行了美化,提升了用户体验。 2. 报表软件功能与应用: - 报表软件用于生成、展示、打印和导出各种复杂的数据统计和分析报告。 - 常见的报表功能还包括但不限于排序、筛选、分组、图表展示等。 - 报表软件广泛应用于企业数据分析、财务报表、销售数据统计等多种场景。 3. Delphi编程语言和开发环境: - Delphi是一种面向对象的编程语言,广泛应用于快速应用程序开发(RAD)。 - Report Machine 5.5版本使用Delphi作为开发语言,因此涉及到Delphi的相关开发知识。 - Delphi具有强大的数据库操作能力,适用于构建复杂的数据处理和报告系统。 4. 软件版本迭代: - 软件开发中通常遵循版本迭代的过程,每个新版本都会增加一些新功能,改善用户体验,或者修复旧版本中的bug。 - 从描述中可以看出Report Machine 从3.0迭代到5.5版本,加入了新的统计功能。 5. 文件压缩与解压缩工具: - 压缩包子文件的文件名称列表中提到的“.rar”和“.zip”是两种常见的压缩文件格式。 - 在IT行业中,文件压缩是为了节省存储空间、加快网络传输速度,以及对文件进行打包管理。 - 常见的文件压缩工具有WinRAR、WinZip、7-Zip等。 6. DEMO应用的作用: - DEMO通常指的演示版或示例应用程序,用于向潜在用户展示软件的功能和操作方法。 - 根据描述,压缩文件中包含了Report Machine 3.0和7.0版本的DEMO,可以作为学习和参考的资源,帮助用户理解软件的功能和使用方法。 - DEMO还可以用来测试软件是否满足用户需求,验证软件性能。 7. 报表软件的版本演化: - 从DEMO文件列表中可以发现,Report Machine从3.0版本演进到7.0版本,展示了其在功能上的不断扩展和完善。 - 软件版本的演化是IT行业中的常态,随着技术的进步和用户需求的变化,软件会持续更新迭代,增加新的特性和优化。 - 报表软件的版本演化通常伴随着新技术的引入,例如大数据分析、云计算集成等。 8. Delphi开发环境中的报表工具: - Delphi环境中提供了多种报表工具,如QuickReport、FastReport等。 - 这些报表工具能够与Delphi语言紧密结合,为开发者提供便捷的报表解决方案。 - 报表工具通常具有可视化的报表设计界面,可以轻松实现报表的布局、数据源绑定、样式定制等功能。 9. 软件升级策略: - 软件的升级应该遵循一定的策略,确保升级过程的平滑和用户的最小干扰。 - 新功能的引入应该有详细的文档说明和教学示例,方便用户快速掌握和使用。 - 对于像Report Machine这样的工具,软件开发者应当定期收集用户反馈,优先解决用户最关心的问题,并在此基础上开发新功能。 通过以上的知识点,我们可以了解到Report Machine 5.5版本相较于旧版新增的统计功能,Delphi在报表软件开发中的应用,以及软件版本迭代和升级策略的重要性和常见实践。同时,也强调了DEMO在软件学习和演示中的价值,以及压缩文件在IT行业中的普遍应用。
recommend-type

【故障恢复策略】:RK3588与NVMe固态硬盘的容灾方案指南

# 1. RK3588处理器与NVMe固态硬盘的概述 ## 1.1 RK3588处理器简介 RK3588是Rockchip推出的一款高端处理器,具备强大的性能和多样的功能,集成了八核CPU和六核GPU,以及专用的AI处理单元,主要用于高端移动设备、边缘计算和
recommend-type

给出这篇文献

<think>我们正在验证Si的电子结构计算结果(特别是带隙和有效质量)与文献值的一致性。用户已经通过`sumo-bandstats`输出了计算结果,现在需要文献支持进行对比。关键计算结果:-间接带隙:0.611eV-直接带隙:2.557eV-价带顶(VBM)在Γ点([0,0,0])-导带底(CBM)在k点[0.42,0.00,0.42](约85%Γ-X路径)-有效质量:空穴:-0.093,-0.645,-0.645(三个带)电子:0.250和1.795(两个方向)注意:计算使用的是PBE泛函,已知PBE会低估带隙(实验值1.12eV),所以0.611eV的间接带隙符合预期。文献对比:1.**