Skip to content

Commit

Permalink
Apply suggestions from code review to centroidal expressions
Browse files Browse the repository at this point in the history
Co-authored-by: Diego Ferigo <[email protected]>
  • Loading branch information
S-Dafarra and diegoferigo committed Jan 19, 2024
1 parent df7a3fa commit ecfa28f
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/hippopt/robot_planning/expressions/centroidal.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ def centroidal_dynamics_with_point_forces(
) -> cs.Function:
options = {} if options is None else options

if point_position_names is None:
point_position_names = []
for i in range(number_of_points):
point_position_names.append(f"p{i}")
point_position_names = (
point_position_names
if point_position_names is not None
else [f"p{i}" for i in range(number_of_points)]
)

assert len(point_position_names) == number_of_points

Expand All @@ -44,20 +45,19 @@ def centroidal_dynamics_with_point_forces(

p = []
f = []
for i in range(number_of_points):
p.append(cs.MX.sym(point_position_names[i], 3))
input_vars.append(p[i])
f.append(cs.MX.sym(point_force_names[i], 3))
input_vars.append(f[i])

input_names = []
for var in input_vars:
input_names.append(var.name())

h_g = m @ g

for i in range(number_of_points):
h_g = h_g + cs.vertcat(f[i], cs.cross(p[i] - x, f[i]))
for point_position_name, point_force_name in zip(
point_position_names, point_force_names
):
p.append(cs.MX.sym(point_position_name, 3))
input_vars.append(p[-1])
f.append(cs.MX.sym(point_force_name, 3))
input_vars.append(f[-1])

input_names = [var.name() for var in input_vars]

h_g = cs.sum(
[m * g] + [cs.vertcat(fi, cs.cross(pi - x, fi)) for fi, pi in zip(f, p)]
)

return cs.Function(
"centroidal_dynamics_with_point_forces",
Expand Down

0 comments on commit ecfa28f

Please sign in to comment.