Base Environments
These are the base classes for all humanoids used within LocoMuJoCo.
- class BaseHumanoid(use_muscles=False, use_box_feet=True, disable_arms=True, alpha_box_feet=0.5, **kwargs)[source]
Bases:
LocoEnvMuJoCo simulation of a base humanoid model.
- create_dataset(ignore_keys=None)[source]
Creates a dataset from the specified trajectories.
- Args:
ignore_keys (list): List of keys to ignore in the dataset. Default is [“q_pelvis_tx”, “q_pelvis_tz”].
- Returns:
Dictionary containing states, next_states and absorbing flags. For the states the shape is (N_traj x N_samples_per_traj, dim_state), while the absorbing flag has the shape is (N_traj x N_samples_per_traj).
- static generate(env, path, task='walk', dataset_type='real', debug=False, **kwargs)[source]
Returns a Humanoid environment and a dataset corresponding to the specified task.
- Args:
env (class): Humanoid class, either HumanoidTorque or HumanoidMuscle. path (str): Path to the dataset. task (str): Main task to solve. Either “walk” or “run”. dataset_type (str): “real” or “perfect”. “real” uses real motion capture data as the reference trajectory. This data does not perfectly match the kinematics and dynamics of this environment, hence it is more challenging. “perfect” uses a perfect dataset. debug (bool): If True, the smaller test datasets are used for debugging purposes.
- Returns:
An MDP of a Torque Humanoid.
- class BaseHumanoid4Ages(scaling=None, scaling_trajectory_map=None, use_muscles=False, use_box_feet=True, disable_arms=True, alpha_box_feet=0.5, **kwargs)[source]
Bases:
BaseHumanoidMuJoCo simulation of 4 simplified humanoid models. At the beginning of each episode, one of the four humanoid models are sampled and used to simulate a trajectory. The different humanoids should resemble an adult, a teenager (∼12 years), a child (∼5 years), and a toddler (∼1-2 years). This environment can be partially observable by using state masks to hide the humanoid type indicator from the policy.
- static generate(env, path, task='walk', mode='all', dataset_type='real', n_models=None, debug=False, **kwargs)[source]
Returns a Humanoid environment corresponding to the specified task.
- Args:
env (class): Humanoid class, either HumanoidTorque4Ages or HumanoidMuscle4Ages. path (str): Path to the dataset. task (str): Main task to solve. Either “walk” or “run”. mode (str): Mode of the environment. Either “all” (sample between all humanoid envs), “1” (smallest humanoid), “2” (second smallest humanoid), “3” (teenage humanoid), and “4” (adult humanoid). dataset_type (str): “real” or “perfect”. “real” uses real motion capture data as the reference trajectory. This data does not perfectly match the kinematics and dynamics of this environment, hence it is more challenging. “perfect” uses a perfect dataset. debug (bool): If True, the smaller test datasets are used for debugging purposes.
- Returns:
An MDP of a set of Torque or Muscle Humanoid of different sizes.
- get_mask(obs_to_hide)[source]
This function returns a boolean mask to hide observations from a fully observable state.
- Args:
- obs_to_hide (tuple): A tuple of strings with names of objects to hide.
Hidable objects are “positions”, “velocities”, “foot_forces”, and “env_type”.
- Returns:
Mask in form of a np.array of booleans. True means that that the obs should be included, and False means that it should be discarded.
- load_trajectory(traj_params, scaling_trajectory_map=None, warn=True)[source]
Loads trajectories. If there were trajectories loaded already, this function overrides the latter.
- Args:
traj_params (dict): Dictionary of parameters needed to load trajectories; scaling_trajectory_map (list): A list that contains tuples of two integers for each scaling. Given a set of trajectories, they define the range of the valid trajectory numbers for each scaling factor. warn (bool): If True, a warning will be raised if scaling_trajectory_map is not set or the trajectory ranges are violated.
- static scale_body(xml_handle, scaling, use_muscles)[source]
This function scales the kinematics and dynamics of the humanoid model given a Mujoco XML handle.
- Args:
xml_handle: Handle to Mujoco XML. scaling (float): Scaling factor.
- Returns:
Modified Mujoco XML handle.
- setup(obs)[source]
Function to setup the initial state of the simulation. Initialization can be done either randomly, from a certain initial, or from the default initial state of the model. If random is chosen, a trajectory is sampled based on the current model.
- Args:
obs (np.array): Observation to initialize the environment from;
- property n_all_models
- class BaseRobotHumanoid(xml_handles, action_spec, observation_spec, collision_groups=None, gamma=0.99, horizon=1000, n_substeps=10, reward_type=None, reward_params=None, traj_params=None, random_start=True, init_step_no=None, timestep=0.001, use_foot_forces=False, default_camera_mode='follow', use_absorbing_states=True, domain_randomization_config=None, parallel_dom_rand=True, N_worker_per_xml_dom_rand=4, **viewer_params)[source]
Bases:
LocoEnvBase Class for the Mujoco simulation of Atlas, UnitreeH1 and Talos.
- create_dataset(ignore_keys=None)[source]
Creates a dataset from the specified trajectories.
- Args:
ignore_keys (list): List of keys to ignore in the dataset. Default is [“q_pelvis_tx”, “q_pelvis_tz”].
- Returns:
Dictionary containing states, next_states and absorbing flags. For the states the shape is (N_traj x N_samples_per_traj, dim_state), while the absorbing flag has the shape is (N_traj x N_samples_per_traj).
- static generate(env, path, task='walk', dataset_type='real', debug=False, clip_trajectory_to_joint_ranges=False, **kwargs)[source]
Returns an environment corresponding to the specified task.
- Args:
env (class): Humanoid class, either HumanoidTorque or HumanoidMuscle. path (str): Path to the dataset. task (str): Main task to solve. Either “walk” or “carry”. The latter is walking while carrying an unknown weight, which makes the task partially observable. dataset_type (str): “real” or “perfect”. “real” uses real motion capture data as the reference trajectory. This data does not perfectly match the kinematics and dynamics of this environment, hence it is more challenging. “perfect” uses a perfect dataset. debug (bool): If True, the smaller test datasets are used for debugging purposes. clip_trajectory_to_joint_ranges (bool): If True, trajectory is clipped to joint ranges.
- Returns:
An MDP of the Robot.
- get_mask(obs_to_hide)[source]
This function returns a boolean mask to hide observations from a fully observable state.
- Args:
obs_to_hide (tuple): A tuple of strings with names of objects to hide. Hidable objects are “positions”, “velocities”, “foot_forces”, and “env_type”.
- Returns:
Mask in form of a np.array of booleans. True means that that the obs should be included, and False means that it should be discarded.