-
Notifications
You must be signed in to change notification settings - Fork 0
/
move.py
36 lines (29 loc) · 924 Bytes
/
move.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
31
32
33
34
35
36
#!/usr/bin/env python
import rospy
from geometry_msgs.msg import Twist
from sensor_msgs.msg import LaserScan
from time import time
def laser_scan_callback(data):
print data.ranges
def read_laser_scan_data():
rospy.Subscriber('scan',LaserScan,laser_scan_callback)
def move_motor(fwd,ang):
pub = rospy.Publisher('cmd_vel',Twist,queue_size = 10)
mc = Twist()
mc.linear.x = fwd
mc.angular.z = ang
pub.publish(mc)
if __name__ == '__main__':
rospy.init_node('example_script',anonymous=True)
start_time = time()
duration = 5 #in seconds
forward_speed = 1
turn_speed = 1
while time()<start_time+duration:
try:
read_laser_scan_data()
move_motor(forward_speed,turn_speed)
except rospy.ROSInterruptException:
pass
else:
move_motor(0,0)