-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdodge_ball.jl
133 lines (107 loc) · 2.89 KB
/
dodge_ball.jl
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
using Revise
using KinodynamicFabrics
using KinodynamicFabrics.MuJoCo.PythonCall
using KinodynamicFabrics.LinearAlgebra
const kf = KinodynamicFabrics
F = 1e1
N = 30
# init Digit
visualize = true
prioritize = true
environment = :dodge_env
digit = load_digit(;visualize=visualize, env=environment)
## task goals
xᵨs = Dict()
xᵨs[:upper_body_posture] = [-0.15, 1.1, 0, -0.145, 0.15, -1.1, 0, 0.145]
xᵨs[:lower_body_posture] = [0.31, 0.2, 0.19, -0.31, -0.2, -0.19]
xᵨs[:zmp] = [0.0, 0.0]
## task maps
ψs = Dict()
ψs[:level4] = []
ψs[:level3] = []
ψs[:level2] = []
ψs[:level1] = [
:upper_body_posture,
:lower_body_posture,
:dodge,
:zmp_upper_limit,
:zmp_lower_limit,
:joint_lower_limit,
:joint_upper_limit
]
## Task weights
Ws = Dict()
Ws[:upper_body_posture] = 1e0
Ws[:lower_body_posture] = 0.6e0
Ws[:dodge] = 1.5e1
Ws[:zmp_upper_limit] = 1e-1
Ws[:zmp_lower_limit] = 1e-1
Ws[:joint_lower_limit] = 1e-1
Ws[:joint_upper_limit] = 1e-1
## Priorities
Pr = Dict()
Pr[:upper_body_posture] = 2
Pr[:lower_body_posture] = 2
Pr[:dodge] = 2
Pr[:zmp_upper_limit] = 1
Pr[:zmp_lower_limit] = 1
Pr[:joint_lower_limit] = 2
Pr[:joint_upper_limit] = 2
## dynamics functions
g = kf.dyn.generalized_gravity
M = kf.dyn.mass_inertia_matrix
## selection matrics
s_leg = zeros(N)
s_leg[digit.leg_joint_indices] .= 1.0
S_leg = diagm(s_leg)
s_arm = zeros(N)
s_arm[digit.arm_joint_indices] .= 1.0
S_arm = diagm(s_arm)
s_whole = zeros(N)
s_whole[[digit.arm_joint_indices; digit.leg_joint_indices]] .= 1.0
S_whole = diagm(s_whole)
s_toes = zeros(N)
s_toes[[kf.qleftToePitch, kf.qleftToeRoll, kf.qrightToePitch, kf.qrightToeRoll]] .= 1.0
S_toes = diagm(s_toes)
Ss = Dict()
Ss[:upper_body_posture] = S_arm
Ss[:lower_body_posture] = S_leg
Ss[:dodge] = S_leg
Ss[:zmp_upper_limit] = S_toes
Ss[:zmp_lower_limit] = S_toes
Ss[:joint_lower_limit] = S_arm
Ss[:joint_upper_limit] = S_arm
data = Dict()
data[:obstacle] = Dict(
:radius=>0.15,
:position=>zeros(3),
:max_range=>15.0
)
data[:zmp] = Dict(
:prev_time=>0.0,
:prev_com_vel=>[0.0, 0.0],
:g=>9.806,
:prev_zmp=>[0.0, 0.0],
:prev_a=>[0.0, 0.0],
:filter=>0.01,
:lower_limit=>-0.1,
:upper_limit=>0.1
)
Js = nothing
Obstacles = nothing
problem = FabricProblem(ψs, Js, g, M, Ss, xᵨs, Ws, Obstacles, Pr, data,
zeros(N), zeros(N), 1.0/F, N, digit, 0.0, StandingMode())
digit.problem = problem
digit.obstacle_force = -1.0 # Newtons
step(digit)
dists = []
#Horizon
T = 3 # seconds
Horizon = T/digit.Δt # timesteps
for i = 1:Horizon
fabric_controller!(digit)
step(digit)
render_sim(digit, visualize)
end
if visualize digit.viewer.close() end
:Done