Skip to content

Update Model parsing #2402

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

Merged
merged 45 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
38d62b4
[parser/mjcf] Add rootJointName parameter
Sep 3, 2024
0145df5
[parser/sdf] Add rootJointName parameter
Sep 3, 2024
ad0687d
[parser/urdf] Add rootJointName parameter
Sep 3, 2024
ba8e855
[parser] Add rootJointName in urdfVisitor
Sep 3, 2024
cae3991
[parser] Remove fixed frame root_joint at the base of parsed models
Sep 3, 2024
6b66ed6
[unittest/urdf] Update test to fit new convention
Sep 3, 2024
7a067ac
Update CHANGELOG.md
MegMll Sep 3, 2024
ad79557
[parsers] Added reference
Sep 3, 2024
3299356
[parsers] Move rootJointName argument
Sep 3, 2024
649f83a
[bindings/parsers] Add rootJointName argument to bindings
Sep 3, 2024
596f017
[parser/shortcuts] Fix shortcuts
Sep 4, 2024
de59068
[robot_wrapper] Add root_joint_name argument
Sep 4, 2024
098cf9f
[parsers] Reintroduce old signature to not api
Sep 5, 2024
8cef590
[bindings/parser] reintroduce old signature to not break api
Sep 5, 2024
1b51d06
[bindings/parser] unify naming
Sep 9, 2024
a0df4b1
[unittest/mjcf] unify naming
Sep 9, 2024
d356419
[bindings/parser] Make doc clearer
Sep 9, 2024
35faa8c
[parser] unify naming
Sep 9, 2024
a106a1b
[parsers] Throw errors when no jointRootName is given
Sep 9, 2024
87c1ae4
[python/shortcuts] Modify buildModels to take different sets of argum…
Sep 10, 2024
e685f60
Update Changelog
Sep 10, 2024
81ccabb
[bindings/shortcut] update to accept positionnal arguments
Sep 10, 2024
5bb3af3
[robot_wrapper] update to match shortcuts
Sep 10, 2024
d601a99
[bindings/shortcut] simplify for loop
Sep 11, 2024
f7f0382
[bindings/shortcut] Avoid code duplicate
Sep 11, 2024
82df9fd
Update Changelog
Sep 11, 2024
1adb96c
[bindings/parsers] simplify call
Sep 11, 2024
feccc93
[bindings/shortcut] Simplify logic of code
Sep 11, 2024
5188367
[bindings/parsers] unify naming
Sep 11, 2024
e5917df
[robot_wrapper] Fix argument
Sep 12, 2024
7570a17
[python/shortcuts] Add security
Sep 12, 2024
8bf1cad
[python/shortcuts] Modify sdf shortcut api
Sep 12, 2024
f3d9638
Fix sdf new api
Sep 12, 2024
4086e07
Adding unittest for new api
Sep 12, 2024
27db2a3
python: Add WITH_SDFORMAT flag in Python binding and only run SDF tes…
jorisv Sep 23, 2024
9d2b22c
[parser/mjcf] Add combinatory arguments
Sep 23, 2024
23191bd
[binding/mjcf] Add binding to support constraint and modify shortcut
Sep 23, 2024
5515013
unittest: Normalize q vector to avoid some assertion
jorisv Sep 24, 2024
7edfbc8
sdf: Replace `not and `and` keyword into `!` and `&&`
jorisv Sep 24, 2024
01cbd93
sdf: Replace `and` and `or` by `&&` and `||`
jorisv Sep 24, 2024
8430941
[python/shortcuts] Add empty list in case contact is true and rootJoi…
Sep 24, 2024
60b432b
[parser/mjcf] Re-added every buildModelFromXML
Sep 24, 2024
b4ea965
unittest: Allow 6 failure because of Windows
jorisv Sep 24, 2024
dcf3a15
python: Apply codacy review
jorisv Sep 24, 2024
566d6e5
pre-commit: Apply pre-commit
jorisv Sep 24, 2024
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

- Modernize python code base with ruff ([#2418](https://github.com/stack-of-tasks/pinocchio/pull/2418))

### Changed
- Does not create a root_joint frame from parsed models (urdf, mjcf and sdf) when no root joint is provided ([#2402](https://github.com/stack-of-tasks/pinocchio/pull/2402))

### Added
- Added argument to let users decide of root joint name when parsing models (urdf, mjcf, sdf) ([#2402](https://github.com/stack-of-tasks/pinocchio/pull/2402))

## [3.2.0] - 2024-08-27

### Fixed
Expand Down
18 changes: 18 additions & 0 deletions bindings/python/parsers/mjcf/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ namespace pinocchio
return model;
}

Model buildModelFromMJCF(
const std::string & filename,
const JointModel & root_joint,
const std::string & root_joint_name)
{
Model model;
::pinocchio::mjcf::buildModel(filename, root_joint, root_joint_name, model);
return model;
}

void exposeMJCFModel()
{
bp::def(
Expand All @@ -42,6 +52,14 @@ namespace pinocchio
pinocchio::python::buildModelFromMJCF),
bp::args("mjcf_filename", "root_joint"),
"Parse the MJCF file and return a pinocchio Model with the given root Joint.");

bp::def(
"buildModelFromMJCF",
static_cast<Model (*)(const std::string &, const JointModel &, const std::string &)>(
pinocchio::python::buildModelFromMJCF),
bp::args("mjcf_filename", "root_joint", "root_joint_name"),
"Parse the MJCF file and return a pinocchio Model with the given root Joint and its "
"specified name.");
}
} // namespace python
} // namespace pinocchio
25 changes: 25 additions & 0 deletions bindings/python/parsers/sdf/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@ namespace pinocchio
filename, root_joint, model, contact_models, root_link_name, parent_guidance);
return bp::make_tuple(model, contact_models);
}

bp::tuple buildModelFromSdf(
const std::string & filename,
const JointModel & root_joint,
const std::string & root_link_name,
const std::string & root_joint_name,
const std::vector<std::string> & parent_guidance)
{
Model model;
PINOCCHIO_STD_VECTOR_WITH_EIGEN_ALLOCATOR(RigidConstraintModel) contact_models;
pinocchio::sdf::buildModel(
filename, root_joint, root_joint_name, model, contact_models, root_link_name,
parent_guidance);
return bp::make_tuple(model, contact_models);
}
#endif

void exposeSDFModel()
Expand All @@ -65,6 +80,16 @@ namespace pinocchio
bp::arg("parent_guidance") = bp::list()),
"Parse the SDF file given in input and return a pinocchio Model and constraint "
"models starting with the given root joint.");

bp::def(
"buildModelFromSdf",
static_cast<bp::tuple (*)(
const std::string &, const JointModel &, const std::string &, const std::string &,
const std::vector<std::string> &)>(pinocchio::python::buildModelFromSdf),
(bp::arg("sdf_filename"), bp::arg("root_joint"), bp::arg("root_link_name"),
bp::arg("root_joint_name"), bp::arg("parent_guidance") = bp::list()),
"Parse the SDF file given in input and return a pinocchio Model and constraint "
"models starting with the given root joint and its specified name.");
#endif
}
} // namespace python
Expand Down
91 changes: 83 additions & 8 deletions bindings/python/parsers/urdf/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,36 +38,75 @@ namespace pinocchio
return model;
}

Model buildModelFromUrdf(
const std::string & filename,
const JointModel & root_joint,
const std::string & root_joint_name)
{
Model model;
pinocchio::urdf::buildModel(filename, root_joint, root_joint_name, model);
return model;
}

Model &
buildModelFromUrdf(const std::string & filename, const JointModel & root_joint, Model & model)
{
return pinocchio::urdf::buildModel(filename, root_joint, model);
}

Model buildModelFromXML(const std::string & XMLstream, const JointModel & root_joint)
Model & buildModelFromUrdf(
const std::string & filename,
const JointModel & root_joint,
const std::string & root_joint_name,
Model & model)
{
return pinocchio::urdf::buildModel(filename, root_joint, root_joint_name, model);
}

Model buildModelFromXML(const std::string & xml_stream, const JointModel & root_joint)
{
Model model;
pinocchio::urdf::buildModelFromXML(XMLstream, root_joint, model);
pinocchio::urdf::buildModelFromXML(xml_stream, root_joint, model);
return model;
}

Model buildModelFromXML(
const std::string & xml_stream,
const JointModel & root_joint,
const std::string & root_joint_name)
{
Model model;
pinocchio::urdf::buildModelFromXML(xml_stream, root_joint, root_joint_name, model);
return model;
}

Model &
buildModelFromXML(const std::string & XMLstream, const JointModel & root_joint, Model & model)
buildModelFromXML(const std::string & xml_stream, const JointModel & root_joint, Model & model)
{
pinocchio::urdf::buildModelFromXML(XMLstream, root_joint, model);
pinocchio::urdf::buildModelFromXML(xml_stream, root_joint, model);
return model;
}

Model buildModelFromXML(const std::string & XMLstream)
Model & buildModelFromXML(
const std::string & xml_stream,
const JointModel & root_joint,
const std::string & root_joint_name,
Model & model)
{
pinocchio::urdf::buildModelFromXML(xml_stream, root_joint, root_joint_name, model);
return model;
}

Model buildModelFromXML(const std::string & xml_stream)
{
Model model;
pinocchio::urdf::buildModelFromXML(XMLstream, model);
pinocchio::urdf::buildModelFromXML(xml_stream, model);
return model;
}

Model & buildModelFromXML(const std::string & XMLstream, Model & model)
Model & buildModelFromXML(const std::string & xml_stream, Model & model)
{
pinocchio::urdf::buildModelFromXML(XMLstream, model);
pinocchio::urdf::buildModelFromXML(xml_stream, model);
return model;
}

Expand All @@ -86,6 +125,14 @@ namespace pinocchio
"Parse the URDF file given in input and return a pinocchio Model starting with the "
"given root joint.");

bp::def(
"buildModelFromUrdf",
static_cast<Model (*)(const std::string &, const JointModel &, const std::string &)>(
pinocchio::python::buildModelFromUrdf),
bp::args("urdf_filename", "root_joint", "root_joint_name"),
"Parse the URDF file given in input and return a pinocchio Model starting with the "
"given root joint with its specified name.");

bp::def(
"buildModelFromUrdf",
static_cast<Model (*)(const std::string &)>(pinocchio::python::buildModelFromUrdf),
Expand All @@ -110,6 +157,17 @@ namespace pinocchio
"it is treated as operational frame and not as a joint of the model.",
bp::return_internal_reference<3>());

bp::def(
"buildModelFromUrdf",
static_cast<Model & (*)(const std::string &, const JointModel &, const std::string &,
Model &)>(pinocchio::python::buildModelFromUrdf),
bp::args("urdf_filename", "root_joint", "root_joint_name", "model"),
"Append to a given model a URDF structure given by its filename and the root joint with "
"its specified name.\n"
"Remark: In the URDF format, a joint of type fixed can be defined. For efficiency reasons,"
"it is treated as operational frame and not as a joint of the model.",
bp::return_internal_reference<3>());

bp::def(
"buildModelFromXML",
static_cast<Model (*)(const std::string &, const JointModel &)>(
Expand All @@ -118,6 +176,14 @@ namespace pinocchio
"Parse the URDF XML stream given in input and return a pinocchio Model starting with "
"the given root joint.");

bp::def(
"buildModelFromXML",
static_cast<Model (*)(const std::string &, const JointModel &, const std::string &)>(
pinocchio::python::buildModelFromXML),
bp::args("urdf_xml_stream", "root_joint", "root_joint_name"),
"Parse the URDF XML stream given in input and return a pinocchio Model starting with "
"the given root joint with its specified name.");

bp::def(
"buildModelFromXML",
static_cast<Model & (*)(const std::string &, const JointModel &, Model &)>(
Expand All @@ -127,6 +193,15 @@ namespace pinocchio
"given interfacing joint.",
bp::return_internal_reference<3>());

bp::def(
"buildModelFromXML",
static_cast<Model & (*)(const std::string &, const JointModel &, const std::string &,
Model &)>(pinocchio::python::buildModelFromXML),
bp::args("urdf_xml_stream", "root_joint", "root_joint_name", "model"),
"Parse the URDF XML stream given in input and append it to the input model with the "
"given interfacing joint with its specified name.",
bp::return_internal_reference<3>());

bp::def(
"buildModelFromXML",
static_cast<Model (*)(const std::string &)>(pinocchio::python::buildModelFromXML),
Expand Down
78 changes: 19 additions & 59 deletions bindings/python/pinocchio/robot_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,27 @@
from . import pinocchio_pywrap_default as pin
from . import utils
from .shortcuts import (
buildModelsFromMJCF,
buildModelsFromSdf,
buildModelsFromMJCF,
buildModelsFromUrdf,
createDatas,
)


class RobotWrapper:
@staticmethod
def BuildFromURDF(
filename, package_dirs=None, root_joint=None, verbose=False, meshLoader=None
):
def BuildFromURDF(filename, *args, **kwargs):
robot = RobotWrapper()
robot.initFromURDF(filename, package_dirs, root_joint, verbose, meshLoader)

robot.initFromURDF(filename, *args, **kwargs)

return robot

def initFromURDF(
self,
filename,
package_dirs=None,
root_joint=None,
verbose=False,
meshLoader=None,
):
def initFromURDF(self, filename, *args, **kwargs):
model, collision_model, visual_model = buildModelsFromUrdf(
filename, package_dirs, root_joint, verbose, meshLoader
filename, *args, **kwargs
)

RobotWrapper.__init__(
self,
model=model,
Expand All @@ -40,46 +34,16 @@ def initFromURDF(
)

@staticmethod
def BuildFromSDF(
filename,
package_dirs=None,
root_joint=None,
root_link_name="",
parent_guidance=[],
verbose=False,
meshLoader=None,
):
def BuildFromSDF(filename, *args, **kwargs):
robot = RobotWrapper()
robot.initFromSDF(
filename,
package_dirs,
root_joint,
root_link_name,
parent_guidance,
verbose,
meshLoader,
)
robot.initFromSDF(filename, *args, **kwargs)
return robot

def initFromSDF(
self,
filename,
package_dirs=None,
root_joint=None,
root_link_name="",
parent_guidance=[],
verbose=False,
meshLoader=None,
):
def initFromSDF(self, filename, *args, **kwargs):
model, constraint_models, collision_model, visual_model = buildModelsFromSdf(
filename,
package_dirs,
root_joint,
root_link_name,
parent_guidance,
verbose,
meshLoader,
filename, *args, **kwargs
)

RobotWrapper.__init__(
self,
model=model,
Expand All @@ -89,21 +53,17 @@ def initFromSDF(
self.constraint_models = constraint_models

@staticmethod
def BuildFromMJCF(filename, root_joint=None, verbose=False, meshLoader=None):
def BuildFromMJCF(filename, *args, **kwargs):
robot = RobotWrapper()
robot.initFromMJCF(filename, root_joint, verbose, meshLoader)
robot.initFromMJCF(filename, *args, **kwargs)

return robot

def initFromMJCF(
self,
filename,
root_joint=None,
verbose=False,
meshLoader=None,
):
def initFromMJCF(self, filename, *args, **kwargs):
model, collision_model, visual_model = buildModelsFromMJCF(
filename, root_joint, verbose, meshLoader
filename, *args, **kwargs
)

RobotWrapper.__init__(
self,
model=model,
Expand Down
Loading
Loading