-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathturn_in_place.py
76 lines (63 loc) · 2.78 KB
/
turn_in_place.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from ControlsKit import time_sources, BodyModel, BodyController
from ControlsKit.math_utils import NUM_LEGS, LEG_DOF
from scipy import zeros
from ControlsKit.body_paths import RotateFeetAboutOrigin, BodyPause
from ControlsKit.body_paths import GoToStandardHexagon, TrapezoidalFeetLiftLower
from ControlsKit.leg_paths import TrapezoidalFootMove
controller = BodyController()
model = BodyModel()
path = None
state = 0
RAISE_FIRST_TRIPOD = 1
TURN_FIRST_TRIPOD = 2
RAISE_SECOND_TRIPOD = 3
TURN_SECOND_TRIPOD = 4
FEET_ON_GROUND = leg_lift_height = .2
RESOLVE = 6
STAND = 7
PAUSE = 8
LIFT_TRIPOD_024 = [1, -1, 1, -1, 1, -1]
LIFT_TRIPOD_135 = [-i for i in LIFT_TRIPOD_024]
TURN_ANGLE = 0.2
def update(time, leg_sensor_matrix, imu_orientation, imu_accelerations, imu_angular_rates, command):
global path, state, leg_lift_height
time_sources.global_time.updateTime(time)
model.setSensorReadings(leg_sensor_matrix, imu_orientation, imu_angular_rates)
target_angle_matrix = zeros((NUM_LEGS, LEG_DOF))
if path is None:
path = BodyPause(model, controller, 1)
state = STAND
leg_lift_height = .2
if path.isDone():
if state == STAND:
path = GoToStandardHexagon(model, controller)
state = RAISE_FIRST_TRIPOD
elif state == RAISE_FIRST_TRIPOD:
path = TrapezoidalFeetLiftLower(model, controller, range(NUM_LEGS),
[i * leg_lift_height for i in LIFT_TRIPOD_024], 2, 1)
state = TURN_FIRST_TRIPOD
elif state == TURN_FIRST_TRIPOD:
path = RotateFeetAboutOrigin(model, controller, [0, 2, 4], TURN_ANGLE, 2, 1)
state = RAISE_SECOND_TRIPOD
elif state == RAISE_SECOND_TRIPOD:
leg_lift_height = .4
path = TrapezoidalFeetLiftLower(model, controller, range(NUM_LEGS),
[i * leg_lift_height for i in LIFT_TRIPOD_135], 2, 1)
state = TURN_SECOND_TRIPOD
elif state == TURN_SECOND_TRIPOD:
path = RotateFeetAboutOrigin(model, controller, [1, 3, 5], TURN_ANGLE, 2, 1)
state = FEET_ON_GROUND
elif state == FEET_ON_GROUND:
leg_lift_height = .2
path = TrapezoidalFeetLiftLower(model, controller, range(NUM_LEGS),
[i * leg_lift_height for i in LIFT_TRIPOD_024], 2, 1)
state = RESOLVE
elif state == RESOLVE:
path = RotateFeetAboutOrigin(model, controller, range(NUM_LEGS), -TURN_ANGLE, 2, 1)
state = RAISE_FIRST_TRIPOD
target_angle_matrix = path.update()
# controller.setDesiredJointAngles(joint_angle_matrix)
# Send commands
return controller.update(model.getJointAngleMatrix(), target_angle_matrix)
def turnBody(angle):
pass