-
Notifications
You must be signed in to change notification settings - Fork 482
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
Draft
MegMll
wants to merge
70
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.
Draft
Changes from all commits
Commits
Show all changes
70 commits
Select commit
Hold shift + click to select a range
7a5c37e
Joints - Add a first implementation of joint spline
MegMll 2f6dd50
Unittest - Add TU for spline joint
MegMll 1fd4295
Bindings - add bindings for spline joint
MegMll f169e9c
Spatial - Weird fix to make spline joint work for now (to remove)
MegMll 936c1d4
Unittest - update joint unittests to include spline joints
MegMll 7109553
SplineJoint - apply pre-commit
MegMll d42f298
Spline - use the true cumulative form of the spline
MegMll c9c780a
Spline - Add isEqual Method
MegMll 245bc08
Spline - Add TU with finite difference
MegMll 87c9314
Unittest - fix tests for spline joint
MegMll 343c4fa
Spline joint - change if/else to be casadi compatible
MegMll befe587
Joint Spline - Remove useless comments
MegMll ba09e10
Joint Spline - Fix indexing
MegMll 8e6fac3
Joint Spline - Eigen No Malloc checked and passed
MegMll 835a3be
Spline joints - fix casadi joints tests
MegMll 6bf8e04
Joint Spline - Add a build method
MegMll 2c73df3
Unittest - Fix joint spline's unittests
MegMll 5a15d61
Model-graph - Add spline joint to model graph
MegMll bbff9a3
JointSpline - make some correction to the joint
MegMll 59c7cf6
TU - apply new jointSpline constructor
MegMll 0c69a04
ModelGraph - use new JointSpline method
MegMll 5b614da
Serialization - Add attributes from spline model and data
MegMll 0a6e431
Unittest - use std vector instead of se3
MegMll 522db04
JointSpline - Diverse Changes
MegMll cb17904
Casadi - Add a separated file for findSpan to be able to do specializ…
MegMll db6439b
Bindings - modify joint spline binding
MegMll 11f31c9
JointSpline - Remove findSpan
MegMll 1f14429
Unittest - remove buildJoint function
MegMll 2592cc6
ModelGraph - finish adding jointSpline to model graph + unittest
MegMll 0f8bb0e
cppadcg: Fix cppadcg cast test with spline joint
jorisv fa73b20
multiprecision: Fix multiprecision cast test with Spline joint
jorisv 4d3d02e
multiprecision: Add missing header
jorisv dbcbf1a
lint: Run linter
jorisv 57d00f0
JointSpline - Removed comments
MegMll 9f418a8
JointSpline - move bspline functions in public to be able to test it
MegMll 789fe01
Unittest - add more test for joint spline
MegMll 2bbd344
Bindings - Add another constructor for joint spline
MegMll 3e1b6a3
Unittest - put full knee trajectory
MegMll 10e0012
Unittest - try a fix for windows and serialization
MegMll 119595d
Unittest - fix getTrajectory function
MegMll 0fd8a15
Bindings - add modelgraph bindings constant
MegMll 26bf375
JointSpline - Fix indexing
MegMll 5887519
JointSpline - Add a doc
MegMll 618c495
JointSpline - Fix bias computation
MegMll db32494
Unittest - add a finite difference test for S and bias c for JointSpline
MegMll de1ef3a
JointSpline - Add comments and complete isEqual function
MegMll fe4b5ca
Unittest - Try to add tolerance to see if it fixes macos-intel problem
MegMll 78ec286
Unittest - fix compilation error
MegMll 3f4b6a6
JointSpline - add assert for configuration to be between 0 and 1
MegMll f9c336c
Bindings - Add graph spline joints bindings
MegMll d89552b
Algo/Splines - remove comments
MegMll e5fbd70
Unittest - add find span test for q = 0
MegMll 1097d4f
Changelog - update
MegMll 4b42132
JointSpline - remove SE3 and use Transformation_t
MegMll d5b210a
Unittest - remove comments
MegMll 2ffe305
JointSpline - Use transformation_t and motion_t
MegMll a2b0703
Examples - Add a small examples on what the spline joint can do
MegMll f2e5c30
Unittest - Specialize for joint spline
MegMll 4768a32
Examples - add spline joint examples
MegMll 079720e
Unittest - Fix joint generic test for joint spline
MegMll ef9b1e3
Examples - Fix some linting errors
MegMll 86b40d7
JointSpline - Disable assert
MegMll 096a5ec
core: Apply small changes
jorisv a94b07b
Algo/splines - add doc
MegMll f4421ae
Unittest - Avoid code duplication for randomConfig vector generation
MegMll a8c2e58
Unittest - more complex and complete tests
MegMll 4b8c8e9
Unittest/cppad - use degree 3 spline joint
MegMll 57e31ab
unittest - change name of struct to be more generic
MegMll 08af0ca
unittest - avoid code duplication
MegMll 86537d9
unittest - avoid code duplication
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
Some comments aren't visible on the classic Files Changed page.
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.