Skip to content

Commit

Permalink
[mjcf] replace with throw pretty
Browse files Browse the repository at this point in the history
  • Loading branch information
Megane Millan committed Jan 7, 2025
1 parent cf3a416 commit df04cf2
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions src/parsers/mjcf/mjcf-graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ namespace pinocchio
else
{
if (filePath.extension().empty())
throw std::invalid_argument("Cannot find extension for one of the mesh/texture");
PINOCCHIO_THROW_PRETTY(std::invalid_argument, "Cannot find extension for one of the mesh/texture");

auto st = filePath.stem();
if (!st.empty())
return st.string();
else
throw std::invalid_argument("Cannot find a name for one of the mesh.texture");
PINOCCHIO_THROW_PRETTY(std::invalid_argument, "Cannot find a name for one of the mesh.texture");
}
}

Expand Down Expand Up @@ -172,7 +172,7 @@ namespace pinocchio
{

if (!use_limits && el.get_optional<std::string>("<xmlattr>.range"))
throw std::invalid_argument("Range limit is specified but it was not specify to use it.");
PINOCCHIO_THROW_PRETTY(std::invalid_argument, "Range limit is specified but it was not specify to use it.");

// Type
auto type_s = el.get_optional<std::string>("<xmlattr>.type");
Expand Down Expand Up @@ -227,7 +227,7 @@ namespace pinocchio
else if (jointType == "hinge")
posRef = currentCompiler.convertAngle(*value);
else
throw std::invalid_argument(
PINOCCHIO_THROW_PRETTY(std::invalid_argument,
"Reference position can only be used with hinge or slide joints.");
}
}
Expand Down Expand Up @@ -358,7 +358,7 @@ namespace pinocchio
double mass = std::max(el.get<double>("<xmlattr>.mass"), compilerInfo.boundMass);
;
if (mass < 0)
throw std::invalid_argument("Mass of body is not supposed to be negative");
PINOCCHIO_THROW_PRETTY(std::invalid_argument, "Mass of body is not supposed to be negative");

Inertia::Vector3 com;
auto com_s = el.get_optional<std::string>("<xmlattr>.pos");
Expand Down Expand Up @@ -410,7 +410,7 @@ namespace pinocchio
auto chcl_s = childClass;
// if inertiafromgeom is false and inertia does not exist - throw
if (!compilerInfo.inertiafromgeom && !el.get_child_optional("inertial"))
throw std::invalid_argument("Cannot get inertia from geom and no inertia was found");
PINOCCHIO_THROW_PRETTY(std::invalid_argument, "Cannot get inertia from geom and no inertia was found");

bool usegeominertia = false;
if (compilerInfo.inertiafromgeom)
Expand Down Expand Up @@ -524,7 +524,7 @@ namespace pinocchio
{
std::cout << "Warning - Only texture with files are supported" << std::endl;
if (name.empty())
throw std::invalid_argument("Textures need a name.");
PINOCCHIO_THROW_PRETTY(std::invalid_argument, "Textures need a name.");
}
else
{
Expand Down Expand Up @@ -553,7 +553,7 @@ namespace pinocchio
if (n)
name = *n;
else
throw std::invalid_argument("Material was given without a name");
PINOCCHIO_THROW_PRETTY(std::invalid_argument, "Material was given without a name");

// default < Class < Attributes
if (mapOfClasses.find("mujoco_default") != mapOfClasses.end())
Expand Down Expand Up @@ -644,7 +644,7 @@ namespace pinocchio
parseTexture(v.second);

if (v.first == "hfield")
throw std::invalid_argument("hfields are not supported yet");
PINOCCHIO_THROW_PRETTY(std::invalid_argument, "hfields are not supported yet");
}
}

Expand All @@ -666,7 +666,7 @@ namespace pinocchio
mapOfClasses.insert(std::make_pair(*nameClass, classDefault));
}
else
throw std::invalid_argument("Class does not have a name. Cannot parse model.");
PINOCCHIO_THROW_PRETTY(std::invalid_argument, "Class does not have a name. Cannot parse model.");
}
else if (v.first == "default")
parseDefault(v.second, el, v.first);
Expand Down Expand Up @@ -735,8 +735,10 @@ namespace pinocchio
{
std::string eulerseq = *eulerS;
if (eulerseq.find_first_not_of("xyzXYZ") != std::string::npos || eulerseq.size() != 3)
throw std::invalid_argument(
{
PINOCCHIO_THROW_PRETTY(std::invalid_argument,
"Model tried to use euler angles but euler sequence is wrong");
}
else
{
// get index combination
Expand Down Expand Up @@ -764,7 +766,7 @@ namespace pinocchio
compilerInfo.mapEulerAngles.col(ci) = Eigen::Vector3d::UnitZ();
break;
default:
throw std::invalid_argument("Euler Axis does not exist");
PINOCCHIO_THROW_PRETTY(std::invalid_argument, "Euler Axis does not exist");
break;
}
}
Expand Down Expand Up @@ -817,7 +819,7 @@ namespace pinocchio
if (body1)
eq.body1 = *body1;
else
throw std::invalid_argument("Equality constraint needs a first body");
PINOCCHIO_THROW_PRETTY(std::invalid_argument, "Equality constraint needs a first body");

// get the name of second body
auto body2 = v.second.get_optional<std::string>("<xmlattr>.body2");
Expand Down Expand Up @@ -846,7 +848,7 @@ namespace pinocchio
if (pt.get_child_optional("mujoco"))
el = pt.get_child("mujoco");
else
throw std::invalid_argument("This is not a standard mujoco model. Cannot parse it.");
PINOCCHIO_THROW_PRETTY(std::invalid_argument, "This is not a standard mujoco model. Cannot parse it.");

for (const ptree::value_type & v : el)
{
Expand All @@ -857,7 +859,7 @@ namespace pinocchio
if (n_s)
modelName = *n_s;
else
throw std::invalid_argument("Model is missing a name. Cannot parse it");
PINOCCHIO_THROW_PRETTY(std::invalid_argument, "Model is missing a name. Cannot parse it");
}

if (v.first == "compiler")
Expand Down Expand Up @@ -945,7 +947,7 @@ namespace pinocchio
jType = UrdfVisitor::REVOLUTE;
}
else
throw std::invalid_argument("Unknown joint type");
PINOCCHIO_THROW_PRETTY(std::invalid_argument, "Unknown joint type");

urdfVisitor.addJointAndBody(
jType, joint.axis, parentFrameId, jointInParent, joint.jointName, inert, bodyInJoint,
Expand Down Expand Up @@ -1017,7 +1019,7 @@ namespace pinocchio
for (const auto & joint : currentBody.jointChildren)
{
if (joint.jointType == "free")
throw std::invalid_argument("Joint Composite trying to be created with a freeFlyer");
PINOCCHIO_THROW_PRETTY(std::invalid_argument, "Joint Composite trying to be created with a freeFlyer");

SE3 jointInParent = bodyPose * joint.jointPlacement;
bodyInJoint = joint.jointPlacement.inverse();
Expand Down Expand Up @@ -1052,7 +1054,7 @@ namespace pinocchio
rangeCompo = rangeCompo.concatenate<1, 1>(joint.range);
}
else
throw std::invalid_argument("Unknown joint type trying to be parsed.");
PINOCCHIO_THROW_PRETTY(std::invalid_argument, "Unknown joint type trying to be parsed.");

prevJointPlacement = jointInParent;
}
Expand Down Expand Up @@ -1152,7 +1154,7 @@ namespace pinocchio
urdfVisitor.model.referenceConfigurations.insert(std::make_pair(keyName, qpos));
}
else
throw std::invalid_argument("Keyframe size does not match model size");
PINOCCHIO_THROW_PRETTY(std::invalid_argument, "Keyframe size does not match model size");
}

void MjcfGraph::parseContactInformation(
Expand Down Expand Up @@ -1189,7 +1191,7 @@ namespace pinocchio
void MjcfGraph::parseRootTree()
{
urdfVisitor.setName(modelName);

// get name and inertia of first root link
std::string rootLinkName = bodiesList.at(0);
MjcfBody rootBody = mapOfBodies.find(rootLinkName)->second;
Expand Down

0 comments on commit df04cf2

Please sign in to comment.