Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ab00835
Add plot backup, full-JAX PCS planar + Gaussian quadrature integratio…
solangegbv May 12, 2025
231c9e3
Change fori_loop to vmap/scan and cond to min in
solangegbv May 13, 2025
19d91ea
Transformed simulate_planar_pcs into a function
solangegbv May 28, 2025
63ed97f
Replacement of at.set by block
solangegbv Jun 4, 2025
6dd50a4
Add quadax dependency, recover original files, remove jit for math_utils
solangegbv Jun 5, 2025
7c17c6a
Changing Coriolis for loop to vmap,
solangegbv Jun 6, 2025
3bb65cf
Corrected type error in planar_pcs_num.py
solangegbv Jun 10, 2025
7bb0d43
Added formulas in SE2, Coriolis corrections
solangegbv Jun 16, 2025
6952264
Correction of the kinetic energy function
solangegbv Jun 17, 2025
81e5895
Fix jit decorators to apply JIT-compilation to
solangegbv Jun 20, 2025
62a7aa4
Creation of a test file for planar_pcs_num.py
solangegbv Jul 7, 2025
d72094a
Roll-back changes to symbolic expressions
mstoelzle Jul 21, 2025
877634a
Bumpy version number and add Solange as an author
mstoelzle Jul 21, 2025
b4beba7
Merge branch 'main' into numerical-derivation
mstoelzle Jul 21, 2025
b8c1fe6
Rename `planar_pcs` system to `planar_pcs_sym`
mstoelzle Jul 21, 2025
5fec620
Fix some type hinting errors
mstoelzle Jul 21, 2025
6838cec
Fix missing changes in last commit
mstoelzle Jul 21, 2025
9baef51
Rename `test_planar_pcs.py` to `test_planar_pcs_sym`
mstoelzle Jul 21, 2025
3eb5391
Fix some bugs
mstoelzle Jul 21, 2025
94c4928
Format systems
mstoelzle Jul 21, 2025
44242a2
Format the `tests` files
mstoelzle Jul 21, 2025
e021a71
Format the `utils` files
mstoelzle Jul 21, 2025
7107cbd
Exclude some test scripts from automated testing if they require gui
mstoelzle Jul 21, 2025
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
990 changes: 776 additions & 214 deletions examples/simulate_planar_pcs.py

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion examples/videos/.gitignore

This file was deleted.

40 changes: 36 additions & 4 deletions src/jsrm/math_utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from jax import numpy as jnp
from jax import Array, lax, jit


@jit
def blk_diag(a: Array) -> Array:
def blk_diag(
a: Array
) -> Array:
"""
Create a block diagonal matrix from a tensor of blocks
Create a block diagonal matrix from a tensor of blocks.

Args:
a: matrices to be block diagonalized of shape (m, n, o)

Expand All @@ -31,7 +33,7 @@ def assign_block_diagonal(i, _b):

# Implement for loop to assign each block in `a` to the block-diagonal of `b`
# Hint: use `jax.lax.fori_loop` and pass `assign_block_diagonal` as an argument
b = jnp.zeros((a.shape[0] * a.shape[1], a.shape[0] * a.shape[2]))
b = jnp.zeros((a.shape[0] * a.shape[1], a.shape[0] * a.shape[2]), dtype=a.dtype)
b = lax.fori_loop(
lower=0,
upper=a.shape[0],
Expand All @@ -40,3 +42,33 @@ def assign_block_diagonal(i, _b):
)

return b

@jit
def blk_concat(
a: Array
) -> Array:
"""
Concatenate horizontally (along the columns) a list of N matrices of size (a, b) to create a single matrix of size (a, b * N).

Args:
a (Array): matrices to be concatenated of shape (N, a, b)

Returns:
Array: concatenated matrix of shape (a, N * b)
"""
b = a.transpose(1, 0, 2).reshape(a.shape[1], -1)
return b

if __name__ == "__main__":
# Example usage
a = jnp.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])
print("Original array:")
print(a)

b = blk_diag(a)
print("Block diagonal matrix:")
print(b)

c = blk_concat(a)
print("Concatenated matrix:")
print(c)
4 changes: 2 additions & 2 deletions src/jsrm/symbolic_derivation/planar_pcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ def symbolically_derive_planar_pcs_model(
# Jacobians (positional + orientation) in each segment as a function of the point coordinate s and its time derivative
J_sms, J_d_sms = [], []
# cross-sectional area of each segment
A = sp.zeros(num_segments)
A = sp.zeros(num_segments, 1)
# second area moment of inertia of each segment
I = sp.zeros(num_segments)
I = sp.zeros(num_segments, 1)
# inertia matrix
B = sp.zeros(num_dof, num_dof)
# potential energy
Expand Down
Binary file modified src/jsrm/symbolic_expressions/planar_pcs_ns-1.dill
Binary file not shown.
Binary file modified src/jsrm/symbolic_expressions/planar_pcs_ns-2.dill
Binary file not shown.
2 changes: 1 addition & 1 deletion src/jsrm/systems/planar_pcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ def operational_space_dynamical_matrices_fn(
Lambda: inertia matrix in the operational space of shape (3, 3)
mu: matrix with corioli and centrifugal terms in the operational space of shape (3, 3)
J: Jacobian of the Cartesian pose with respect to the generalized coordinates of shape (3, n_q)
J: time-derivative of the Jacobian of the end-effector pose with respect to the generalized coordinates
J_d: time-derivative of the Jacobian of the end-effector pose with respect to the generalized coordinates
of shape (3, n_q)
JB_pinv: Dynamically-consistent pseudo-inverse of the Jacobian. Allows the mapping of torques
from the generalized coordinates to the operational space: f = JB_pinv.T @ tau_q
Expand Down
Loading