-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
169 lines (133 loc) · 4.96 KB
/
main.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import numpy as np
from robot import Biped
from walking import PreviewControl
import argparse
def stand():
biped = Biped()
CoM_height = 0.45
targetRPY = [0.0, 0.0, 0.0]
targetPosL = [0.0, 0.065, -CoM_height]
targetPosR = [0.0, -0.065, -CoM_height]
biped.positionInitialize(initializeTime=0.2)
while True:
incline = biped.getIncline()
biped.resetIncline(incline)
targetRPY[1] = incline
biped.setLegPositions(targetPosL, targetPosR, targetRPY)
biped.oneStep()
def squat():
biped = Biped()
CoM_height = 0.45
targetRPY = [0.0, 0.0, 0.0]
targetPosL = [0.0, 0.065, -CoM_height]
targetPosR = [0.0, -0.065, -CoM_height]
biped.positionInitialize(initializeTime=0.1)
dp = 0.002
while True:
incline = biped.getIncline()
biped.resetIncline(incline)
targetRPY[1] = incline
for _ in range(100):
biped.setLegPositions(targetPosL, targetPosR, targetRPY)
biped.oneStep()
targetPosL[2] += dp
targetPosR[2] += dp
for _ in range(100):
biped.setLegPositions(targetPosL, targetPosR, targetRPY)
biped.oneStep()
targetPosL[2] -= dp
targetPosR[2] -= dp
def jump(withTorsoTwist=False):
biped = Biped()
CoM_height = 0.45
targetRPY = [0.0, 0.0, 0.0]
targetPosL = [0.0, 0.065, -CoM_height]
targetPosR = [0.0, -0.065, -CoM_height]
biped.positionInitialize(initializeTime=0.1)
dp = 0.0025
dRPY = 0.0065
while True:
incline = biped.getIncline()
biped.resetIncline(incline)
targetRPY[1] = incline
for _ in range(60):
biped.setLegPositions(targetPosL, targetPosR, targetRPY)
biped.oneStep()
targetPosL[2] += dp
targetPosR[2] += dp
if withTorsoTwist:
targetRPY[2] += dRPY
for _ in range(60):
biped.setLegPositions(targetPosL, targetPosR, targetRPY)
biped.oneStep()
targetPosL[2] -= dp
targetPosR[2] -= dp
if withTorsoTwist:
targetRPY[2] -= dRPY
def torsoTwist():
biped = Biped()
CoM_height = 0.45
targetRPY = [0.0, 0.0, -0.25]
targetPosL = [0.0, 0.065, -CoM_height]
targetPosR = [0.0, -0.065, -CoM_height]
biped.positionInitialize(initializeTime=0.1)
dp = 0.005
while True:
incline = biped.getIncline()
biped.resetIncline(incline)
targetRPY[1] = incline
for _ in range(100):
biped.setLegPositions(targetPosL, targetPosR, targetRPY)
biped.oneStep()
targetRPY[2] += dp
for _ in range(100):
biped.setLegPositions(targetPosL, targetPosR, targetRPY)
biped.oneStep()
targetRPY[2] -= dp
def walk():
biped = Biped()
# CoM_height = 0.45
# CoM_to_body = np.array([0.0, 0.0, 0.0])
targetRPY = [0.0, 0.0, 0.0]
pre = PreviewControl(dt=1./240., Tsup_time=0.3, Tdl_time=0.1, previewStepNum=190)
biped.positionInitialize(initializeTime=0.2)
CoM_trajectory = np.empty((0, 3), float)
trjR_log = np.empty((0, 3), float)
trjL_log = np.empty((0, 3), float)
supPoint = np.array([0., 0.065])
while True:
incline = biped.getIncline()
biped.resetIncline(incline)
targetRPY[1] = incline
stepHeight = biped.getStepHeight()
# Generates one cycle trajectory
CoM_trj, footTrjL, footTrjR = pre.footPrintAndCoM_trajectoryGenerator(inputTargetZMP=supPoint,
inputFootPrint=supPoint,
stepHeight=stepHeight)
CoM_trajectory = np.vstack((CoM_trajectory, CoM_trj))
trjR_log = np.vstack((trjR_log, footTrjR))
trjL_log = np.vstack((trjL_log, footTrjL))
for j in range(len(CoM_trj)):
targetPosR = footTrjR[j] - CoM_trj[j]
targetPosL = footTrjL[j] - CoM_trj[j]
biped.setLegPositions(targetPosL, targetPosR, targetRPY)
biped.oneStep()
supPoint[0] += biped.getStride()
supPoint[1] = -supPoint[1]
if __name__ == '__main__':
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--action', help='Choose from walk, stand, squat, jump_w_Twist, jump_wo_Twist, torsoTwist', type=str, default='walk')
args = parser.parse_args()
#---------------------------------------------------------------------------------------------------------------------------------
if (args.action == 'walk'):
walk()
elif (args.action == 'jump_w_Twist'):
jump(withTorsoTwist=True)
elif (args.action == 'jump_wo_Twist'):
jump(withTorsoTwist=False)
elif (args.action == 'squat'):
squat()
elif (args.action == 'torsoTwist'):
torsoTwist()
else:
stand()