1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ROS Python タイマー割り込み

Last updated at Posted at 2021-10-21

以下のように、rospyを使うとtimer割り込みを簡単に行うことができます.

timer_callback.py
import rospy

def callback(msg):
  print("callback")

rospy.init_node('timer_callback')
rospy.Timer(rospy.Duration(1), callback) # 1秒お気にタイマー割り込み, 0.1秒おきに実行したい場合は rospy.Duration(0.1) のように書く

r = rospy.Rate(3) 
while not rospy.is_shutdown():
  print("loop")
  r.sleep()

結果

$ python timer_callback.py
loop
loop
loop
callbackloop

loop
loop
loop
 callback
loop
loop
loop
 callback
loop
loop
loop
callback

参考:https://raw.githubusercontent.com/ros-visualization/visualization_tutorials/kinetic-devel/interactive_marker_tutorials/scripts/basic_controls.py

c++:https://qiita.com/srs/items/a159fd8e86bb41a2f0ba

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?