unittest_utils.py 4.16 KB
Newer Older
1
2
from os.path import exists, join

Guilhem Saurel's avatar
Guilhem Saurel committed
3
4
import numpy as np

5
6
7
8
import pinocchio
from pinocchio.robot_wrapper import RobotWrapper


9
10
11
12
13
14
15
16
def getModelPath(subpath):
    for path in ['..', '../..', '/opt/openrobots/share/example-robot-data']:
        if exists(join(path, subpath.strip('/'))):
            print "using %s as modelPath" % path
            return path
    raise IOError('%s not found' % (subpath))


17
def readParamsFromSrdf(robot, SRDF_PATH, verbose):
Guilhem Saurel's avatar
Guilhem Saurel committed
18
19
20
    rmodel = robot.model

    pinocchio.loadRotorParameters(rmodel, SRDF_PATH, verbose)
21
22
23
    rmodel.armature = \
        np.multiply(rmodel.rotorInertia.flat,
                    np.square(rmodel.rotorGearRatio.flat))
24
    try:
Guilhem Saurel's avatar
Guilhem Saurel committed
25
        pinocchio.loadReferenceConfigurations(rmodel, SRDF_PATH, verbose)
26
27
        robot.q0.flat[:] = \
            rmodel.referenceConfigurations["half_sitting"].copy()
28
    except:
29
30
        print "loadReferenceConfigurations did not work. Please check your \
            Pinocchio Version"
Guilhem Saurel's avatar
Guilhem Saurel committed
31
32
33
34
35
36
37
38
        try:
            pinocchio.getNeutralConfiguration(rmodel, SRDF_PATH, verbose)
            robot.q0.flat[:] = rmodel.neutralConfiguration.copy()
        except:
            robot.q0.flat[:] = pinocchio.neutral(rmodel)
    return


39
def loadTalosArm():
40
    URDF_FILENAME = "talos_left_arm.urdf"
41
    URDF_SUBPATH = "/talos_data/robots/" + URDF_FILENAME
42
    SRDF_FILENAME = "talos.srdf"
43
    SRDF_SUBPATH = "/talos_data/srdf/" + SRDF_FILENAME
44
    modelPath = getModelPath(URDF_SUBPATH)
45
    # Load URDF file
46
    robot = RobotWrapper.BuildFromURDF(modelPath+URDF_SUBPATH, [modelPath])
47
48

    # Load SRDF file
49
    readParamsFromSrdf(robot, modelPath+SRDF_SUBPATH, False)
50
51
    return robot

Guilhem Saurel's avatar
Guilhem Saurel committed
52

53
def loadTalos():
54
55
    URDF_FILENAME = "talos_reduced.urdf"
    SRDF_FILENAME = "talos.srdf"
56
57
    SRDF_SUBPATH = "/talos_data/srdf/" + SRDF_FILENAME
    URDF_SUBPATH = "/talos_data/robots/" + URDF_FILENAME
58
    modelPath = getModelPath(URDF_SUBPATH)
59
    # Load URDF file
60
    robot = RobotWrapper.BuildFromURDF(modelPath+URDF_SUBPATH, [modelPath],
61
                                       pinocchio.JointModelFreeFlyer())
62
    # Load SRDF file
63
    readParamsFromSrdf(robot, modelPath+SRDF_SUBPATH, False)
64
    assert((robot.model.armature[:6] == 0.).all())
65
66
67
    return robot


68
def loadHyQ():
69
    URDF_FILENAME = "hyq_no_sensors.urdf"
70
71
    SRDF_FILENAME = "hyq.srdf"
    SRDF_SUBPATH = "/hyq_description/srdf/" + SRDF_FILENAME
72
    URDF_SUBPATH = "/hyq_description/robots/" + URDF_FILENAME
73
    modelPath = getModelPath(URDF_SUBPATH)
74
    # Load URDF file
75
76
    robot = RobotWrapper.BuildFromURDF(modelPath+URDF_SUBPATH, [modelPath],
                                       pinocchio.JointModelFreeFlyer())
77
78
    # Load SRDF file
    readParamsFromSrdf(robot, modelPath+SRDF_SUBPATH, False)
79
    return robot
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105


def loadTiago():
    URDF_FILENAME = "tiago.urdf"
#    SRDF_FILENAME = "tiago.srdf"
#    SRDF_SUBPATH = "/tiago_description/srdf/" + SRDF_FILENAME
    URDF_SUBPATH = "/tiago_description/robots/" + URDF_FILENAME
    modelPath = getModelPath(URDF_SUBPATH)
    # Load URDF file
    robot = RobotWrapper.BuildFromURDF(modelPath+URDF_SUBPATH, [modelPath])
    # Load SRDF file
#    readParamsFromSrdf(robot, modelPath+SRDF_SUBPATH, False)
    return robot


def loadTiagoNoHand():
    URDF_FILENAME = "tiago_no_hand.urdf"
#    SRDF_FILENAME = "tiago.srdf"
#    SRDF_SUBPATH = "/tiago_description/srdf/" + SRDF_FILENAME
    URDF_SUBPATH = "/tiago_description/robots/" + URDF_FILENAME
    modelPath = getModelPath(URDF_SUBPATH)
    # Load URDF file
    robot = RobotWrapper.BuildFromURDF(modelPath+URDF_SUBPATH, [modelPath])
    # Load SRDF file
#    readParamsFromSrdf(robot, modelPath+SRDF_SUBPATH, False)
    return robot
106

107
108
109
110
111
def loadICub(reduced=True):
    if reduced:
        URDF_FILENAME = "icub_reduced.urdf"
    else:
        URDF_FILENAME = "icub.urdf"
112
113
    SRDF_FILENAME = "icub.srdf"
    SRDF_SUBPATH = "/icub_description/srdf/" + SRDF_FILENAME
114
115
116
117
118
119
    URDF_SUBPATH = "/icub_description/robots/" + URDF_FILENAME
    modelPath = getModelPath(URDF_SUBPATH)
    # Load URDF file
    robot = RobotWrapper.BuildFromURDF(modelPath+URDF_SUBPATH, [modelPath],
                                       pinocchio.JointModelFreeFlyer())
    # Load SRDF file
120
    readParamsFromSrdf(robot, modelPath+SRDF_SUBPATH, False)
121
    return robot