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

[parsing] Slightly improve joint parsing diagnostics #17054

Merged
Merged
Show file tree
Hide file tree
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
40 changes: 37 additions & 3 deletions multibody/parsing/detail_sdf_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,43 @@ void AddJointFromSpecification(
child_body, X_CJ, damping);
break;
}
default: {
throw std::logic_error(
"Joint type not supported for joint '" + joint_spec.Name() + "'.");
case sdf::JointType::CONTINUOUS: {
// TODO(#14747) Use an unlimited multibody::RevoluteJoint here.
diagnostic.Error(fmt::format(
"Joint type (continuous) not supported for joint '{}'.",
joint_spec.Name()));
break;
}
case sdf::JointType::SCREW: {
// TODO(jwnimmer-tri) Use a multibody::ScrewJoint here.
diagnostic.Error(fmt::format(
"Joint type (screw) not supported for joint '{}'.",
joint_spec.Name()));
break;
}
case sdf::JointType::GEARBOX: {
// TODO(jwnimmer-tri) Demote this to a warning, possibly adding a
// RevoluteJoint as an approximation (stopgap) in that case.
diagnostic.Error(fmt::format(
"Joint type (gearbox) not supported for joint '{}'.",
joint_spec.Name()));
break;
}
case sdf::JointType::REVOLUTE2: {
// TODO(jwnimmer-tri) Demote this to a warning, possibly adding a
// UniversalJoint as an approximation (stopgap) in that case.
diagnostic.Error(fmt::format(
"Joint type (revolute2) not supported for joint '{}'.",
joint_spec.Name()));
break;
}
case sdf::JointType::INVALID: {
// N.B. It's not practical to reach this code via unit test.
// In (probably?) all cases, libsdformat will have already detected
// this error and so Drake won't even call this function.
diagnostic.Error(fmt::format(
"Unknown joint type for joint '{}'.", joint_spec.Name()));
break;
}
}
joint_types->insert(joint_spec.Type());
Expand Down
75 changes: 75 additions & 0 deletions multibody/parsing/test/detail_sdf_parser_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,81 @@ TEST_F(SdfParserTest, JointParsingTest) {
EXPECT_TRUE(CompareMatrices(planar_joint2.velocity_upper_limits(), inf3));
}

// Tests the error handling for an unsupported joint type.
TEST_F(SdfParserTest, ContinuousJointParsingTest) {
ParseTestString(R"""(
<model name="molly">
<link name="larry" />
<joint name="jerry" type="continuous">
<parent>world</parent>
<child>larry</child>
</joint>
</model>)""");
EXPECT_THAT(FormatFirstError(), ::testing::MatchesRegex(
".*continuous.*not supported.*jerry.*"));
ClearDiagnostics();
}

// Tests the error handling for an unsupported joint type.
TEST_F(SdfParserTest, ScrewJointParsingTest) {
ParseTestString(R"""(
<model name="molly">
<link name="larry" />
<joint name="jerry" type="screw">
<parent>world</parent>
<child>larry</child>
</joint>
</model>)""");
EXPECT_THAT(FormatFirstError(), ::testing::MatchesRegex(
".*screw.*not supported.*jerry.*"));
ClearDiagnostics();
}

// Tests the error handling for an unsupported joint type.
TEST_F(SdfParserTest, GearboxJointParsingTest) {
ParseTestString(R"""(
<model name="molly">
<link name="larry" />
<joint name="jerry" type="gearbox">
<parent>world</parent>
<child>larry</child>
</joint>
</model>)""");
EXPECT_THAT(FormatFirstError(), ::testing::MatchesRegex(
".*gearbox.*not supported.*jerry.*"));
ClearDiagnostics();
}

// Tests the error handling for an unsupported joint type.
TEST_F(SdfParserTest, Revolute2JointParsingTest) {
ParseTestString(R"""(
<model name="molly">
<link name="larry" />
<joint name="jerry" type="revolute2">
<parent>world</parent>
<child>larry</child>
</joint>
</model>)""");
EXPECT_THAT(FormatFirstError(), ::testing::MatchesRegex(
".*revolute2.*not supported.*jerry.*"));
ClearDiagnostics();
}

// Tests the error handling for a misspelled joint type.
TEST_F(SdfParserTest, MisspelledJointParsingTest) {
ParseTestString(R"""(
<model name="molly">
<link name="larry" />
<joint name="jerry" type="revoluteQQQ">
<parent>world</parent>
<child>larry</child>
</joint>
</model>)""");
EXPECT_THAT(FormatFirstError(), ::testing::MatchesRegex(
".*revoluteqqq is invalid.*"));
ClearDiagnostics();
}

// Verifies that the SDF parser parses the joint actuator limit correctly.
TEST_F(SdfParserTest, JointActuatorParsingTest) {
const std::string full_name = FindResourceOrThrow(
Expand Down