tests/python/humanoid_robot.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # Copyright 2011, Florent Lamiraux, Thomas Moulard, JRL, CNRS/AIST
4 
5 import unittest
6 
7 import numpy as np
8 from dynamic_graph.sot.dynamic_pinocchio import DynamicPinocchio
9 from dynamic_graph.sot.dynamic_pinocchio.humanoid_robot import AbstractHumanoidRobot
10 
11 from example_robot_data import load_full
12 
13 
14 class Robot(AbstractHumanoidRobot):
15  def __init__(self, name, urdfString=None, urdfFile=None):
16  if urdfString is not None:
17  self.loadModelFromString(urdfString)
18  elif urdfFile is not None:
19  self.loadModelFromUrdf(urdfFile)
20  else:
21  raise RuntimeError("You should provide either a URDF file or a URDF string")
22 
23  AbstractHumanoidRobot.__init__(self, name, None)
24 
25  def defineHalfSitting(self, q):
26  pass
27 
28 
29 class HumanoidRobotTest(unittest.TestCase):
30  def setUp(self):
31  self.name = "talos"
32  _, _, urdf, _ = load_full(self.name)
33  self.urdf_file_name = urdf
34 
36  class NonInstanciableRobot(AbstractHumanoidRobot):
37  pass
38 
39  self.assertRaises(TypeError, NonInstanciableRobot, "non_instanciable_robot")
40 
42  with open(self.urdf_file_name, "r") as urdf:
43  urdfString = urdf.read()
44  arobot = Robot("test_build_robot_from_string", urdfString=urdfString)
45 
46  # Test if the two vectors are identical:
47  arobot.dynamic = DynamicPinocchio(self.name + "_dynamic")
48  arobot.dynamic.setModel(arobot.pinocchioModel)
49  arobot.dynamic.setData(arobot.pinocchioData)
50  arobot.dynamic.add_signals()
51 
52  def get(s):
53  s.recompute(0)
54  return s.value
55 
56  loc_lowerJl = np.array(get(arobot.dynamic.lowerJl))
57  pin_lowerJl = np.array(
58  arobot.pinocchioModel.lowerPositionLimit[
59  1 : len(arobot.pinocchioModel.lowerPositionLimit)
60  ]
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 
68  Robot("test_build_robot_from_string", urdfFile=self.urdf_file_name)
69 
70 
71 if __name__ == "__main__":
72  unittest.main()
humanoid_robot.Robot.defineHalfSitting
def defineHalfSitting(self, q)
Definition: tests/python/humanoid_robot.py:25
humanoid_robot.HumanoidRobotTest.setUp
def setUp(self)
Definition: tests/python/humanoid_robot.py:30
humanoid_robot.Robot.__init__
def __init__(self, name, urdfString=None, urdfFile=None)
Definition: tests/python/humanoid_robot.py:15
humanoid_robot.Robot
Definition: tests/python/humanoid_robot.py:14
humanoid_robot.HumanoidRobotTest.test_non_instanciable_robot
def test_non_instanciable_robot(self)
Definition: tests/python/humanoid_robot.py:35
humanoid_robot.HumanoidRobotTest.test_build_robot_from_string
def test_build_robot_from_string(self)
Definition: tests/python/humanoid_robot.py:41
humanoid_robot.HumanoidRobotTest.name
name
Definition: tests/python/humanoid_robot.py:31
humanoid_robot.HumanoidRobotTest.test_build_robot_from_urdf
def test_build_robot_from_urdf(self)
Definition: tests/python/humanoid_robot.py:67
humanoid_robot.HumanoidRobotTest.urdf_file_name
urdf_file_name
Definition: tests/python/humanoid_robot.py:33


sot-dynamic-pinocchio
Author(s): Olivier Stasse
autogenerated on Fri Jul 28 2023 02:10:01