Skip to content
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

[fix] missing const in arguments of RobotWrapper.set_rotor_inertia and RobotWrapper.set_gear_ratios python bindings #245

Merged
merged 6 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Fix missing `const` specifier in python bindings for methods `RobotInertia.set_rotor_inertia()`
and `RobotInertia.set_gear_ratios()`
## [1.7.1] - 2024-08-26

- Fix a typo in ex_4_walking
Expand Down
5 changes: 3 additions & 2 deletions include/tsid/bindings/python/robots/robot-wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,11 @@ struct RobotPythonVisitor
static Eigen::VectorXd gear_ratios(const Robot &self) {
return self.gear_ratios();
}
static bool set_rotor_inertias(Robot &self, Eigen::VectorXd &rotor_inertias) {
static bool set_rotor_inertias(Robot &self,
const Eigen::VectorXd &rotor_inertias) {
return self.rotor_inertias(rotor_inertias);
}
static bool set_gear_ratios(Robot &self, Eigen::VectorXd &gear_ratios) {
static bool set_gear_ratios(Robot &self, const Eigen::VectorXd &gear_ratios) {
return self.gear_ratios(gear_ratios);
}

Expand Down
22 changes: 22 additions & 0 deletions tests/python/test_RobotWrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,31 @@
q = se3.randomConfiguration(robot.model(), lb, ub)
print(q.transpose())


data = robot.data()
v = np.ones(robot.nv)
robot.computeAllTerms(data, q, v)
print(robot.com(data))
base_mass_matrix = robot.mass(data)

# Adding motor inertia
rng = np.random.default_rng()
rotor_inertia = rng.uniform(0, 1, size=(robot.nq - 7))
gear_ratio = rng.uniform(0, 1, size=(robot.nq - 7))
expected_inertia = rotor_inertia * gear_ratio**2
print(f"Expected motors inertia: {expected_inertia}")

robot.set_rotor_inertias(rotor_inertia)
robot.set_gear_ratios(gear_ratio)

robot.computeAllTerms(data, q, v)

mass_matrix_with_motor_inertia = robot.mass(data)

# Assert that mass matrices are different by motor's inertia
np.testing.assert_allclose(
np.diag(mass_matrix_with_motor_inertia - base_mass_matrix)[6:], expected_inertia
)


print("All test is done")
Loading