# Path: osim/env/utils/mygym.py
# def convert_to_gym(space):
#     return spaces.Box(np.array(space[0]), np.array(space[1]) )


import math
import numpy as np
import os
import gym
import opensim
import random
from .utils.mygym import convert_to_gym
        from envs.target import VTgtField
        QQ[13] = init_pose[6] # right knee extend
        QQ[15] = -init_pose[7] # right ankle flex
        QQ[10] = -init_pose[8] # left hip adduct
        QQ[9] = -init_pose[9] # left hip flex
        QQ[14] = init_pose[10] # left knee extend
        QQ[16] = -init_pose[11] # left ankle flex

        state.setQ(QQ)
        state.setU(QQDot)
        self.osim_model.set_state(state)
        self.osim_model.model.equilibrateMuscles(self.osim_model.state)

        self.osim_model.state.setTime(0)
        self.osim_model.istep = 0

        self.osim_model.reset_manager()

        d = super(L2M2019Env, self).get_state_desc()
        pose = np.array([d['body_pos']['pelvis'][0], -d['body_pos']['pelvis'][2], d['joint_pos']['ground_pelvis'][2]])
        self.v_tgt_field, self.flag_new_v_tgt_field = self.vtgt.update(pose)
        
        if not project:
            return self.get_state_desc()
        if obs_as_dict:
            return self.get_observation_dict()
        return self.get_observation()

    def load_model(self, model_path = None):
        super(L2M2019Env, self).load_model(model_path)
        observation_space = np.concatenate((self.obs_vtgt_space, self.obs_body_space), axis=1)

# Path: osim/env/utils/mygym.py
# def convert_to_gym(space):
#     return spaces.Box(np.array(space[0]), np.array(space[1]) )


# Path: osim/env/osim.py
import math
import numpy as np
import os
import gym
import opensim
import random
from .utils.mygym import convert_to_gym
        from envs.target import VTgtField

        QQ[13] = init_pose[6] # right knee extend
        QQ[15] = -init_pose[7] # right ankle flex
        QQ[10] = -init_pose[8] # left hip adduct
        QQ[9] = -init_pose[9] # left hip flex
        QQ[14] = init_pose[10] # left knee extend
        QQ[16] = -init_pose[11] # left ankle flex

        state.setQ(QQ)
        state.setU(QQDot)
        self.osim_model.set_state(state)
        self.osim_model.model.equilibrateMuscles(self.osim_model.state)

        self.osim_model.state.setTime(0)
        self.osim_model.istep = 0

        self.osim_model.reset_manager()

        d = super(L2M2019Env, self).get_state_desc()
        pose = np.array([d['body_pos']['pelvis'][0], -d['body_pos']['pelvis'][2], d['joint_pos']['ground_pelvis'][2]])
        self.v_tgt_field, self.flag_new_v_tgt_field = self.vtgt.update(pose)
        
        if not project:
            return self.get_state_desc()
        if obs_as_dict:
            return self.get_observation_dict()
        return self.get_observation()

    def load_model(self, model_path = None):
        super(L2M2019Env, self).load_model(model_path)
        observation_space = np.concatenate((self.obs_vtgt_space, self.obs_body_space), axis=1)

        self.observation_space = convert_to_gym(observation_space)