Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new JaxSim.insert_model_from_description #31

Merged
merged 1 commit into from
May 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 32 additions & 11 deletions src/jaxsim/simulation/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import jaxsim.physics
import jaxsim.simulation.simulator_callbacks as scb
import jaxsim.typing as jtp
from jaxsim import logging
from jaxsim.high_level.common import VelRepr
from jaxsim.high_level.model import Model, StepData
from jaxsim.physics.algos.soft_contacts import SoftContactsParams
Expand Down Expand Up @@ -218,29 +219,28 @@ def set_gravity(self, gravity: jtp.Vector) -> None:

self._set_mutability(self._mutability())

def insert_model_from_sdf(
def insert_model_from_description(
self,
sdf: Union[pathlib.Path, str],
model_name: str = None,
considered_joints: List[str] = None,
model_description: Union[pathlib.Path, str],
model_name: Optional[str] = None,
considered_joints: Optional[List[str]] = None,
) -> Model:
"""
Insert a model from an SDF resource.
Insert a model from a model description.

Args:
sdf: The SDF resource.
model_name: Optional name of the model to insert.
It defaults to the name of the model found in the SDF resource.
model_description: Either a path to a file or a string containing the URDF/SDF description.
model_name: The optional name of the model that overrides the one in the description.
considered_joints: Optional list of joints to consider.
It is also useful to specify the joint serialization.

Returns:
The newly inserted model.
"""

# Build the model from the input SDF resource
model = jaxsim.high_level.model.Model.build_from_sdf(
sdf=sdf,
# Build the model from the given model description
model = jaxsim.high_level.model.Model.build_from_model_description(
model_description=model_description,
model_name=model_name,
vel_repr=self.velocity_representation,
considered_joints=considered_joints,
Expand All @@ -261,6 +261,27 @@ def insert_model_from_sdf(
# Return the newly inserted model
return self.data.models[model.name()]

def insert_model_from_sdf(
self,
sdf: Union[pathlib.Path, str],
model_name: str = None,
considered_joints: List[str] = None,
) -> Model:
"""
Insert a model from an SDF resource.
"""

msg = "JaxSim.{} is deprecated, use JaxSim.{} instead."
logging.warning(
msg=msg.format("insert_model_from_sdf", "insert_model_from_description")
)

return self.insert_model_from_description(
model_description=sdf,
model_name=model_name,
considered_joints=considered_joints,
)

def insert_model(
self, model_description: descriptions.ModelDescription, model_name: str = None
) -> Model:
Expand Down
Loading