talos.py 5.79 KB
Newer Older
Olivier Stasse's avatar
Olivier Stasse committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# -*- coding: utf-8 -*-
# Copyright 2016, Olivier STASSE, LAAS-CNRS
#
# This file is part of TALOSController.
# TALOSController is free software: you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
#
# TALOSController is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Lesser Public License for more details.  You should have
# received a copy of the GNU Lesser General Public License along with
# TALOSController. If not, see <http://www.gnu.org/licenses/>.

from __future__ import print_function

import numpy as np

21
from dynamic_graph.sot.dynamics_pinocchio.humanoid_robot import AbstractHumanoidRobot
Olivier Stasse's avatar
Olivier Stasse committed
22
23
24
from dynamic_graph.sot.dynamics_pinocchio import DynamicPinocchio
from dynamic_graph import plug

25
26
import pinocchio as se3
from rospkg import RosPack
Olivier Stasse's avatar
Olivier Stasse committed
27
28
29
30
31
32
33
34
35
36
37

# Internal helper tool.
def matrixToTuple(M):
    tmp = M.tolist()
    res = []
    for i in tmp:
        res.append(tuple(i))
    return tuple(res)

class Talos(AbstractHumanoidRobot):
    """
38
    This class defines a Talos robot
Olivier Stasse's avatar
Olivier Stasse committed
39
40
41
42
    """

    forceSensorInLeftAnkle =  ((1.,0.,0.,0.),
                               (0.,1.,0.,0.),
43
                               (0.,0.,1.,-0.107),
Olivier Stasse's avatar
Olivier Stasse committed
44
45
46
                               (0.,0.,0.,1.))
    forceSensorInRightAnkle = ((1.,0.,0.,0.),
                               (0.,1.,0.,0.),
47
                               (0.,0.,1.,-0.107),
Olivier Stasse's avatar
Olivier Stasse committed
48
                               (0.,0.,0.,1.))
49
50
    """
    TODO: Confirm the position and existence of these sensors
Olivier Stasse's avatar
Olivier Stasse committed
51
52
53
54
55
56
57
58
59
60
61
62
63
    accelerometerPosition = np.matrix ((
            (1., 0., 0., -.13,),
            (0., 1., 0., 0.,),
            (0., 0., 1., .118,),
            (0., 0., 0., 1.,),
            ))

    gyrometerPosition = np.matrix ((
            (1., 0., 0., -.13,),
            (0., 1., 0., 0.,),
            (0., 0., 1., .118,),
            (0., 0., 0., 1.,),
            ))
64
    """
Olivier Stasse's avatar
Olivier Stasse committed
65
    def smallToFull(self, config):
66
67
68
69
        #Gripper position in full configuration: 27:34, and 41:48
        #Small configuration: 36 DOF
        #Full configuration: 50 DOF
        res = config[0:27] + 7*(0.,) + config[27:34]+ 7*(0.,)+config[34:]
Olivier Stasse's avatar
Olivier Stasse committed
70
71
        return res

Olivier Stasse's avatar
Olivier Stasse committed
72
    def __init__(self, name, initialConfig, device = None, tracer = None):
73
74
        self.OperationalPointsMap = {'left-wrist'  : 'arm_left_7_joint',
                                     'right-wrist' : 'arm_right_7_joint',
75
76
                                     'left-ankle'  : 'leg_left_6_joint',
                                     'right-ankle' : 'leg_right_6_joint',
77
78
79
80
                                     'gaze'        : 'head_2_joint',
                                     'waist'       : 'root_joint',
                                     'chest'       : 'torso_2_joint'}

Olivier Stasse's avatar
Olivier Stasse committed
81
82
        from rospkg import RosPack
        rospack = RosPack()
83
        urdfPath = rospack.get_path('talos_data')+"/urdf/talos_reduced_v2.urdf"
84
        urdfDir = [rospack.get_path('talos_data')+"/../"]
Olivier Stasse's avatar
Olivier Stasse committed
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112

        # Create a wrapper to access the dynamic model provided through an urdf file.
        from pinocchio.robot_wrapper import RobotWrapper
        import pinocchio as se3
        from dynamic_graph.sot.dynamics_pinocchio import fromSotToPinocchio
        pinocchioRobot = RobotWrapper(urdfPath, urdfDir, se3.JointModelFreeFlyer())
        self.pinocchioModel = pinocchioRobot.model
        self.pinocchioData = pinocchioRobot.data

        AbstractHumanoidRobot.__init__ (self, name, tracer)

        self.OperationalPoints.append('waist')
        self.OperationalPoints.append('chest')

        # Create rigid body dynamics model and data (pinocchio) 
        self.dynamic = DynamicPinocchio(self.name + "_dynamic")
        self.dynamic.setModel(self.pinocchioModel)
        self.dynamic.setData(self.pinocchioData)
        self.dimension = self.dynamic.getDimension()

        # Initialize device
        self.device = device

        self.device.resize(self.dynamic.getDimension())
        self.halfSitting = initialConfig
        self.device.set(self.halfSitting)
        plug(self.device.state, self.dynamic.position)

Olivier Stasse's avatar
Olivier Stasse committed
113
114
        self.AdditionalFrames.append(
            ("leftFootForceSensor",
115
             self.forceSensorInLeftAnkle, self.OperationalPointsMap["left-ankle"]))
Olivier Stasse's avatar
Olivier Stasse committed
116
117
        self.AdditionalFrames.append(
            ("rightFootForceSensor",
118
             self.forceSensorInRightAnkle, self.OperationalPointsMap["right-ankle"]))
Olivier Stasse's avatar
Olivier Stasse committed
119
        
Olivier Stasse's avatar
Olivier Stasse committed
120
121
        self.dimension = self.dynamic.getDimension()
        self.plugVelocityFromDevice = True
122
        self.dynamic.displayModel()
Olivier Stasse's avatar
Olivier Stasse committed
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147

        # Initialize velocity derivator if chosen
        if self.enableVelocityDerivator:
            self.velocityDerivator = Derivator_of_Vector('velocityDerivator')
            self.velocityDerivator.dt.value = self.timeStep
            plug(self.device.state, self.velocityDerivator.sin)
            plug(self.velocityDerivator.sout, self.dynamic.velocity)
        else:
            self.dynamic.velocity.value = self.dimension*(0.,)

        # Initialize acceleration derivator if chosen            
        if self.enableAccelerationDerivator:
            self.accelerationDerivator = \
                Derivator_of_Vector('accelerationDerivator')
            self.accelerationDerivator.dt.value = self.timeStep
            plug(self.velocityDerivator.sout,
                 self.accelerationDerivator.sin)
            plug(self.accelerationDerivator.sout, self.dynamic.acceleration)
        else:
            self.dynamic.acceleration.value = self.dimension*(0.,)

        # Create operational points based on operational points map (if provided)
        if self.OperationalPointsMap is not None:
            self.initializeOpPoints()

Olivier Stasse's avatar
Olivier Stasse committed
148
__all__ = [Talos]