Commit f31b4bc5 authored by olivier stasse's avatar olivier stasse Committed by GitHub

Merge pull request #64 from jmirabel/devel

[Python] Add convenient function to create a robot from a URDF file.
parents 92f75f2d b5fa49f1
Pipeline #9153 failed with stage
in 9 minutes and 6 seconds
......@@ -49,7 +49,6 @@ IF(BUILD_PYTHON_INTERFACE)
__init__.py
humanoid_robot.py
tools.py
parser.py
)
FOREACH(py_file ${${PY_NAME}_PYTHON})
......
This diff is collapsed.
SET(${PROJECT_NAME}_PYTHON_TESTS
humanoid_robot
)
FOREACH(TEST ${${PROJECT_NAME}_PYTHON_TESTS})
ADD_PYTHON_UNIT_TEST("py-${TEST}" "tests/python/${TEST}.py")
......
......@@ -4,15 +4,43 @@
import unittest
from dynamic_graph.sot.dynamic_pinocchio.humanoid_robot import HumanoidRobot
from dynamic_graph.sot.dynamic_pinocchio.humanoid_robot import AbstractHumanoidRobot
class Robot (AbstractHumanoidRobot):
def __init__ (self, name, urdfString=None, urdfFile=None):
import pinocchio
if urdfString is not None:
self.loadModelFromString(urdfString)
elif urdfFile is not None:
self.loadModelFromUrdf(urdfFile)
else:
raise RuntimeError("You should provide either a URDF file or a URDF string")
class HumanoidRobotTest(unittest.TestCase):
def test_simple(self):
AbstractHumanoidRobot.__init__(self, name, None)
def defineHalfSitting (self, q):
pass
def test_model_not_exist(self):
self.assertRaises(IOError, HumanoidRobot, "robot", True, "IDONOTEXIST")
class HumanoidRobotTest(unittest.TestCase):
def setUp(self):
import os
dir_path = os.path.dirname(os.path.realpath(__file__))
self.r2d2_urdf_file = os.path.join(dir_path, "r2d2.urdf")
def test_non_instanciable_robot(self):
class NonInstanciableRobot (AbstractHumanoidRobot):
pass
self.assertRaises(TypeError, NonInstanciableRobot, "non_instanciable_robot")
def test_build_robot_from_string(self):
with open(self.r2d2_urdf_file, 'r') as urdf:
urdfString = urdf.read()
robot = Robot("test_build_robot_from_string", urdfString = urdfString)
def test_build_robot_from_urdf(self):
robot = Robot("test_build_robot_from_string", urdfFile = self.r2d2_urdf_file)
if __name__ == '__main__':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment