Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ConstantRateThrottle Nodelet #1748

Merged

Conversation

sktometometo
Copy link
Contributor

@sktometometo sktometometo commented Jul 5, 2022

Fix #1747.
There is still some problem.

This PR provides ConstantRateThrottle Nodelet which throttle a topic to accurate specified rate.

constant_rate_throttle_resized.mp4

to run a demo,

roslaunch jsk_topic_tools sample_constant_rate_throttle.launch

@sktometometo sktometometo changed the title Pr/add constant rate throttle node Add ConstantRateThrottle Nodelet Jul 5, 2022
@sktometometo sktometometo force-pushed the PR/add-constant-rate-throttle-node branch from a914e04 to f10149f Compare September 15, 2022 06:36
@sktometometo sktometometo marked this pull request as ready for review September 15, 2022 09:00
@sktometometo sktometometo force-pushed the PR/add-constant-rate-throttle-node branch from 560e7fe to b951036 Compare September 15, 2022 09:23
Copy link
Member

@iory iory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add test code?
You can use hztest.
It's suitable for this PR.
http://wiki.ros.org/rostest/Nodes#hztest

@sktometometo
Copy link
Contributor Author

I'll add a test.

… it.

[jsk_topic_tools] add constant_rate_throttle_node files

[jsk_topic_tools] update for constant_rate_throttle_nodelet

[jsk_topic_tools] add compiling of constant_rate_throttle_nodelet

[jsk_topic_tools] update constatn_rate_throttle_nodelet

[jsk_topic_tools] fix class name for ConstantRateThrottle

[jsk_topic_tools] fix plugin build

[jsk_topic_tools] update sample for constant_rate_nodelet

[jsk_topic_tools] fix bugs

[jsk_topic_tools] add constant_rate_throttle_nodelet docs
@sktometometo sktometometo force-pushed the PR/add-constant-rate-throttle-node branch from f6314a0 to 1b39e05 Compare September 20, 2022 03:09
@k-okada
Copy link
Member

k-okada commented Sep 27, 2022

Will this fix the problaem @haraduka reporeted on 2019/6/25 on 学生教員 mail?

都築くんがこの前の研究会で話したtopic_tools/throttleの挙動がおかしいという件で, sample programを用意してくれました.
https://github.com/tsu-K/throttle_debug

catkin bt
source ~/.bashrc
roslaunch launch/single_array.launch from:=125 to:=50 array_size:=100000

で実行できます.
少なくとも都築と自分のPCでは, size:=100程度だとHzが41くらい, size:=1000程度だとHzが21くらい, size:=100000程度だと逆にHzが41くらいまで戻る, という現象が起こっています.
sizeが極端にでかいor小さければ正常に動き, 1000程度だと一気にHzが下がってしまうという現状です.

https://github.com/jsk-ros-pkg/jsk_tendon_robot/pull/1176 ???

@sktometometo
Copy link
Contributor Author

@k-okada

With this PR. throttled rate does not fall down to ~20Hz. But there still exists strange behavior.

<launch>

  <arg name="from" default="125" />
  <arg name="to" default="50" />
  <arg name="array_size" default="10" />
  <arg name="stamped" default="False" />
  <arg name="throttle_type" default="normal" />

  <node name="single_array_publisher"
        pkg="throttle_debug" type= "single_array_publisher.py" output="screen">
    <param name="array_size" value="$(arg array_size)" />
    <param name="publish_rate" value="$(arg from)" />
    <param name="with_header" value="$(arg stamped)" />
  </node>

  <node name="tools_throttle_normal"
      pkg="topic_tools" type= "throttle" args="messages /hoge $(arg to)" output="screen"
      if="$(eval arg('throttle_type')=='normal')"/>

  <node name="tools_throttle_constant"
      pkg="nodelet" type="nodelet"
      args="standalone jsk_topic_tools/ConstantRateThrottle" output="screen"
      if="$(eval arg('throttle_type')=='constant_rate')">
      <rosparam subst_value="true">
          update_rate: $(arg to)
      </rosparam>
      <remap from="~input" to="/hoge" />
      <remap from="~output" to="/hoge_throttle" />
  </node>

  <node name="rostopic_hz"
        pkg="rostopic" type="rostopic" args="hz /hoge_throttle -w 10" output="screen"/>

</launch>

array_size = 100

~/ros/ws_jsk_ros_pkg/src/throttle_debug $ roslaunch launch/single_array.launch from:=125 to:=50 array_size:=100 throttle_type:=constant_rate
... logging to /home/sktometometo/.ros/log/076f6d2e-446f-11ed-9a55-7c10c9467f3d/roslaunch-Leopard-16659.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
WARNING: disk usage in log directory [/home/sktometometo/.ros/log] is over 1GB.
It's recommended that you use the 'rosclean' command.

started roslaunch server http://Leopard:42143/

SUMMARY
========

PARAMETERS
 * /rosdistro: melodic
 * /rosversion: 1.14.13
 * /single_array_publisher/array_size: 100
 * /single_array_publisher/publish_rate: 125
 * /single_array_publisher/with_header: False
 * /tools_throttle_constant/update_rate: 50

NODES
  /
    rostopic_hz (rostopic/rostopic)
    single_array_publisher (throttle_debug/single_array_publisher.py)
    tools_throttle_constant (nodelet/nodelet)

auto-starting new master
process[master]: started with pid [16743]
ROS_MASTER_URI=http://localhost:11311

setting /run_id to 076f6d2e-446f-11ed-9a55-7c10c9467f3d
process[rosout-1]: started with pid [16817]
started core service [/rosout]
process[single_array_publisher-2]: started with pid [16824]
process[tools_throttle_constant-3]: started with pid [16831]
type is jsk_topic_tools/ConstantRateThrottle
process[rostopic_hz-4]: started with pid [16838]
WARNING: topic [/hoge_throttle] does not appear to be published yet
subscribed to [/hoge_throttle]
average rate: 49.998
        min: 0.020s max: 0.020s std dev: 0.00013s window: 10
average rate: 50.003
        min: 0.020s max: 0.020s std dev: 0.00010s window: 10

array_size=1000

~/ros/ws_jsk_ros_pkg/src/throttle_debug $ roslaunch launch/single_array.launch from:=125 to:=50 array_size:=1000 throttle_type:=constant_rate
... logging to /home/sktometometo/.ros/log/27873948-446f-11ed-9a55-7c10c9467f3d/roslaunch-Leopard-17233.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
WARNING: disk usage in log directory [/home/sktometometo/.ros/log] is over 1GB.
It's recommended that you use the 'rosclean' command.

started roslaunch server http://Leopard:35997/

SUMMARY
========

PARAMETERS
 * /rosdistro: melodic
 * /rosversion: 1.14.13
 * /single_array_publisher/array_size: 1000
 * /single_array_publisher/publish_rate: 125
 * /single_array_publisher/with_header: False
 * /tools_throttle_constant/update_rate: 50

NODES
  /
    rostopic_hz (rostopic/rostopic)
    single_array_publisher (throttle_debug/single_array_publisher.py)
    tools_throttle_constant (nodelet/nodelet)

auto-starting new master
process[master]: started with pid [17306]
ROS_MASTER_URI=http://localhost:11311

setting /run_id to 27873948-446f-11ed-9a55-7c10c9467f3d
process[rosout-1]: started with pid [17391]
started core service [/rosout]
process[single_array_publisher-2]: started with pid [17398]
process[tools_throttle_constant-3]: started with pid [17405]
type is jsk_topic_tools/ConstantRateThrottle
process[rostopic_hz-4]: started with pid [17411]
WARNING: topic [/hoge_throttle] does not appear to be published yet
subscribed to [/hoge_throttle]
average rate: 61.622
        min: 0.000s max: 0.044s std dev: 0.02008s window: 10
average rate: 51.133
        min: 0.000s max: 0.044s std dev: 0.02184s window: 10
average rate: 51.136
        min: 0.000s max: 0.044s std dev: 0.02184s window: 10

array_size = 10000

~/ros/ws_jsk_ros_pkg/src/throttle_debug $ roslaunch launch/single_array.launch from:=125 to:=50 array_size:=10000 throttle_type:=constant_rate
... logging to /home/sktometometo/.ros/log/3ca9dc4a-446f-11ed-9a55-7c10c9467f3d/roslaunch-Leopard-17803.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
WARNING: disk usage in log directory [/home/sktometometo/.ros/log] is over 1GB.
It's recommended that you use the 'rosclean' command.

started roslaunch server http://Leopard:41497/

SUMMARY
========

PARAMETERS
 * /rosdistro: melodic
 * /rosversion: 1.14.13
 * /single_array_publisher/array_size: 10000
 * /single_array_publisher/publish_rate: 125
 * /single_array_publisher/with_header: False
 * /tools_throttle_constant/update_rate: 50

NODES
  /
    rostopic_hz (rostopic/rostopic)
    single_array_publisher (throttle_debug/single_array_publisher.py)
    tools_throttle_constant (nodelet/nodelet)

auto-starting new master
process[master]: started with pid [17876]
ROS_MASTER_URI=http://localhost:11311

setting /run_id to 3ca9dc4a-446f-11ed-9a55-7c10c9467f3d
process[rosout-1]: started with pid [17950]
started core service [/rosout]
process[single_array_publisher-2]: started with pid [17957]
process[tools_throttle_constant-3]: started with pid [17962]
process[rostopic_hz-4]: started with pid [17970]
type is jsk_topic_tools/ConstantRateThrottle
WARNING: topic [/hoge_throttle] does not appear to be published yet
subscribed to [/hoge_throttle]
average rate: 50.003
        min: 0.000s max: 0.040s std dev: 0.01331s window: 10
average rate: 50.013
        min: 0.000s max: 0.040s std dev: 0.01331s window: 10

I don't know why only 1000 Hz case's average rate is changed...

@k-okada k-okada merged commit 880a9e1 into jsk-ros-pkg:master Oct 13, 2022
@sktometometo sktometometo deleted the PR/add-constant-rate-throttle-node branch October 13, 2022 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Throttle nodes doesn't support exact publish rate.
3 participants