-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwalkv2.py
59 lines (42 loc) · 1.38 KB
/
walkv2.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
56
57
58
59
import motors.servos.servoWirPWM as servoControl
import motors.wheels.sn75SoftwarePwm as dcMotorControl
from motors.wheels.pigpio_encoder_functions import *
import proximity_sensors.sonar.srte as sonar
def loop():
# get sonar readings
proximity = read_proximity_sensors()
# get wheel encoder ticks
leftEncoderTicks
rightEncoderTicks
# set wheel speed
dcMotorControl.set_wheel_drive_rates(v_l, v_r)
# get servo positions
verticalServo.position
verticalServo.minPos
verticalServo.centerPosition
verticalServo.maxPos
horizontalServo.position
horizontalServo.minPos
horizontalServo.centerPosition
horizontalServo.maxPos
# set servo position
verticalServo.setPosition(dt)
horizontalServo.setPosition(dt)
# generate and send the correct commands to the robot
def _send_robot_commands( self ):
v_l, v_r = self._uni_to_diff( v, omega )
self.robot.set_wheel_drive_rates( v_l, v_r )
# Change unicycle model to differential drive model
# See: https://www.toptal.com/robotics/programming-a-robot-an-introductory-tutorial
def _uni_to_diff( self, v, omega ):
# v = translational velocity (m/s)
# omega = angular velocity (rad/s)
R = self.robot_wheel_radius
L = self.robot_wheel_base_length
v_l = ( (2.0 * v) - (omega*L) ) / (2.0 * R)
v_r = ( (2.0 * v) + (omega*L) ) / (2.0 * R)
return v_l, v_r
def cleanup():
cleanupEncoders()
dcMotorControl.cleanup()
sonar.cleanupSonar()