当您使用具有许多坐标系的机器人时,将它们全部发布到tf变得非常重要。
The robot state publisher是一个可以为您完成此任务的工具。
机器人状态发布者可帮助您将机器人的状态广播到tf transform library。
机器人状态发布者具有机器人的运动学模型;
因此,当给定机器人的关节位置,he robot state publisher can compute and broadcast the 3D pose of each link in the robot.
您可以将机械手状态发布者用作独立的ROS节点或库。
1 作为ROS节点运行
1.1 robot_state_publisher
运行机器人状态发布者的最简单方法是作为节点。对于普通用户,这是推荐用法。运行机器人状态发布者需要两件事:
-
A urdf xml robot description loaded on the Parameter Server.
-
A source that publishes the joint positions as a sensor_msgs/JointState.
Please read the following sections on how to configure the parameters and topics for robot_state_publisher.
1.1.1 订阅主题
joint_states(sensor_msgs / JointState):关节的位置信息
1.1.2 参数
robot_description(urdf map)
-
The urdf xml robot description. This is accessed via `urdf_model::initParam`
tf_prefix(string)
publish_frequency(double)
- Publish frequency of state publisher, default: 50Hz.
1.2 示例启动文件
一旦设置了XML机器人描述和关节位置信息,只需创建一个这样的启动文件:
<launch>
<node pkg="robot_state_publisher" type="robot_state_publisher" name="rob_st_pub" >
<remap from="robot_description" to="different_robot_description" />
<remap from="joint_states" to="different_joint_states" />
</node>
</launch>
2 作为一个库运行
高级用户还可以从他们自己的C ++代码中将机器人状态发布者作为库运行。包含头文件后:
#include <robot_state_publisher / robot_state_publisher.h>
all you need is the constructor which takes in a KDL tree
RobotStatePublisher(const KDL :: Tree&tree);
现在,每次要发布机器人的状态时,都要调用publishTransforms函数:
// publish moving joints
void publishTransforms(const std::map<std::string, double>& joint_positions,
const ros::Time& time);
// publish fixed joints
void publishFixedTransforms();
The first argument is a map with joint names and joint positions, and the second argument is the time at which the joint positions were recorded。如果地图不包含所有关节 名称,那也没关系。如果地图包含一些不属于运动学模型的关节名称,也可以。ut note if you don't tell the joint state publisher about some of the joints in your kinematic model, then your tf tree will not be complete.