Skip to content

RSDK-14756: Gripper kinematic model, model file loader and joint limits narrowing - #739

Open
JohnN193 wants to merge 8 commits into
mainfrom
RSDK-14756-gripper-kinematics
Open

JohnN193 wants to merge 8 commits into
mainfrom
RSDK-14756-gripper-kinematics

Conversation

@JohnN193

@JohnN193 JohnN193 commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Part of the typed GetKinematics work (RSDK-14232). This fills in what the C++ SDK was still missing after #731.

What changed

Gripper GetKinematics

  • Gripper::get_kinematic_model, with client and server support.
  • It is not pure virtual, unlike arm and gantry, so existing gripper modules keep compiling. A gripper that does not override it throws k_not_supported, which the server answers as gRPC UNIMPLEMENTED. That is what viam-server already sees from C++ grippers and what it falls back to geometries on.

Kinematic model file loader

  • KinematicModel::from_file reads the proto JSON of a KinematicModel.
  • The parse is strict and makes the same checks and mesh reads as rdk's ReadKinematicModelFile: unknown fields, non finite numbers, ids, parents, cycles, mimic joints, mesh paths and content types.

Shared fixtures

  • The rdk fixtures (referenceframe/testfiles/kinematic_models) are not checked in. When tests are configured, CMake fetches that one directory from rdk at a pinned commit (cefbb7080) into the build tree.
  • A failed fetch warns and leaves the fixture test failing with the reason, so a build without the network still configures. VIAMCPPSDK_KINEMATIC_MODEL_FIXTURES_DIR points the test at an rdk checkout instead.
  • test_kinematic_model.cpp runs all 32 cases and compares messages, not text.
  • For unknown_field and malformed_json the runner only checks that the parse failed and the mentions, since that wording is protobuf's and differs between versions.

Joint limits

  • KinematicModel::narrow_joint_limits follows rdk's NarrowJointLimits. A requested value can only narrow what the model holds.
  • There is no helper to read the limits out of a resource config, since a module is free to shape its attributes however it likes.

Mesh bytes

  • KinematicModel::drop_unrequested_mesh_bytes is for a module that holds its model with every mesh loaded. With either include flag set it clears the bytes of the role that was not asked for. With neither set it leaves the model whole, as rdk does for clients that predate the flags.
  • The servers do not strip anything themselves, that stays with the module.

Breaking change: KinematicModel is a class

  • KinematicModel was a struct with public fields. It is now a class, built with KinematicModel(name, links, joints, output_frames, properties) or KinematicModel::from_file.
  • The constructor makes the same tree checks as the file loader and throws naming the link or joint at fault: ids present, not world and not reused, parents that exist, no cycles, and mimic joints that name another joint and carry no limits of their own.
  • A model received over the wire (from_proto) skips the checks, so a client can hold whatever a server sent.
  • Fields are read through name(), links(), joints(), output_frames() and properties(), and changed only through set_name, narrow_joint_limits and drop_unrequested_mesh_bytes.
  • Code that filled model.links = ... has to move to the constructor. The arm mock had a mimic joint with limits, which is now refused, so its mimic moved to the joint without any.

Behaviour change for arm and gantry

The arm, gantry and gripper servers now always set the served model's name to the resource name, as rdk does. Before, arm and gantry only did so when the name was empty. A model read from a file always carries a name, so the old rule would have served the file's name.

Not in this PR

  • The servers still fill the deprecated bytes fields only when a module overrides the old get_kinematics. Filling them from the model needs a model to SVA writer.
  • ModelTable from a KinematicModel (RSDK-14033).
  • A kinematic model file writer.

After #732

Main moved to C++20 under this PR. The merge of main here moves the new code onto std::optional, std::variant, std::visit and std::get_if, which #732 chose for kinematics.hpp, and drops the hand written operator== set in favour of the defaulted ones. Built and tested at gnu20 with conan after the merge, the four test binaries pass, 62 cases.

Testing

  • test_kinematic_model, test_gripper, test_arm and test_gantry pass locally.
  • The rest of the suite was not built or run locally, and clang-tidy was run with version 18, not CI's 16.
  • Not yet tried against a real viam-server with a Go client.

🤖 Generated with Claude Code

…ts helper

Add get_kinematic_model to Gripper with its client and server. The method
is not pure virtual so existing gripper modules keep compiling, and a
gripper that does not override it answers UNIMPLEMENTED, which is what
viam-server falls back to geometries on.

Add read_kinematic_model_file, a strict proto JSON reader for kinematic
model files that makes the same checks and mesh reads as rdk's
ReadKinematicModelFile, with a pinned copy of the rdk fixtures and a
runner for them.

Add narrow_joint_limits and joint_limits_from_attribute, following rdk's
NarrowJointLimits, and drop_unrequested_mesh_bytes for a module that
holds its model with every mesh loaded.

The arm, gantry and gripper servers now always name the served model for
the resource, as rdk does, instead of only when the name is empty.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@JohnN193
JohnN193 requested a review from a team as a code owner November 12, 2026 20:43
@JohnN193
JohnN193 requested review from martha-johnston and Naveed Jooma (njooma) and removed request for a team November 12, 2026 20:43
A module is free to shape its config attributes however it likes, so the
SDK should not assume the joint_limits layout. A module builds the map
narrow_joint_limits takes from its own config.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@JohnN193 JohnN193 changed the title RSDK-14756: Gripper kinematic model, model file loader and joint limits helper RSDK-14756: Gripper kinematic model, model file loader and joint limits narrowing Nov 12, 2026
Called with a std::string, an unqualified quoted also finds std::quoted
through argument dependent lookup wherever <iomanip> has been pulled in.
On CI's toolchain that overload won for a non const string and the
concatenation failed to compile.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
JohnN193 and others added 3 commits November 13, 2026 01:17
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
FieldDescriptor::name returns a string view from protobuf 26 on, which
cannot be added to a std::string. The Windows build uses such a version.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Main took C++20 in #732, which swapped boost optional and variant for
std::optional and std::variant in kinematics.hpp and defaulted the
comparison operators. The gripper, loader and limits code written
against boost follows: std::optional, std::nullopt, std::visit and
std::get_if, with the hand written operator== set dropped in favour of
the defaulted ones. Built and tested at gnu20 with conan, the four
kinematics test binaries pass.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Comment thread src/viam/sdk/tests/CMakeLists.txt Outdated
VIAMCPPSDK_TEST_TESTFILES_DIR="${CMAKE_CURRENT_SOURCE_DIR}/testfiles"
)

# The fixture cases are a copy of rdk's referenceframe/testfiles/kinematic_models. The test gets

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't like having to check in all the rdk's test files, my first question is if there's a need for us to test this stuff on our side, but if so i think it makes more sense to do some cmake scripting to grab the test directory from a specified commit and download it into the binary directory.

also we are not on c++14, std::filesystem is available

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set it up so we pull in the test files

Comment thread src/viam/sdk/common/kinematics.hpp Outdated
/// stands. A continuous joint given a min or a max becomes a revolute joint with that bound. A
/// mimic joint follows the joint it mimics and cannot be narrowed.
///
/// @param model The model to narrow in place. It is left untouched when this throws.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this kinda looks like it should be a method on a KinematicModel rather than a free function. in hindsight maybe KinematicModel should have been class rather than struct, or a struct with a bunch of methods if we don't want it to be a breaking change. although the type is new enough that i don't think it's a huge deal for it to be a breaking change

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

went ahead and switched to a class then

Comment thread src/viam/sdk/common/kinematics.hpp Outdated
/// type and loses its bytes. The geometry of a prismatic joint counts as a collision mesh. With
/// neither flag set the model is left whole, since such a request may come from a viam-server
/// that predates the flags and expects every mesh with its bytes.
void drop_unrequested_mesh_bytes(KinematicModel& model, const kinematics_options& options);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similarly this smells like a method

/// resource name when the model is served.
///
/// @throws Exception naming the file and the link, joint or mesh at fault.
KinematicModel read_kinematic_model_file(const std::string& path);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like it would make more sense as a named constructor

}

// the directory part of a path, empty when the file sits in the working directory
std::string directory_of(const std::string& path) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be done with std::filesystem

}

// the extension of the last element of a forward slash path, lowercased and without the dot
std::string extension_of(const std::string& source) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this too

JohnN193 and others added 2 commits November 20, 2026 13:53
…ures

The loader, the limits narrowing and the mesh bytes helper become
KinematicModel::from_file, narrow_joint_limits and
drop_unrequested_mesh_bytes, so kinematic_model_file.hpp is gone. The
loader takes a std::filesystem::path and uses it for the model's
directory and for mesh extensions.

The rdk fixtures are no longer checked in. CMake fetches the one
directory from rdk at a pinned commit into the build tree when tests
are configured, and the test walks it with std::filesystem. A failed
fetch warns and leaves the fixture test failing with the reason, so a
build without the network still configures.
VIAMCPPSDK_KINEMATIC_MODEL_FIXTURES_DIR points the test at an rdk
checkout instead.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
KinematicModel was a struct anyone could fill with a tree that does not
hold together, and only a model read from a file was checked. It is now
a class built through a constructor that makes the same checks as the
file loader: ids present, not "world" and not reused, parents that
exist, no cycles, and mimic joints that name another joint and carry no
limits of their own. The checks live in one function that both the
constructor and the loader call.

A model received over the wire skips the checks, since a client has to
be able to hold whatever a server sent it. The fields are read through
accessors, and changed through set_name, narrow_joint_limits and
drop_unrequested_mesh_bytes, none of which can break the tree.

The arm mock had a mimic joint with limits, which the constructor now
refuses, so the mimic moves to the joint without any.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants