-
Notifications
You must be signed in to change notification settings - Fork 3
/
Week1.py
30 lines (22 loc) · 1.02 KB
/
Week1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import rospy
from geometry_msgs.msg import Twist # This is the message type the robot uses for velocities
class CommandVelocity():
"""Driving my robot
"""
def __init__(self):
rospy.loginfo("Starting node")
self.pub = rospy.Publisher("...", Twist) # Creating a publisher with whatever name...
# A function to send velocities until the node is killed
def send_velocities(self):
r = rospy.Rate(10) # Setting a rate (hz) at which to publish
while not rospy.is_shutdown(): # Runnin until killed
rospy.loginfo("Sending commands")
twist_msg = Twist() # Creating a new message to send to the robot
# ... put something relevant into your message
self.pub.publish(twist_msg) # Sending the message via our publisher
r.sleep() # Calling sleep to ensure the rate we set above
if __name__ == '__main__':
rospy.init_node("command_velocity")
cv = CommandVelocity()
cv.send_velocities() # Calling the function
rospy.spin()