-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwheel_velocities.py
More file actions
50 lines (40 loc) · 1.44 KB
/
wheel_velocities.py
File metadata and controls
50 lines (40 loc) · 1.44 KB
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
#!/usr/bin/env python
#Week 3
import rospy
#import cv2
import math
#import cv2.cv as cv
import numpy as np
#from sensor_msgs.msg import Image
from std_msgs.msg import Float32
#from cv_bridge import CvBridge, CvBridgeError
from geometry_msgs.msg import Twist
wheel_radius = 1.0
robot_radius = 1.0
class wheel_velocities:
def __init__(self):
#Used to access the simulated turtlebot's camera
self.wheel_sub = rospy.Subscriber("/turtlebot_1/wheel_vel_left",
Float32, self.callback)
#Used for the real turtlebot
#self.wheel_sub = rospy.Subscriber("/wheel_vel_left",
# Image, self.callback)
self.pub = rospy.Publisher("/turtlebot_1/cmd_vel", Twist, queue_size=10)
def callback(self, data):
wheel_left = forward_kinematics(float(data), 0.0)
print data
r = rospy.rate(10)
while not rospy.is_shutdown():
twist_msg = Twist()
twist_msg.angular.x = wheel_left[0]
self.pub.publish(twist_msg)
r.sleep()
def forward_kinematics(w_l, w_r):
c_l = wheel_radius * w_l
c_r = wheel_radius * w_r
v = (c_l + c_r) / 2
a = (c_l - c_r) / robot_radius
return (v, a)
wheel_velocities()
rospy.init_node('wheel_velocities', anonymous=True)
rospy.spin()