Skip to content
Snippets Groups Projects
Commit 9c6a8ee4 authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

[Test] Standardization

parent c7a5bae7
No related branches found
No related tags found
No related merge requests found
Pipeline #3048 failed
image: gepgitlab.laas.fr:4567/Gepetto/example-robot-data
test:
script:
- cd unittest && python test_all.py
include: http://rainboard.laas.fr/project/example-robot-data/.gitlab-ci.yml
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
INCLUDE(cmake/base.cmake)
INCLUDE(cmake/test.cmake)
SET(PROJECT_NAMESPACE gepetto)
SET(PROJECT_NAME example-robot-data)
SET(PROJECT_DESCRIPTION "Set of robot URDFs for benchmarking and developed examples.")
SET(PROJECT_URL https://gepgitlab.laas.fr/gepetto/${PROJECT_NAME})
SET(PROJECT_URL https://gepgitlab.laas.fr/${PROJECT_NAMESPACE}/${PROJECT_NAME})
SETUP_PROJECT()
INSTALL(DIRECTORY hyq DESTINATION share/${PROJECT_NAME})
INSTALL(DIRECTORY talos DESTINATION share/${PROJECT_NAME})
ADD_SUBDIRECTORY(unittest)
SETUP_PROJECT_FINALIZE()
FROM gepgitlab.laas.fr:4567/gepetto/buildfarm/robotpkg-jrl:16.04
RUN apt-get update -qqy \
&& apt-get install -qqy \
robotpkg-py27-pinocchio \
&& rm -rf /var/lib/apt/lists/*
SET(${PROJECT_NAME}_PYTHON_TESTS
load
)
FOREACH(TEST ${${PROJECT_NAME}_PYTHON_TESTS})
ADD_PYTHON_UNIT_TEST("py-${TEST}" "unittest/test_${TEST}.py")
ENDFOREACH(TEST ${${PROJECT_NAME}_PYTHON_TESTS})
import unittest
import sys
testmodules = [
'test_load',
]
suite = unittest.TestSuite()
for t in testmodules:
try:
# If the module defines a suite() function, call it to get the suite.
mod = __import__(t, globals(), locals(), ['suite'])
suitefn = getattr(mod, 'suite')
suite.addTest(suitefn())
except (ImportError, AttributeError):
# else, just load all the test cases from the module.
suite.addTest(unittest.defaultTestLoader.loadTestsFromName(t))
result = unittest.TextTestRunner().run(suite)
sys.exit(len(result.errors) + len(result.failures))
from unittest_utils import loadTalosArm, loadTalos, loadHyQ
#!/usr/bin/env python2
import unittest
from unittest_utils import loadHyQ, loadTalos, loadTalosArm
class RobotTestCase(unittest.TestCase):
ROBOT = None
......@@ -16,29 +19,32 @@ class RobotTestCase(unittest.TestCase):
self.assertEqual(model.nv, self.NV, "Wrong nv value.")
def test_q0(self):
self.assertTrue(hasattr(self.ROBOT, "q0"), "It doesn't have q0")
self.assertTrue(hasattr(self.ROBOT, "q0"), "It doesn't have q0")
class TalosArmTest(RobotTestCase):
RobotTestCase.ROBOT = loadTalosArm()
RobotTestCase.NQ = 7
RobotTestCase.NV = 7
class TalosArmFloatingTest(RobotTestCase):
RobotTestCase.ROBOT = loadTalosArm()
RobotTestCase.NQ = 14
RobotTestCase.NV = 13
class TalosTest(RobotTestCase):
RobotTestCase.ROBOT = loadTalos()
RobotTestCase.NQ = 39
RobotTestCase.NV = 38
class HyQTest(RobotTestCase):
RobotTestCase.ROBOT = loadHyQ()
RobotTestCase.NQ = 19
RobotTestCase.NV = 18
if __name__ == '__main__':
unittest.main()
import numpy as np
import pinocchio
from pinocchio.utils import *
from pinocchio.robot_wrapper import RobotWrapper
def readParamsFromSrdf(robot, SRDF_PATH, verbose):
rmodel = robot.model
pinocchio.loadRotorParameters(rmodel, SRDF_PATH, verbose)
rmodel.armature = \
np.multiply(rmodel.rotorInertia.flat, np.square(rmodel.rotorGearRatio.flat))
try:
pinocchio.loadReferenceConfigurations(rmodel, SRDF_PATH, verbose)
robot.q0.flat[:] = rmodel.referenceConfigurations["half_sitting"].copy()
except:
print "loadReferenceConfigurations did not work. Please check your Pinocchio Version"
rmodel = robot.model
pinocchio.loadRotorParameters(rmodel, SRDF_PATH, verbose)
rmodel.armature = np.multiply(rmodel.rotorInertia.flat, np.square(rmodel.rotorGearRatio.flat))
try:
pinocchio.getNeutralConfiguration(rmodel, SRDF_PATH, verbose)
robot.q0.flat[:] = rmodel.neutralConfiguration.copy()
pinocchio.loadReferenceConfigurations(rmodel, SRDF_PATH, verbose)
robot.q0.flat[:] = rmodel.referenceConfigurations["half_sitting"].copy()
except:
robot.q0.flat[:] = pinocchio.neutral(rmodel)
return
print("loadReferenceConfigurations did not work. Please check your Pinocchio Version")
try:
pinocchio.getNeutralConfiguration(rmodel, SRDF_PATH, verbose)
robot.q0.flat[:] = rmodel.neutralConfiguration.copy()
except:
robot.q0.flat[:] = pinocchio.neutral(rmodel)
return
def loadTalosArm(modelPath='/opt/openrobots/share/example-robot-data'):
URDF_FILENAME = "talos_left_arm.urdf"
URDF_SUBPATH = "/talos/" + URDF_FILENAME
SRDF_FILENAME = "talos.srdf"
SRDF_SUBPATH = "/talos/" + SRDF_FILENAME
# Load URDF file
robot = RobotWrapper.BuildFromURDF(modelPath+URDF_SUBPATH, [modelPath])
robot = RobotWrapper(modelPath + URDF_SUBPATH, [modelPath])
# Load SRDF file
readParamsFromSrdf(robot, modelPath+SRDF_SUBPATH, False)
readParamsFromSrdf(robot, modelPath + SRDF_SUBPATH, False)
return robot
def loadTalos(modelPath='/opt/openrobots/share/example-robot-data'):
URDF_FILENAME = "talos_reduced.urdf"
SRDF_FILENAME = "talos.srdf"
SRDF_SUBPATH = "/talos/" + SRDF_FILENAME
URDF_SUBPATH = "/talos/" + URDF_FILENAME
# Load URDF file
robot = RobotWrapper.BuildFromURDF(modelPath+URDF_SUBPATH, [modelPath],
pinocchio.JointModelFreeFlyer())
robot = RobotWrapper.BuildFromURDF(modelPath + URDF_SUBPATH, [modelPath], pinocchio.JointModelFreeFlyer())
# Load SRDF file
readParamsFromSrdf(robot, modelPath+SRDF_SUBPATH, False)
assert((robot.model.armature[:6]==0.).all())
readParamsFromSrdf(robot, modelPath + SRDF_SUBPATH, False)
assert ((robot.model.armature[:6] == 0.).all())
return robot
......@@ -53,8 +53,7 @@ def loadHyQ(modelPath='/opt/openrobots/share/example-robot-data'):
import os
URDF_FILENAME = "hyq_no_sensors.urdf"
URDF_SUBPATH = "/hyq/" + URDF_FILENAME
robot = RobotWrapper.BuildFromURDF(modelPath+URDF_SUBPATH, [modelPath],
pinocchio.JointModelFreeFlyer())
robot = RobotWrapper.BuildFromURDF(modelPath + URDF_SUBPATH, [modelPath], pinocchio.JointModelFreeFlyer())
# TODO define default position inside srdf
robot.q0.flat[7:] = [-0.2, 0.75, -1.5, -0.2, -0.75, 1.5, -0.2, 0.75, -1.5, -0.2, -0.75, 1.5]
robot.q0[2] = 0.57750958
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment