-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_speed.py
55 lines (41 loc) · 1.37 KB
/
test_speed.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
import rospy
from geometry_msgs.msg import Twist
from geometry_msgs.msg import Vector3
import math
import pygame
"""
Test function used to measure linear and angular speed of the robotino.
The speed and seconds set in this function can be compared with the real measured data, to get an idea of how fast the robot is.
@param linear: if true, the linear speed is tested, else angular
"""
def controller(linear=True):
hertz = 10
secs = 2
#init publisher
pub = rospy.Publisher('/cmd_vel', Twist, queue_size=10)
rospy.init_node('controller', anonymous=True)
rate = rospy.Rate(hertz)
vel = 0.09
ang = math.pi*0.3*0.5
vel2 = 0.0
ang2 = 0.0
#movement data
vec_zero = Vector3(0,0,0)
vec_fwd = Vector3(vel,0,0)
vec_bwd = Vector3(vel2,0,0)
vec_left = Vector3(0,0,ang)
vec_right = Vector3(0,0,-ang2)
for i in range(int(hertz*secs)):
if linear: pub.publish(Twist(vec_fwd, vec_zero))
else: pub.publish(Twist(vec_fwd, vec_left))
rate.sleep()
pub.publish(Twist(vec_zero, vec_zero))
rate.sleep()
for i in range(int(hertz*secs)):
if linear: pub.publish(Twist(vec_bwd, vec_zero))
else: pub.publish(Twist(vec_zero, vec_right))
rate.sleep()
pub.publish(Twist(vec_zero, vec_zero))
if __name__ == '__main__':
controller()