#!/usr/bin/env pythonimport rospy
from geometry_msgs.msg import Twist
import time
classMoveBB8():def__init__(self):
self.bb8_vel_publisher = rospy.Publisher('/cmd_vel', Twist, queue_size=1)
self.ctrl_c = False
rospy.on_shutdown(self.shutdownhook)
self.rate = rospy.Rate(10) # 10hzdefpublish_once_in_cmd_vel(self, cmd):"""
This is because publishing in topics sometimes fails teh first time you publish.
In continuos publishing systems there is no big deal but in systems that publish only
once it IS very important.
"""whilenot self.ctrl_c:
connections = self.bb8_vel_publisher.get_num_connections()
if connections > 0:
self.bb8_vel_publisher.publish(cmd)
rospy.loginfo("Cmd Published")
breakelse:
self.rate.sleep()
def