相关代码:
<node pkg="turn_on_wheeltec_robot" type="wheeltec_robot_node" name="wheeltec_robot" output="screen" respawn="false">
<param name="usart_port_name" type="string" value="/dev/wheeltec_controller"/>
<param name="serial_baud_rate" type="int" value="115200"/>
<param name="odom_frame_id" type="string" value="$(arg odom_frame_id)"/>
<param name="robot_frame_id" type="string" value="base_footprint"/>
<param name="gyro_frame_id" type="string" value="gyro_link"/>
<remap if="$(arg smoother)" from="cmd_vel" to="smoother_cmd_vel"/>
</node>
在turn_on_wheeltec_robot文件夹下有个文件src文件夹里面有个文件叫wheeltec_robot.cpp的文件,其中有一段代码用到了上述的参数:
turn_on_robot::turn_on_robot():Sampling_Time(0),Power_voltage(0)
{
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()入口参数分别对应:参数服务器上的名称 参数变量名 初始值
private_nh.param<std::string>("usart_port_name", usart_port_name, "/dev/wheeltec_controller"); //Fixed serial port number //固定串口号
private_nh.param<int> ("serial_baud_rate", serial_baud_rate, 115200); //Communicate baud rate 115200 to the lower machine //和下位机通信波特率115200
private_nh.param<std::string>("odom_frame_id", odom_frame_id, "odom_combined"); //The odometer topic corresponds to the parent TF coordinate //里程计话题对应父TF坐标
private_nh.param<std::string>("robot_frame_id", robot_frame_id, "base_footprint"); //The odometer topic corresponds to sub-TF coordinates //里程计话题对应子TF坐标
private_nh.param<std::string>("gyro_frame_id", gyro_frame_id, "gyro_link"); //IMU topics correspond to TF coordinates //IMU话题对应TF坐标
}
我当时就在想这个node里的pkg就是某个功能包,好,找到了这个功能包,那么type应该是某个cpp文件或者py文件吧,然后找了很久发现根本没有这个文件,然后查阅了一下资料如下:
<node pkg="包名,就是节点所属的包"
type="节点类型(与之相同名称的可执行文件)"
name="节点名称(在 ROS 网络拓扑中节点的名称)"
args="将参数传递给节点" (可选)
respawn="true | false如果节点退出,是否自动重启" (可选)
output="log | screen,日志发送目标,可以设置为 log 日志文件,或 screen 屏幕,默认是 log" (可选)/>
现在我们看一下wheeltec_robot.cpp里面的节点名称是什么吧
int main(int argc, char** argv)
{
ros::init(argc, argv, "wheeltec_robot"); //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;
}
好家伙,该节点名是wheeltec_robot,难道我们在type中就用这名嘛,但是我们用的是wheeltec_robot_node这个名称,这个名称到底在哪里呢。回想一下,type里应该=“是节点类型(与之相同名称的可执行文件)”所以我们要的是文件名,最主要的是去找配置文件了,我们看一下CMakelists.txt文件:
add_executable(wheeltec_robot_node src/wheeltec_robot.cpp src/Quaternion_Solution.cpp)
target_link_libraries(wheeltec_robot_node ${catkin_LIBRARIES})
在这个文件里面终于看到了wheeltec_robot_node这个玩意,并且看到了cpp文件,来解释一下:
这是用src文件夹下的wheeltec_robot.cpp文件生成一个wheeltec_robot_node的可执行文件,cpp文件只是你创建的文件,但是最终映射的文件却是wheeltec_robot_node这个文件,一般而言源文件和生成的可执行文件的名称设置为一样的。
下面的target_link_libraries是将生成的可执行文件和catkin库链接到一起。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)