-
Notifications
You must be signed in to change notification settings - Fork 477
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
62
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
62 commits
Select commit
Hold shift + click to select a range
8011234
Joints - Add a first implementation of joint spline
MegMll 74af21a
Unittest - Add TU for spline joint
MegMll c1f4c9e
Bindings - add bindings for spline joint
MegMll ca4b5bf
Spatial - Weird fix to make spline joint work for now (to remove)
MegMll 6fa0947
Unittest - update joint unittests to include spline joints
MegMll 210a1b0
SplineJoint - apply pre-commit
MegMll ffe560e
Spline - use the true cumulative form of the spline
MegMll 36f2618
Spline - Add isEqual Method
MegMll b901345
Spline - Add TU with finite difference
MegMll b562ae2
Unittest - fix tests for spline joint
MegMll c7c0b54
Spline joint - change if/else to be casadi compatible
MegMll 823714b
Joint Spline - Remove useless comments
MegMll be2f401
Joint Spline - Fix indexing
MegMll e4b3f52
Joint Spline - Eigen No Malloc checked and passed
MegMll 863fdd9
Spline joints - fix casadi joints tests
MegMll 4be1e3c
Joint Spline - Add a build method
MegMll 633f41a
Unittest - Fix joint spline's unittests
MegMll a3d7270
Model-graph - Add spline joint to model graph
MegMll a4f3d19
JointSpline - make some correction to the joint
MegMll 6181cde
TU - apply new jointSpline constructor
MegMll dbe5f5a
ModelGraph - use new JointSpline method
MegMll 393cf1c
Serialization - Add attributes from spline model and data
MegMll 6db0782
Unittest - use std vector instead of se3
MegMll 4028aa0
JointSpline - Diverse Changes
MegMll 303ee6b
Casadi - Add a separated file for findSpan to be able to do specializ…
MegMll 61e5f88
Bindings - modify joint spline binding
MegMll 573935d
JointSpline - Remove findSpan
MegMll f207945
Unittest - remove buildJoint function
MegMll 548b7a2
ModelGraph - finish adding jointSpline to model graph + unittest
MegMll a9b1bfe
cppadcg: Fix cppadcg cast test with spline joint
jorisv ac75a25
multiprecision: Fix multiprecision cast test with Spline joint
jorisv 65a9421
multiprecision: Add missing header
jorisv 1024893
lint: Run linter
jorisv 903b9f5
JointSpline - Removed comments
MegMll 44961b4
JointSpline - move bspline functions in public to be able to test it
MegMll 5d7a739
Unittest - add more test for joint spline
MegMll 207c26d
Bindings - Add another constructor for joint spline
MegMll fd7798f
Unittest - put full knee trajectory
MegMll c4e7865
Unittest - try a fix for windows and serialization
MegMll 376b89c
Unittest - fix getTrajectory function
MegMll 7156da5
Bindings - add modelgraph bindings constant
MegMll 3ab2890
JointSpline - Fix indexing
MegMll 2c19b45
JointSpline - Add a doc
MegMll a9ff06b
JointSpline - Fix bias computation
MegMll c4a6be4
Unittest - add a finite difference test for S and bias c for JointSpline
MegMll 8e4dbf9
JointSpline - Add comments and complete isEqual function
MegMll da127f8
Unittest - Try to add tolerance to see if it fixes macos-intel problem
MegMll 82c0f30
Unittest - fix compilation error
MegMll 7d204a8
JointSpline - add assert for configuration to be between 0 and 1
MegMll 951a79a
Bindings - Add graph spline joints bindings
MegMll 3f82e27
Algo/Splines - remove comments
MegMll cbae7d3
Unittest - add find span test for q = 0
MegMll d86231f
Changelog - update
MegMll 5ded836
JointSpline - remove SE3 and use Transformation_t
MegMll bf16106
Unittest - remove comments
MegMll 9c0b4da
JointSpline - Use transformation_t and motion_t
MegMll b04d961
Examples - Add a small examples on what the spline joint can do
MegMll 6b54af1
Unittest - Specialize for joint spline
MegMll ec39eeb
Examples - add spline joint examples
MegMll 9f2aa54
Unittest - Fix joint generic test for joint spline
MegMll f755af3
Examples - Fix some linting errors
MegMll b4923b1
JointSpline - Disable assert
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,49 @@ | ||
| // | ||
| // Copyright (c) 2025 INRIA | ||
| // | ||
|
|
||
| #ifndef __pinocchio_algorithm_splines_hpp__ | ||
| #define __pinocchio_algorithm_splines_hpp__ | ||
|
|
||
| namespace pinocchio | ||
| { | ||
| struct SpanIndexes | ||
| { | ||
| size_t start_idx; | ||
| size_t end_idx; | ||
| }; | ||
|
|
||
| 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.