最近我开始学习 ROS2,但是我遇到了一个问题,我创建了一个包并定义了一个节点。
#! /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
所以,我需要将上面的 ROS1 代码转换为 ROS2,为此我用 RCLPY 替换了 ROSPY 库并将其编码如下:
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()
现在,我想使用 RCLPY 实现下面给出的代码片段,但我无法获得所需的所有功能,我有 RCLPY 替代品rospy.Rate(2)
,它是rclpy.create_node('simple_node').create_rate(2)
.
while not rospy.is_shutdown():
print("Help me body, you are my only hope")
rate.sleep()
请建议功能的 RCLPY 替代品rospy.is_shutdown()
和rospy.Rate(2).sleep()