ROS创建功能包 1 2 $ cd %TOP_DIR_YOUR_CATKIN_WS %/src $ catkin_create_pkg robot_setup_tf roscpp tf geometry_msgs
TF变换(参考 ) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 #include <ros/ros.h> #include <tf/transform_broadcaster.h> int main (int argc, char ** argv) { ros::init (argc, argv, "robot_tf_publisher" ); ros::NodeHandle n; ros::Rate r (100 ) ; tf::TransformBroadcaster broadcaster; while (n.ok ()){ broadcaster.sendTransform ( tf::StampedTransform ( tf::Transform (tf::Quaternion (0 , 0 , 0 , 1 ), tf::Vector3 (0.1 , 0.0 , 0.2 )), ros::Time::now (),"base_link" , "base_laser" )); r.sleep (); } } #include <ros/ros.h> #include <geometry_msgs/PointStamped.h> #include <tf/transform_listener.h> void transformPoint (const tf::TransformListener& listener) { geometry_msgs::PointStamped laser_point; laser_point.header.frame_id = "base_laser" ; laser_point.header.stamp = ros::Time (); laser_point.point.x = 1.0 ; laser_point.point.y = 0.2 ; laser_point.point.z = 0.0 ; try { geometry_msgs::PointStamped base_point; listener.transformPoint ("base_link" , laser_point, base_point); ROS_INFO ("base_laser: (%.2f, %.2f. %.2f) -----> base_link: (%.2f, %.2f, %.2f) at time %.2f" , laser_point.point.x, laser_point.point.y, laser_point.point.z, base_point.point.x, base_point.point.y, base_point.point.z, base_point.header.stamp.toSec ()); } catch (tf::TransformException& ex){ ROS_ERROR ("Received an exception trying to transform a point from \"base_laser\" to \"base_link\": %s" , ex.what ()); } } int main (int argc, char ** argv) { ros::init (argc, argv, "robot_tf_listener" ); ros::NodeHandle n; tf::TransformListener listener (ros::Duration(10 )) ; ros::Timer timer = n.createTimer (ros::Duration (1.0 ), boost::bind (&transformPoint, boost::ref (listener))); ros::spin (); }
rviz(参考 ) joint_state_publisher包 1 sudo apt-get install ros-kinetic-joint-state-publisher
在launch文件里加入下面这句,用来描述机器人各个关节状态的主题
1 <node name="joint_state_publisher" pkg="learning_urdf" type="joint_state_publisher" />
robot_state_publisher包 1 sudo apt-get install ros-kinetic-robot-state-publisher
在launch文件里加入下面这句,用来加载robot状态发布节点
1 <node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher" />
“robot_state_publisher”就是一个tf广播器 , 它是一个C++的程序 ,订阅了”joint_states”主题,计算各个坐标系之间的变换关系,并将之广播出去
主题的发布者只有joint_state_publisher,订阅者是robot_state_publisher。
保存地图 1 rosrun map_server map_saver -f map(地图名称)