Skip to content
This repository was archived by the owner on Nov 28, 2025. It is now read-only.

Commit 58221d7

Browse files
Fix lower position limit.
The initialization was using std::numeric_limits<double>::min instead of std::numeric_limits<double>::lowest. Add a unit test. Fix #71
1 parent e50a87a commit 58221d7

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ PROJECT(${PROJECT_NAME} ${PROJECT_ARGS})
3434

3535
# Project dependencies
3636
ADD_PROJECT_DEPENDENCY(sot-tools REQUIRED PKG_CONFIG_REQUIRES sot-tools)
37+
ADD_PROJECT_DEPENDENCY(example-robot-data)
3738

3839
SET(BOOST_COMPONENTS filesystem system unit_test_framework)
3940

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<exec_depend>sot-tools</exec_depend>
2828
<exec_depend>sot-core</exec_depend>
2929
<exec_depend>pinocchio</exec_depend>
30+
<exec_depend>example-robot-data</exec_depend>
3031

3132
<test_depend>gtest</test_depend>
3233

src/sot-dynamic-pinocchio.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ dg::Vector& DynamicPinocchio::getLowerPositionLimits(dg::Vector& res, const int&
253253

254254
res.resize(m_model->nv);
255255
if (!sphericalJoints.empty()) {
256+
256257
int fillingIndex = 0; // SoTValue
257258
int origIndex = 0; // PinocchioValue
258259
for (std::vector<int>::const_iterator it = sphericalJoints.begin(); it < sphericalJoints.end(); it++) {
@@ -266,12 +267,13 @@ dg::Vector& DynamicPinocchio::getLowerPositionLimits(dg::Vector& res, const int&
266267
}
267268
// Found a Spherical Joint.
268269
// Assuming that spherical joint limits are unset
269-
res(fillingIndex) = std::numeric_limits<double>::min();
270-
res(fillingIndex + 1) = std::numeric_limits<double>::min();
271-
res(fillingIndex + 2) = std::numeric_limits<double>::min();
270+
res(fillingIndex) = std::numeric_limits<double>::lowest();
271+
res(fillingIndex + 1) = std::numeric_limits<double>::lowest();
272+
res(fillingIndex + 2) = std::numeric_limits<double>::lowest();
272273
fillingIndex += 3;
273274
origIndex += 4;
274275
}
276+
275277
assert(m_model->nv - fillingIndex == m_model->nq - origIndex);
276278
if (m_model->nv > fillingIndex)
277279
res.segment(fillingIndex, m_model->nv - fillingIndex) =

tests/python/humanoid_robot.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
# Copyright 2011, Florent Lamiraux, Thomas Moulard, JRL, CNRS/AIST
44

55
import unittest
6+
import pinocchio
67

8+
import numpy as np
9+
10+
from dynamic_graph.sot.dynamic_pinocchio import DynamicPinocchio
711
from dynamic_graph.sot.dynamic_pinocchio.humanoid_robot import AbstractHumanoidRobot
812

913

@@ -26,7 +30,10 @@ class HumanoidRobotTest(unittest.TestCase):
2630
def setUp(self):
2731
import os
2832
dir_path = os.path.dirname(os.path.realpath(__file__))
29-
self.r2d2_urdf_file = os.path.join(dir_path, "r2d2.urdf")
33+
from example_robot_data.path import EXAMPLE_ROBOT_DATA_MODEL_DIR
34+
self.urdf_file_name=EXAMPLE_ROBOT_DATA_MODEL_DIR+\
35+
'/talos_data/robots/talos_reduced.urdf'
36+
self.name = "talos"
3037

3138
def test_non_instanciable_robot(self):
3239
class NonInstanciableRobot(AbstractHumanoidRobot):
@@ -36,12 +43,30 @@ class NonInstanciableRobot(AbstractHumanoidRobot):
3643

3744
def test_build_robot_from_string(self):
3845

39-
with open(self.r2d2_urdf_file, 'r') as urdf:
46+
with open(self.urdf_file_name, 'r') as urdf:
4047
urdfString = urdf.read()
41-
Robot("test_build_robot_from_string", urdfString=urdfString)
48+
arobot = Robot("test_build_robot_from_string", urdfString=urdfString)
49+
50+
# Test if the two vectors are identical:
51+
arobot.dynamic = DynamicPinocchio(self.name + "_dynamic")
52+
arobot.dynamic.setModel(arobot.pinocchioModel)
53+
arobot.dynamic.setData(arobot.pinocchioData)
54+
55+
def get(s):
56+
s.recompute(0)
57+
return s.value
58+
59+
loc_lowerJl=np.array(get(arobot.dynamic.lowerJl))
60+
pin_lowerJl=np.array(arobot.pinocchioModel.lowerPositionLimit[1:len(arobot.pinocchioModel.lowerPositionLimit
61+
)])
62+
63+
for i in range(0,len(loc_lowerJl),1):
64+
if not loc_lowerJl[i] == pin_lowerJl[i]:
65+
self.assertTrue(False,"lowerJl is not working")
66+
4267

4368
def test_build_robot_from_urdf(self):
44-
Robot("test_build_robot_from_string", urdfFile=self.r2d2_urdf_file)
69+
Robot("test_build_robot_from_string", urdfFile=self.urdf_file_name)
4570

4671

4772
if __name__ == '__main__':

0 commit comments

Comments
 (0)