Skip to content

Commit

Permalink
Changes for PEP 8
Browse files Browse the repository at this point in the history
  • Loading branch information
20chupin committed Apr 11, 2024
1 parent d6f1205 commit 7be8b1f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 26 deletions.
23 changes: 14 additions & 9 deletions python/jiminy_py/src/jiminy_py/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def build_robot_from_log(
"""Create and initialize a robot from a single or
multi robot simulation. If the robot to be built is from a multi-robot
simulation, its name needs to be provided.
.. note::
model options and `robot.pinocchio_model` will be the same as during
the simulation until the next call to `reset` method unless the options
Expand All @@ -146,7 +146,7 @@ def build_robot_from_log(
directories to the ones provided by log file. It
may be necessary to specify it to read log
generated on a different environment.
:param robot_name: Name of the robot to be constructed in the log. If it
:param robot_name: Name of the robot to be constructed in the log. If it
is not known, call `build_robots_from_log`.
:returns: Reconstructed robot, and parsed log data as returned by
Expand Down Expand Up @@ -233,6 +233,7 @@ def build_robot_from_log(

return robot


def build_robots_from_log(
log_data: Dict[str, Any],
mesh_path_dir: Optional[str] = None,
Expand All @@ -241,7 +242,7 @@ def build_robots_from_log(
"""Build all the robots in the log of the simulation.
.. note::
This function calls `build_robot_from_log` to build each robot.
This function calls `build_robot_from_log` to build each robot.
Refer to `build_robot_from_log` for more information.
:param log_data: Logged data (constants and variables) as a dictionary.
Expand Down Expand Up @@ -294,7 +295,7 @@ def extract_trajectory_from_log(log_data: Dict[str, Any],
:param robot: Jiminy robot associated with the logged trajectory.
Optional: None by default. If None, then it will be
reconstructed from 'log_data' using `build_robot_from_log`.
:param robot_name: Name of the robot to be constructed in the log. If it
:param robot_name: Name of the robot to be constructed in the log. If it
is not known, call `build_robot_from_log`.
:returns: Trajectory dictionary. The actual trajectory corresponds to the
Expand Down Expand Up @@ -352,11 +353,13 @@ def extract_trajectory_from_log(log_data: Dict[str, Any],

return {"evolution_robot": evolution_robot,
"robot": robot,
"use_theoretical_model": False}
"use_theoretical_model": False}


def extract_trajectories_from_log(log_data: Dict[str, Any],
robots: Optional[Sequence[jiminy.Model]] = None
) -> Dict[str, TrajectoryDataType]:
def extract_trajectories_from_log(
log_data: Dict[str, Any],
robots: Optional[Sequence[jiminy.Model]] = None
) -> Dict[str, TrajectoryDataType]:
"""Extract the minimal required information from raw log data in order to
replay the simulation in a viewer.
Expand All @@ -371,7 +374,8 @@ def extract_trajectories_from_log(log_data: Dict[str, Any],
Optional: None by default. If None, then it will be
reconstructed from 'log_data' using `build_robots_from_log`.
:returns: Dictonary mapping each robot name to its corresponding trajectory.
:returns: Dictonary mapping each robot name to its corresponding
trajectory.
"""
trajectories = {}

Expand All @@ -386,6 +390,7 @@ def extract_trajectories_from_log(log_data: Dict[str, Any],
trajectories[robot.name] = trajectory
return trajectories


def update_sensor_measurements_from_log(
log_data: Dict[str, Any],
robot: jiminy.Model
Expand Down
2 changes: 1 addition & 1 deletion python/jiminy_py/src/jiminy_py/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ class BaseJiminyRobot(jiminy.Robot):
:param name: Name of the robot to be created.
Optional: Empty string by default.
"""
def __init__(self, name : Optional[str] = "") -> None:
def __init__(self, name: Optional[str] = "") -> None:
self.extra_info: Dict[str, Any] = {}
self.hardware_path: Optional[str] = None
self._urdf_path_orig: Optional[str] = None
Expand Down
37 changes: 21 additions & 16 deletions python/jiminy_py/src/jiminy_py/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def _build_robot_from_urdf(name: str,
# Check if robot name is valid
if name != re.sub('[^A-Za-z0-9_]', '_', name):
raise ValueError("The name of the robot should be case-insensitive "
"ASCII alphanumeric characters plus underscore.")
"ASCII alphanumeric characters plus underscore.")

# Generate a temporary Hardware Description File if necessary
if hardware_path is None:
Expand Down Expand Up @@ -128,6 +128,7 @@ def remove_file_at_exit(file_path: str) -> None:

return robot


class Simulator:
"""Simulation wrapper providing a unified user-API on top of the low-level
jiminy C++ core library and Python-native modules for 3D rendering and log
Expand Down Expand Up @@ -183,7 +184,7 @@ def __init__(self, # pylint: disable=unused-argument
# Check if robot name is valid
if robot.name != re.sub('[^A-Za-z0-9_]', '_', robot.name):
raise ValueError("The name of the robot should be case-insensitive"
" ASCII alphanumeric characters plus underscore.")
" ASCII alphanumeric characters plus underscore.")

# Instantiate the low-level Jiminy engine, then initialize it
self.engine = jiminy.Engine()
Expand Down Expand Up @@ -214,7 +215,7 @@ def build(cls,
config_path: Optional[str] = None,
avoid_instable_collisions: bool = True,
debug: bool = False,
name : str = "",
name: str = "",
**kwargs: Any) -> 'Simulator':
r"""Create a new simulator instance from scratch, based on
configuration files only.
Expand Down Expand Up @@ -328,20 +329,22 @@ def add_robot(self,
# Get engine options
engine_options = self.engine.get_options()

for extra_info_key, option_nested_path in (
nested_paths = (
('groundStiffness', ('contacts', 'stiffness')),
('groundDamping', ('contacts', 'damping')),
('controllerUpdatePeriod', ('stepper', 'controllerUpdatePeriod')),
('sensorsUpdatePeriod', ('stepper', 'sensorsUpdatePeriod'))):
('sensorsUpdatePeriod', ('stepper', 'sensorsUpdatePeriod')))

for extra_info_key, option_nested_path in nested_paths:
if extra_info_key in robot.extra_info.keys():
option = engine_options
for option_path in option_nested_path:
option = option[option_path]
if robot.extra_info[extra_info_key] != option:
warnings.warn(
f"You have speficied a different {extra_info_key} then "
f"the one of the engine, the simulation will run with "
f"{option}.")
f"You have speficied a different {extra_info_key} then"
f" the one of the engine, the simulation will run with"
f" {option}.")

# Add the new robot to the engine
self.engine.add_robot(robot)
Expand Down Expand Up @@ -467,7 +470,7 @@ def robot(self) -> jiminy.Robot:
@property
def robot_state(self) -> jiminy.RobotState:
"""Convenience proxy to get the state of the robot in single-robot
simulations.
simulations.
Internally, all it does is returning `self.engine.robot_states[0]`
without any additional processing.
Expand All @@ -482,7 +485,7 @@ def robot_state(self) -> jiminy.RobotState:

@property
def is_viewer_available(self) -> bool:
"""Returns whether a viewer instance associated with the ongoing
"""Returns whether a viewer instance associated with the ongoing
single-robot simulation.
.. warning::
Expand Down Expand Up @@ -606,11 +609,13 @@ def reset(self, remove_all_forces: bool = False) -> None:
# Reset the backend engine
self.engine.reset(False, remove_all_forces)

def start(self,
q_init: Union[np.ndarray, Dict[str, np.ndarray]],
v_init: Union[np.ndarray, Dict[str, np.ndarray]],
a_init: Optional[Union[np.ndarray, Dict[str, np.ndarray]]] = None,
is_state_theoretical: Optional[bool] = None) -> None:
def start(
self,
q_init: Union[np.ndarray, Dict[str, np.ndarray]],
v_init: Union[np.ndarray, Dict[str, np.ndarray]],
a_init: Optional[Union[np.ndarray, Dict[str, np.ndarray]]] = None,
is_state_theoretical: Optional[bool] = None
) -> None:
"""Initialize a simulation, starting from (q_init, v_init) at t=0.
:param q_init: Initial configuration (by robot if it is a dictionnary).
Expand Down Expand Up @@ -819,7 +824,7 @@ def render(self,
colors = ROBOTS_COLORS * (len(self.robots) // len(ROBOTS_COLORS) + 1)

for robot, robot_state, color in zip(
self.robots, self.engine.robot_states, colors):
self.robots, self.engine.robot_states, colors):

# Create new viewer instance if needed or use the existing one.
if robot.name not in Viewer._backend_robot_names:
Expand Down

0 comments on commit 7be8b1f

Please sign in to comment.