【发布时间】:2020-10-09 02:07:14
【问题描述】:
最近开始学习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,为此我将 ROSPY 库替换为 RCLPY 并将其编码如下:
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 实现下面给出的代码 sn-p,但我无法获得所需的所有功能,我有 rospy.Rate(2) 的 RCLPY 替代品,它是 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()
【问题讨论】:
标签: python linux ros ros2 rospy