【ROS工具学习】之topic_tools/throttle,改变节点发布频率

本文介绍了一种在ROS环境中利用topic_tools的throttle工具轻松调整传感器topic发布频率的方法。适用于多传感器融合实验场景,可有效减少数据处理压力。

最近老师想做一个实验,机器人上搭在Hokuyo单线激光雷达,Velodyne16线激光雷达,Kinect2,Bumblebee xb3等传感器,这些传感器做一些实验,因为传感器较多所以采集的数据量非常大,需要在采集的时候降低topic的发布频率,玩过ROS的人都知道,可以直接通过修改源代码发布消息的部分来改变topic的发布频率,但是传感器太多,而且要去仔细研究其源代码,所以比较麻烦,今天发现一神器:topic_tools下面有一个throttle工具可以直接从外部改变topic的发布频率,网址在下面,简单易懂,自己去看吧:
http://wiki.ros.org/topic_tools/throttle

这个工具主要用来限制最大发布频率或者带宽的。

1.限制发布频率
其命令格式如下:

rosrun topic_tools throttle messages <intopic> <msgs_per_sec> [outtopic]

例如,如果我想要让激光雷达的topic发布频率降低至1HZ,则在终端中输入如下命令:

rosrun topic_tools throttle messages base_scan 1.0

可见前面的rosrun topic_tools throttle messages 是指我使用的是throttle 下面的messages模式,其中 intopic是指你想要改变频率的那个topic msgs_per_sec是指你想要它发布的频率,而outtopic是指改变发布频率后的topic的名称,可以省略,如果省略则自动在原来topic的名字上后缀throttle

2.限制每秒发布的字节数
命令格式:

rosrun topic_tools throttle bytes <intopic> <bytes_per_sec> <window> [outtopic]

例如,我想要让雷达的带宽占用降至1KBps,则命令为:

rosrun topic_tools throttle bytes base_scan 1024 1.0

不要问我那个window是生么意思,我也不知道,如果你懂得话,麻烦告诉我下,嘿嘿。

备注:1.所谓的改变topic发布频率并不是说改变之后原来的topic就没了,或者直接在原来的topic上更改,而是更改了之后throttle再把其更改后的topic发布出来,原来的topic仍然存在,例如:原来/base_scan发布的频率是40.0,更改后这个topic发布的频率仍然是40.0,只是使用throttle后会重新生成一个topic,/base_scan_throttle,这个节点的发布频率为1.0
2.这个工具还有一些很有意思的参数,例如,~lazy等于True的话,只有当你订阅到throttle发出来的消息,它才会工作,否则它不工作。
3.我的测试发现它的频率控制其实精度很低,例如我想让它10HZ频率发布,实际才能达到8HZ,不知道我使用是不是有什么问题,如果你知道的话就告诉我吧~

<launch> <arg na<!-- 创建 odom 坐标系 --> <node pkg="tf" type="static_transform_publisher" name="world_to_odom" args="0 0 0 0 0 0 world odom 100" /> <node name="keyboard_control" pkg="uav_simulator" type="keyboard_control" /> <!-- <include file="$(find uav_simulator)/launch/rviz.launme="paused" value="false"/> <arg name="verbose" value="false"/> <arg name="use_sim_time" value="true"/> <arg name="debug" value="false" /> <arg name="world_name" value="$(find uav_simulator)/worlds/generated_env/generated_e> <!-- <arg name="world_name" value="$(find uav_simulator)/worlds/generated_env/genera> <!-- <arg name="world_name" value="$(find uav_simulator)/worlds/generated_env/genera> <!-- launch the custom world --> <include file="$(find gazebo_ros)/launch/empty_world.launch" > <arg name="paused" value="$(arg paused)"/> <arg name="world_name" value="$(arg world_name)"/> <arg name="verbose" value="$(arg verbose)"/> <arg name="use_sim_time" value="$(arg use_sim_time)"/> <arg name="debug" value="$(arg debug)" /> </include> <!-- send robot urdf to param server --> <param name="robot_description" command="cat '$(find uav_simulator)/urdf/car.urdf'" > <!-- push robot_description to factory and spawn robot in gazebo at the origin, chan> <!-- <node name="spawn_gazebo_model" pkg="gazebo_ros" type="spawn_model" args="-urdf> <node pkg="topic_tools" type="throttle" name="gt_pose_throttle" args="messages /CERL> <node pkg="topic_tools" type="throttle" name="gt_vel_throttle" args="messages /CERLA> <node pkg="topic_tools" type="throttle" name="gt_acc_throttle" args="messages /CERLA> <node pkg="topic_tools" type="throttle" name="gt_odom_throttle" args="messages /CERL> <node name="spawn_gazebo_model" pkg="gazebo_ros" type="spawn_model" args="-urdf -par> <!-- TF --> <include file="$(find uav_simulator)/launch/setupTF.launch" > <arg name="pose_topic" value="/CERLAB/quadcopter/pose" /> </include>
最新发布
10-24
不对,你这么改太复杂了,这是你给我写的 GNU nano 4.8 start.launch <launch> <arg name="paused" value="false"/> <arg name="verbose" value="false"/> <arg name="use_sim_time" value="true"/> <arg name="debug" value="false" /> <!-- Gazebo世界 --> <arg name="world_name" value="$(find uav_simulator)/worlds/generated_env/generated_e> <!-- <arg name="world_name" value="$(find uav_simulator)/worlds/generated_env/genera> <!-- <arg name="world_name" value="$(find uav_simulator)/worlds/generated_env/genera> <!-- launch the custom world --> <include file="$(find gazebo_ros)/launch/empty_world.launch" > <arg name="paused" value="$(arg paused)"/> <arg name="world_name" value="$(arg world_name)"/> <arg name="verbose" value="$(arg verbose)"/> <arg name="use_sim_time" value="$(arg use_sim_time)"/> <arg name="debug" value="$(arg debug)" /> </include> <!-- send robot urdf to param server --> <param name="robot_description" command="cat '$(find uav_simulator)/urdf/car1.urdf'"> <!-- 生成模型 --> <node pkg="gazebo_ros" type="spawn_model" name="spawn_car" args="-urdf -model MYROBOT3 -param robot_description -x 0 -y 0 -z 0.1"/> <!-- TF发布 --> <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_pub> <!-- 控制节点 --> <node pkg="my_first_package" name="control" type="lesson6_node"/> </launch>请参照下面这个改,因为我是在下面无人机文件的基础上改成车的,想直接接入其他文件,所以其他东西尽量不要随便改:<launch> <arg name="paused" value="false"/> <arg name="verbose" value="false"/> <arg name="use_sim_time" value="true"/> <arg name="debug" value="false" /> <arg name="world_name" value="$(find uav_simulator)/worlds/generated_env/generated_env_static.world" /> <!-- <arg name="world_name" value="$(find uav_simulator)/worlds/generated_env/generated_env_dynamic.world" /> --> <!-- <arg name="world_name" value="$(find uav_simulator)/worlds/generated_env/generated_env_initial.world" /> --> <!-- launch the custom world --> <include file="$(find gazebo_ros)/launch/empty_world.launch" > <arg name="paused" value="$(arg paused)"/> <arg name="world_name" value="$(arg world_name)"/> <arg name="verbose" value="$(arg verbose)"/> <arg name="use_sim_time" value="$(arg use_sim_time)"/> <arg name="debug" value="$(arg debug)" /> </include> <!-- send robot urdf to param server --> <param name="robot_description" command="cat '$(find uav_simulator)/urdf/car.urdf'" /> <!-- push robot_description to factory and spawn robot in gazebo at the origin, change x,y,z arguments to spawn in a different position --> <!-- <node name="spawn_gazebo_model" pkg="gazebo_ros" type="spawn_model" args="-urdf -param robot_description -model quadcopter -x 0 -y 0 -z 0.1" respawn="false" /> --> <node pkg="topic_tools" type="throttle" name="gt_pose_throttle" args="messages /CERLAB/quadcopter/pose_raw 30 /CERLAB/quadcopter/pose"/> <node pkg="topic_tools" type="throttle" name="gt_vel_throttle" args="messages /CERLAB/quadcopter/vel_raw 30 /CERLAB/quadcopter/vel"/> <node pkg="topic_tools" type="throttle" name="gt_acc_throttle" args="messages /CERLAB/quadcopter/acc_raw 30 /CERLAB/quadcopter/acc"/> <node pkg="topic_tools" type="throttle" name="gt_odom_throttle" args="messages /CERLAB/quadcopter/odom_raw 30 /CERLAB/quadcopter/odom"/> <node name="spawn_gazebo_model" pkg="gazebo_ros" type="spawn_model" args="-urdf -param robot_description -model quadcopter -x -15.0 -y 0.0 -z 0.1 -Y 0.0" respawn="false" /> <!-- TF --> <include file="$(find uav_simulator)/launch/setupTF.launch" > <arg name="pose_topic" value="/CERLAB/quadcopter/pose" /> </include> <node name="keyboard_control" pkg="uav_simulator" type="keyboard_control" /> <!-- <include file="$(find uav_simulator)/launch/rviz.launch"></include> --> </launch>
10-24
评论 4
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值