-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_stick.py
78 lines (64 loc) · 2.29 KB
/
test_stick.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
import os
import sys
script_path = os.path.abspath(__file__)
script_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(script_path))))
sys.path.append(script_dir)
# -------------------------------
# init parameters
# -------------------------------
from learning.cases.stick.stick_param import Parameters
param = Parameters()
from simulator.fts_simulator import MjSimulator
if param.contact_mode_ == 'lse':
from contact.ball_lse_contact_detection import Contact
from planning.ball_mpc_lse import MPC_IPOPT
import numpy as np
# -------------------------------
# init contact
# -------------------------------
contact = Contact(param)
# -------------------------------
# init simulator
# -------------------------------
simulator = MjSimulator(param)
# -------------------------------
# init planner
# -------------------------------
planner = MPC_IPOPT(param)
theta = np.array([100.545, 0.199336, 1.90137, 1.94328, 1.60386, 0.769046, -0.00101175, 0.755457])
for task_id in range(len(param.target_p_list_)):
task_p = param.target_p_list_[task_id]
task_q = param.target_q_list_[task_id]
simulator.set_goal(task_p, task_q)
param.sol_guess_ = None
step_counter = 0
while step_counter < 300:
if not simulator.dyn_paused_:
print('--------------------------------')
curr_q = simulator.getState()
# -----------------------
# contact detect
# -----------------------
phi_results, jac_n, jac_f = contact.detectOnce(curr_q, simulator)
# -----------------------
# planning
# -----------------------
sol = planner.planOnce(
task_p,
task_q,
curr_q,
phi_results,
jac_n, jac_f,
theta,
param.sol_guess_)
param.sol_guess_ = sol['sol_guess']
mpc_planning = sol['action']
# -----------------------
# simulate
# -----------------------
simulator.stepPositionOnce(mpc_planning)
# exit signal
if simulator.break_out_signal_:
os._exit()
step_counter += 1
simulator.reset_mj_env()