Ask Your Question

skyhigh2000's profile - activity

2020-08-17 22:17:26 -0500 received badge  Famous Question (source)
2020-08-03 15:19:59 -0500 received badge  Notable Question (source)
2020-08-03 15:11:45 -0500 commented answer Rate and sleep function in RCLPY library for ROS2

Ohh, it works like that, I understood!! Thank you so much for clearing all my doubts, I apologize if you faced any troub

2020-07-31 18:41:35 -0500 commented answer Rate and sleep function in RCLPY library for ROS2

Awesome, now I'm getting somewhere. So, basically the rclpy.spin() is just counteracting the rate.sleep() function, and

2020-07-31 18:19:07 -0500 received badge  Popular Question (source)
2020-07-31 14:47:09 -0500 commented answer Rate and sleep function in RCLPY library for ROS2

Thank you so much for your answer, the code which you suggested is working fine. Actually, I'm new to ROS, I just had on

2020-07-31 14:23:01 -0500 marked best answer Rate and sleep function in RCLPY library for ROS2

Recently I started learning ROS2, but I've encountered one issue, I've created a package & defined a node.

#! /usr/bin/env python
import rospy
rospy.init_node("simple_node")
rate = rospy.Rate(2) # We create a Rate object of 2Hz
while not rospy.is_shutdown(): # Endless loop until Ctrl + C
    print("Help me body, you are my only hope")
    rate.sleep()
# We sleep the needed time to maintain the Rate fixed above
# This program creates an endless loop that repeats itself 2 times per second (2Hz) 
# until somebody presses Ctrl + C in the Shell

So, I need to convert above ROS1 code for ROS2, for that I replaced ROSPY library with RCLPY and coded it as below:

import rclpy
def main(args=None):
    rclpy.init()
    myfirstnode = rclpy.create_node('simple_node')
    print("Help me body, you are my only hope")

if __name__ == '__main__':
    main()

Now, I want to implement below-given code snippet using RCLPY but I'm not able to get all the functions required, I've got the RCLPY substitute of rospy.Rate(2), it is rclpy.create_node('simple_node').create_rate(2).

while not rospy.is_shutdown():
    print("Help me body, you are my only hope")
    rate.sleep()

Please suggest RCLPY substitutes of the functions rospy.is_shutdown() and rospy.Rate(2).sleep().

2020-07-31 14:23:01 -0500 received badge  Scholar (source)
2020-07-31 14:23:00 -0500 received badge  Supporter (source)
2020-07-30 08:08:37 -0500 asked a question Rate and sleep function in RCLPY library for ROS2

Rate and sleep function in RCLPY library for ROS2 Recently I started learning ROS2, but I've encountered one issue, I've