|
a |
|
b/find_init_pose.py |
|
|
1 |
import config |
|
|
2 |
import numpy as np |
|
|
3 |
from SAC.IK_Framework_Mujoco import Muscle_Env |
|
|
4 |
from SAC import kinematics_preprocessing_specs |
|
|
5 |
from SAC.TR_Algorithm import TR_Algorithm |
|
|
6 |
import cma |
|
|
7 |
|
|
|
8 |
### PARAMETERS ### |
|
|
9 |
parser = config.config_parser() |
|
|
10 |
args = parser.parse_args() |
|
|
11 |
|
|
|
12 |
#Setup the mujoco_env with the given args |
|
|
13 |
env = Muscle_Env(args.musculoskeletal_model_path[:-len('musculoskeletal_model.xml')] + 'musculo_targets.xml', 0, 0, args) |
|
|
14 |
|
|
|
15 |
#Set condition 0 and timpoint 0 for finding the initial position |
|
|
16 |
env.set_cond_to_simulate(0, 0) |
|
|
17 |
initial_state = env.get_musculo_state() |
|
|
18 |
|
|
|
19 |
#Define the objective function to be minimized for the IK optimization algorithm |
|
|
20 |
def obj_func(state): |
|
|
21 |
|
|
|
22 |
#Set the env qpos to the state |
|
|
23 |
env.set_state_musculo(state) |
|
|
24 |
|
|
|
25 |
#Return the l2 norm of the resuling difference between the musculo bodies and targets |
|
|
26 |
|
|
|
27 |
return np.linalg.norm(env.get_obs_musculo_bodies() - env.get_obs_targets()) |
|
|
28 |
|
|
|
29 |
|
|
|
30 |
s_final, s_final_musculo, loss_min, cum_loss, success = TR_Algorithm(obj_func, initial_state, env) |
|
|
31 |
|
|
|
32 |
print(f'success: {success}', f'final/min_loss:{loss_min}') |
|
|
33 |
|
|
|
34 |
if success: |
|
|
35 |
print('Initial Pose found and saved') |
|
|
36 |
np.save(args.initial_pose_path + '/initial_qpos_opt.npy', s_final) |