-
Notifications
You must be signed in to change notification settings - Fork 519
Adding a spline joint to the joint collection #2784
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
Open
MegMll
wants to merge
84
commits into
stack-of-tasks:devel
Choose a base branch
from
MegMll:topic/spline_joint
base: devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
84 commits
Select commit
Hold shift + click to select a range
8c75f2f
Joints - Add a first implementation of joint spline
MegMll 5d84f40
Unittest - Add TU for spline joint
MegMll 534afde
Bindings - add bindings for spline joint
MegMll 928cee7
Spatial - Weird fix to make spline joint work for now (to remove)
MegMll 53f14a2
Unittest - update joint unittests to include spline joints
MegMll 2c047ed
SplineJoint - apply pre-commit
MegMll d45b129
Spline - use the true cumulative form of the spline
MegMll c775bc7
Spline - Add isEqual Method
MegMll e3bb968
Spline - Add TU with finite difference
MegMll f842642
Unittest - fix tests for spline joint
MegMll dde3ca7
Spline joint - change if/else to be casadi compatible
MegMll 46962a8
Joint Spline - Remove useless comments
MegMll 110e9cb
Joint Spline - Fix indexing
MegMll 6a0edea
Joint Spline - Eigen No Malloc checked and passed
MegMll 8aa58f2
Spline joints - fix casadi joints tests
MegMll 53d4ba1
Joint Spline - Add a build method
MegMll d3726d0
Unittest - Fix joint spline's unittests
MegMll 4612a28
Model-graph - Add spline joint to model graph
MegMll d8d9c86
JointSpline - make some correction to the joint
MegMll 4a6d905
TU - apply new jointSpline constructor
MegMll 365e615
ModelGraph - use new JointSpline method
MegMll 88387be
Serialization - Add attributes from spline model and data
MegMll 434e654
Unittest - use std vector instead of se3
MegMll 6704dd2
JointSpline - Diverse Changes
MegMll 25a7696
Casadi - Add a separated file for findSpan to be able to do specializ…
MegMll f00b562
Bindings - modify joint spline binding
MegMll 0c32dfb
JointSpline - Remove findSpan
MegMll b85d202
Unittest - remove buildJoint function
MegMll 2875940
ModelGraph - finish adding jointSpline to model graph + unittest
MegMll c6d110a
cppadcg: Fix cppadcg cast test with spline joint
jorisv 76b9368
multiprecision: Fix multiprecision cast test with Spline joint
jorisv e567234
multiprecision: Add missing header
jorisv 259343a
lint: Run linter
jorisv f6287fb
JointSpline - Removed comments
MegMll 7e5c230
JointSpline - move bspline functions in public to be able to test it
MegMll c6e7970
Unittest - add more test for joint spline
MegMll 689565c
Bindings - Add another constructor for joint spline
MegMll 9b0108e
Unittest - put full knee trajectory
MegMll 31f831f
Unittest - try a fix for windows and serialization
MegMll a37889d
Unittest - fix getTrajectory function
MegMll 30dd38e
Bindings - add modelgraph bindings constant
MegMll 3108bff
JointSpline - Fix indexing
MegMll f49a734
JointSpline - Add a doc
MegMll e0c96bb
JointSpline - Fix bias computation
MegMll f6234b1
Unittest - add a finite difference test for S and bias c for JointSpline
MegMll a741434
JointSpline - Add comments and complete isEqual function
MegMll 98d4af5
Unittest - Try to add tolerance to see if it fixes macos-intel problem
MegMll d0f6a3f
Unittest - fix compilation error
MegMll 9b3443e
JointSpline - add assert for configuration to be between 0 and 1
MegMll c93d6a4
Bindings - Add graph spline joints bindings
MegMll 5d3342d
Algo/Splines - remove comments
MegMll 5cc06ef
Unittest - add find span test for q = 0
MegMll 57f553b
Changelog - update
MegMll 395d570
JointSpline - remove SE3 and use Transformation_t
MegMll 7f56fc1
Unittest - remove comments
MegMll c9f97ff
JointSpline - Use transformation_t and motion_t
MegMll ecc4600
Examples - Add a small examples on what the spline joint can do
MegMll 64b8634
Unittest - Specialize for joint spline
MegMll 145f33d
Examples - add spline joint examples
MegMll a07d7a9
Unittest - Fix joint generic test for joint spline
MegMll f20c196
Examples - Fix some linting errors
MegMll d6798ea
JointSpline - Disable assert
MegMll 557533b
core: Apply small changes
jorisv 6949b41
Algo/splines - add doc
MegMll 9c9b14b
Unittest - Avoid code duplication for randomConfig vector generation
MegMll c1168e4
Unittest - more complex and complete tests
MegMll 12c4b61
Unittest/cppad - use degree 3 spline joint
MegMll e009789
unittest - change name of struct to be more generic
MegMll 8741199
unittest - avoid code duplication
MegMll c110d73
unittest - avoid code duplication
MegMll 6b44312
Unittest - fix casadi/joints test
MegMll 9216634
Unittest - add forgotten helical unaligned joint
MegMll 0932ef5
Unittest - Fix casadi test for universal joints
MegMll 678005b
Mode-graph - use new function for joint spline
MegMll 2b36568
Linting
MegMll 3d6bdd6
unittest - fix new joint
MegMll 18cda3f
JointSpline - Fix bias computation
MegMll 5b6839e
Unittest - Fix finite-difference test
MegMll 078eab8
unittest - use config vector of joints
MegMll 852c605
unittest - remove useless lines
MegMll a522d82
Unittest - Add a utils file to centralize init of joints with parameters
MegMll 004af4a
Run pre-commit
MegMll c38e0fc
unittest/utils - Fix mimic init
MegMll 00bc40a
unittest/serialization - use new utils
MegMll File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import time | ||
|
|
||
| import hppfcl | ||
| import numpy as np | ||
| import pinocchio as pin | ||
| from pinocchio.visualize import MeshcatVisualizer | ||
|
|
||
|
|
||
| def generate_random_se3_trajectory(num_steps, radius, num_revolutions, height): | ||
| """ | ||
| Generates a random trajectory in SE(3) with rotating orientation. | ||
|
|
||
| Args: | ||
| num_keyframes: The number of random keyframes to generate. | ||
| num_steps_per_segment: The number of intermediate steps between each keyframe. | ||
|
|
||
| Returns: | ||
| A list of pinocchio.SE3 objects representing the trajectory. | ||
| """ | ||
| trajectory = [] | ||
| for i in range(num_steps): | ||
| # 1. Parameter to track progress along the helix (from 0.0 to 1.0) | ||
| alpha = float(i) / num_steps | ||
|
|
||
| # 2. Define the translational part (the helical path) | ||
| # The angle determines the position on the XY plane | ||
| angle = alpha * num_revolutions * 2 * np.pi | ||
|
|
||
| # Calculate the x, y, z coordinates for the helix | ||
| translation = np.array( | ||
| [radius * np.cos(angle), radius * np.sin(angle), alpha * height] | ||
| ) | ||
|
|
||
| # 3. Define the rotational part (a new random orientation at each step) | ||
| # pin.SE3.Random().rotation generates a random 3x3 rotation matrix | ||
| random_rotation = pin.SE3.Random().rotation | ||
|
|
||
| # 4. Combine the translation and random rotation into a single SE(3) pose | ||
| pose = pin.SE3(random_rotation, translation) | ||
| trajectory.append(pose) | ||
|
|
||
| return trajectory | ||
|
|
||
|
|
||
| # --- Visualization Setup --- | ||
|
|
||
| # Generate the random trajectory | ||
| # Parameters for the helical trajectory | ||
| num_steps = 30 | ||
| radius = 1.0 | ||
| num_revolutions = 3 | ||
| height = 2 | ||
|
|
||
| trajectory = generate_random_se3_trajectory(num_steps, radius, num_revolutions, height) | ||
|
|
||
| # Create a Pinocchio model with a single free-flyer joint | ||
| model = pin.Model() | ||
| joint_id = model.addJoint( | ||
| 0, pin.JointModelSpline(trajectory, 3), pin.SE3.Identity(), "free_flyer" | ||
| ) | ||
|
|
||
| # Attach a simple visual geometry (a box) to the joint | ||
| visual_model = pin.GeometryModel() | ||
| box_shape = hppfcl.Box(0.1, 0.2, 0.3) | ||
| # The placement of the geometry with respect to the joint frame | ||
| geom_placement = pin.SE3.Identity() | ||
| geom_obj = pin.GeometryObject("box", joint_id, geom_placement, box_shape) | ||
| # Assign a color to the geometry | ||
| geom_obj.meshColor = np.array([1.0, 0.5, 0.5, 1.0]) # RGBA | ||
| visual_model.addGeometryObject(geom_obj) | ||
|
|
||
| # --- Main Execution --- | ||
|
|
||
| # Initialize the MeshCat visualizer. | ||
| try: | ||
| viz = MeshcatVisualizer(model, visual_model, visual_model) | ||
| viz.initViewer(open=True) | ||
| viz.loadViewerModel() | ||
| except ImportError as e: | ||
| print("Error while initializing the viewer.") | ||
| print(e) | ||
|
|
||
|
|
||
| time.sleep(0.1) | ||
|
|
||
| q = pin.neutral(model) | ||
|
|
||
| q_vector = np.arange(0, 1, 0.05) | ||
| for q in q_vector: | ||
| # Display the new configuration. | ||
| viz.display(np.array([q])) | ||
|
|
||
| # Delay for visualization | ||
| time.sleep(0.05) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // | ||
| // Copyright (c) 2025 INRIA | ||
| // | ||
|
|
||
| #ifndef __pinocchio_algorithm_splines_hpp__ | ||
| #define __pinocchio_algorithm_splines_hpp__ | ||
|
|
||
| namespace pinocchio | ||
| { | ||
| /// @brief Helper structure defining a range of indices. | ||
| /// @details This struct identifies the subset of control frames in a spline that are active | ||
| /// (i.e., have non-zero basis functions) for a specific spline parameter value. | ||
| /// Using this local support property allows for efficient computation of the joint | ||
| /// transformation, S, and bias c. | ||
| struct SpanIndexes | ||
| { | ||
| size_t start_idx; | ||
| size_t end_idx; | ||
| }; | ||
|
|
||
| /// @brief Algorithm to locate the span for a given B-spline parameter, q. | ||
| /// @details This struct implements a binary search (FindSpan) to determine which knot span | ||
| /// a given parameter value falls into. In B-spline curves, a parameter value $u$ implies that | ||
| /// only $(p+1)$ control points affect the curve at that location (where $p$ is the degree). | ||
| template<typename Scalar, int Options> | ||
| struct FindSpan | ||
| { | ||
| template<typename ConfigVector, typename KnotsVector> | ||
| static SpanIndexes run( | ||
| const Eigen::MatrixBase<ConfigVector> & q, | ||
| const int degree, | ||
| const int nbCtrlFrames, | ||
| const Eigen::MatrixBase<KnotsVector> & knots) | ||
| { | ||
| // Edge case: if q is at or beyond the end of the spline parameterization | ||
| if (q[0] >= 1.0) | ||
| return { | ||
| static_cast<size_t>(nbCtrlFrames - (degree + 1)), static_cast<size_t>(nbCtrlFrames)}; | ||
|
|
||
| int low = degree; | ||
| int high = nbCtrlFrames; | ||
| int mid; | ||
|
|
||
| while (low < high) | ||
| { | ||
| mid = low + (high - low) / 2; | ||
| if (q[0] < knots[mid]) | ||
| high = mid; | ||
| else | ||
| low = mid + 1; | ||
| } | ||
|
|
||
| return {static_cast<size_t>(low - (degree + 1)), static_cast<size_t>(low)}; | ||
| } | ||
| }; | ||
| } // namespace pinocchio | ||
|
|
||
| #endif // __pinocchio_algorithm_splines_hpp__ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // | ||
| // Copyright (c) 2025 INRIA | ||
| // | ||
|
|
||
| #ifndef __pinocchio_autodiff_casadi_splines_hpp__ | ||
| #define __pinocchio_autodiff_casadi_splines_hpp__ | ||
|
|
||
| #include "pinocchio/algorithm/splines.hpp" | ||
|
|
||
| namespace pinocchio | ||
| { | ||
| // Fwd Declare | ||
| struct SpanIndexes; | ||
|
|
||
| template<typename Scalar, int Options> | ||
| struct FindSpan; | ||
|
|
||
| template<int Options> | ||
| struct FindSpan<::casadi::SX, Options> | ||
| { | ||
| template<typename ConfigVector, typename KnotsVector> | ||
| static SpanIndexes run( | ||
| const Eigen::MatrixBase<ConfigVector> & /*q*/, | ||
| const int /*degree*/, | ||
| const int nbCtrlFrames, | ||
| const Eigen::MatrixBase<KnotsVector> & /*knots*/) | ||
| { | ||
| return {0, static_cast<size_t>(nbCtrlFrames)}; | ||
| } | ||
| }; | ||
| } // namespace pinocchio | ||
|
|
||
| #endif // __pinocchio_autodiff_casadi_splines_hpp__ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.