Skip to content

Commit 7d5027a

Browse files
committed
add reconstruction to example position
1 parent 1ed681a commit 7d5027a

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ __pycache__/
1616
casadi_codegen.obj
1717
invariants_py/data/sine_wave_invariants.csv
1818
venv/
19+
debug_fatrop_*
20+
nlp_hess_l.casadi

examples/calculate_invariants_position.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,18 @@
1313
trajectory, time = dh.read_pose_trajectory_from_data(path_data,dtype = 'txt')
1414

1515
# Calculate the invariants of the translation trajectory
16-
invariants, progress, calc_trajectory, movingframes = invariants_handler.calculate_invariants_translation(trajectory)
16+
invariants, progress, calc_trajectory, movingframes, progress_n = invariants_handler.calculate_invariants_translation(trajectory)
17+
18+
# (Optional) Reconstruction of the trajectory from the invariants
19+
reconstructed_trajectory, recon_mf = invariants_handler.reconstruct_trajectory(invariants, progress_n, p_init=calc_trajectory[0,:], mf_init=movingframes[0,:,:])
20+
21+
print(recon_mf[1,:,:])
22+
print(movingframes[1,:,:])
1723

1824
# Plotting the results
1925
plotters.plot_invariants_new2(invariants, progress) # calculated invariants
2026
plotters.plot_trajectory(calc_trajectory) # calculated trajectory corresponding to invariants
27+
plotters.plot_trajectory(reconstructed_trajectory) # reconstructed trajectory corresponding to invariants
2128
plotters.plot_moving_frames(calc_trajectory, movingframes) # calculated moving frames along trajectory
2229
plotters.animate_moving_frames(calc_trajectory, movingframes) # animated moving frames along trajectory
2330

invariants_py/invariants_handler.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33
"""
44

55
import invariants_py.reparameterization as reparam
6+
import invariants_py.dynamics_vector_invariants as dyn
67
import invariants_py.calculate_invariants.opti_calculate_vector_invariants_position_mf as FS_calculation
8+
import numpy as np
79

810
def calculate_invariants_translation(trajectory, progress_definition="arclength"):
911

1012
# different progress definition: {time, default: arclength, arcangle, screwbased}
1113
# Reparameterize the trajectory based on arclength
1214
trajectory_geom, arclength, arclength_n, nb_samples, stepsize = reparam.reparameterize_trajectory_arclength(trajectory)
1315

16+
print(stepsize)
17+
1418
# Create an instance of the OCP_calc_pos class
1519
FS_calculation_problem = FS_calculation.OCP_calc_pos(window_len=nb_samples, geometric=True)
1620

@@ -20,5 +24,31 @@ def calculate_invariants_translation(trajectory, progress_definition="arclength"
2024
invariants = result[0]
2125
trajectory = result[1]
2226
movingframes = result[2]
23-
return invariants, arclength, trajectory, movingframes
27+
return invariants, arclength, trajectory, movingframes, arclength_n
28+
29+
30+
def reconstruct_trajectory(invariants, progress, p_init=np.zeros((3,1)), mf_init=np.eye(3)):
31+
32+
N = len(progress)
33+
34+
positions = np.zeros((N,3))
35+
R_frames = np.zeros((N,3,3))
36+
37+
stepsize = 1/N
38+
print(stepsize)
39+
40+
positions[0,:] = p_init
41+
R_frames[0,:,:] = mf_init
2442

43+
# Use integrator to find the other initial states
44+
for k in range(N-1):
45+
46+
[R_plus1,p_plus1] = dyn.integrate_vector_invariants_position(mf_init, p_init, invariants[k,:], stepsize)
47+
48+
positions[k+1,:] = np.array(p_plus1).T
49+
R_frames[k+1,:,:] = np.array(R_plus1)
50+
51+
p_init = p_plus1
52+
mf_init = R_plus1
53+
54+
return positions, R_frames

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "invariants-py"
3-
version = "0.3.7" # note that it is possible for the build backend to manage versions in a dynamic way
3+
version = "0.3.8" # note that it is possible for the build backend to manage versions in a dynamic way
44
description = "Calculate invariant trajectory representations from trajectory data and generate new trajectories from invariant representations"
55
authors = [ {name = "Maxim Vochten"},
66
{name = "Riccardo Burlizzi"},

0 commit comments

Comments
 (0)