robot.py 5.45 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env python
# Copyright (c) 2019 CNRS
# Author: Pierre Fernbach
#
# This file is part of hpp-rbprm-robot-data.
# hpp_tutorial 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.
#
# hpp_tutorial 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
# hpp_tutorial.  If not, see
# <http://www.gnu.org/licenses/>.

from hpp.corbaserver.rbprm.rbprmfullbody import FullBody as Parent
from pinocchio import SE3, Quaternion
import numpy as np

class Robot (Parent):
    ##
    #  Information to retrieve urdf and srdf files.

27
28
    packageName = "anymal_description"
    meshPackageName = "anymal_description"
29
    rootJointType = "freeflyer"
Pierre Fernbach's avatar
Pierre Fernbach committed
30
31
32
    urdfName = "anymal_reachability"
    urdfSuffix = "_boxFeet"
    srdfSuffix = ""
33
34

    ## Information about the names of thes joints defining the limbs of the robot
Pierre Fernbach's avatar
Pierre Fernbach committed
35
36
    rLegId = 'RFleg'
    rleg = 'RF_HAA'
Pierre Fernbach's avatar
Pierre Fernbach committed
37
    rfoot = 'RF_KFE'
Pierre Fernbach's avatar
Pierre Fernbach committed
38
39
    lLegId = 'LFleg'
    lleg = 'LF_HAA'
Pierre Fernbach's avatar
Pierre Fernbach committed
40
    lfoot = 'LF_KFE'
Pierre Fernbach's avatar
Pierre Fernbach committed
41
42
    lArmId = 'LHleg'
    larm = 'LH_HAA'
Pierre Fernbach's avatar
Pierre Fernbach committed
43
    lhand = 'LH_KFE'
Pierre Fernbach's avatar
Pierre Fernbach committed
44
45
    rArmId = 'RHleg'
    rarm = 'RH_HAA'
Pierre Fernbach's avatar
Pierre Fernbach committed
46
    rhand = 'RH_KFE'
47
48


Pierre Fernbach's avatar
Pierre Fernbach committed
49
    referenceConfig =[0.,0.,0.444, 0.,0.,0.,1., # FF
Pierre Fernbach's avatar
Pierre Fernbach committed
50
51
52
53
        0.04, 0.74, -1.08,0.34,-0.04,0.,
        0.04, -0.74, 1.08,-0.34,-0.04,0.,
        -0.04, 0.74, -1.08,0.34,0.04, 0.,
        -0.04, -0.74, 1.08,-0.34,0.04,0.
Pierre Fernbach's avatar
Pierre Fernbach committed
54
        ]
55
    
Pierre Fernbach's avatar
Pierre Fernbach committed
56
57
    reference_weights=[100.,1.,1.,0.,0.,0.]

58
    # informations required to generate the limbs databases the limbs : 
Pierre Fernbach's avatar
Pierre Fernbach committed
59
60
61
    nbSamples = 50000
    octreeSize = 0.01
    cType = "_3_DOF"
Pierre Fernbach's avatar
Pierre Fernbach committed
62
63
64
65
66
67
    offset = [0.,0.,0.33]

    rLegLimbOffset = [0.373, 0.264, 0.]
    lLegLimbOffset = [0.373, -0.264,0.]
    rArmLimbOffset = [-0.373, 0.264, 0.]
    lArmLimbOffset = [-0.373, -0.264, 0.]
68
69
    normal = [0,0,1]
    legx = 0.02; legy = 0.02
Pierre Fernbach's avatar
Pierre Fernbach committed
70
    kinematicConstraintsPath="package://anymal-rbprm/com_inequalities/"
71

Pierre Fernbach's avatar
Pierre Fernbach committed
72
73
74
75
76
77
    minDist = 0.2 

    # data used by scripts :,,,
    #limbs_names = [rArmId,lLegId,lArmId,rLegId] # reverse default order to try to remove contacts at the beginning of the contact plan
    #limbs_names = [lLegId,rArmId,rLegId,lArmId] # default order to try to remove contacts at the beginning of the contact plan
    limbs_names = [rArmId,lArmId,lLegId,rLegId]
Pierre Fernbach's avatar
Pierre Fernbach committed
78
    dict_limb_rootJoint = {rLegId:rleg, lLegId:lleg, rArmId:rarm, lArmId:larm}
79
80
81
82
    dict_limb_joint = {rLegId:rfoot, lLegId:lfoot, rArmId:rhand, lArmId:lhand}
    dict_limb_color_traj = {rfoot:[0,1,0,1], lfoot:[1,0,0,1],rhand:[0,0,1,1],lhand:[0.9,0.5,0,1]}
    FOOT_SAFETY_SIZE = 0.01
    # size of the contact surface (x,y)
Pierre Fernbach's avatar
Pierre Fernbach committed
83
    dict_size={rfoot:[0.031 , 0.031], lfoot:[0.031 , 0.031],rhand:[0.031 , 0.031],lhand:[0.031 , 0.031]}
Pierre Fernbach's avatar
Pierre Fernbach committed
84
    #dict_size={rfoot:[0.01 , 0.01], lfoot:[0.01 , 0.01],rhand:[0.01 , 0.01],lhand:[0.01 , 0.01]}
85
86
87
88
89
90
91
    #various offset used by scripts
    MRsole_offset = SE3.Identity()
    MRsole_offset.translation = np.matrix(offset).T
    MLsole_offset = MRsole_offset.copy()
    MRhand_offset = MRsole_offset.copy()
    MLhand_offset = MRsole_offset.copy()
    dict_offset = {rfoot:MRsole_offset, lfoot:MLsole_offset, rhand:MRhand_offset, lhand:MLhand_offset}
Pierre Fernbach's avatar
Pierre Fernbach committed
92
    dict_limb_offset= {rLegId:rLegLimbOffset, lLegId:lLegLimbOffset, rArmId:rArmLimbOffset, lArmId:lArmLimbOffset}
Pierre Fernbach's avatar
Pierre Fernbach committed
93
    dict_normal = {rfoot:normal, lfoot:normal, rhand:normal, lhand:normal}
94
95
96
97
98
99
100
101
102
103
104
105
106
    # display transform :
    MRsole_display = SE3.Identity()
    MLsole_display = SE3.Identity()
    MRhand_display = SE3.Identity()
    MLhand_display = SE3.Identity()
    dict_display_offset = {rfoot:MRsole_display, lfoot:MLsole_display, rhand:MRhand_display, lhand:MLhand_display}

    def __init__ (self, name = None,load = True):
        Parent.__init__ (self,load)
        if load:
            self.loadFullBodyModel(self.urdfName, self.rootJointType, self.meshPackageName, self.packageName, self.urdfSuffix, self.srdfSuffix)
        if name != None:
            self.name = name
Pierre Fernbach's avatar
Pierre Fernbach committed
107
108

    def loadAllLimbs(self,heuristic, analysis = None, nbSamples = nbSamples, octreeSize = octreeSize):
Pierre Fernbach's avatar
Pierre Fernbach committed
109
110
111
112
113
114
115
116
117
        if isinstance(heuristic,basestring):#only one heuristic name given assign it to all the limbs
            dict_heuristic = {}
            for id in self.limbs_names:
                dict_heuristic.update({id:heuristic})
        elif isinstance(heuristic,dict):
            dict_heuristic=heuristic
        else : 
            raise Exception("heuristic should be either a string or a map limbId:string")
        #dict_heuristic = {self.rLegId:"static", self.lLegId:"static", self.rArmId:"fixedStep04", self.lArmId:"fixedStep04"}
Pierre Fernbach's avatar
Pierre Fernbach committed
118
        for id in self.limbs_names:
Pierre Fernbach's avatar
Pierre Fernbach committed
119
            print "add limb : ",id
Pierre Fernbach's avatar
Pierre Fernbach committed
120
            eff = self.dict_limb_joint[id]
Pierre Fernbach's avatar
Pierre Fernbach committed
121
            print "effector name = ",eff
Pierre Fernbach's avatar
Pierre Fernbach committed
122
            self.addLimb(id,self.dict_limb_rootJoint[id],eff,self.dict_offset[eff].translation.T.tolist()[0],self.dict_normal[eff],self.dict_size[eff][0]/2.,self.dict_size[eff][1]/2.,nbSamples,dict_heuristic[id],octreeSize,self.cType,kinematicConstraintsPath=self.kinematicConstraintsPath+self.dict_limb_rootJoint[id]+"06_com_constraints.obj",limbOffset=self.dict_limb_offset[id],kinematicConstraintsMin=self.minDist)
Pierre Fernbach's avatar
Pierre Fernbach committed
123
124
125
            if analysis :
                self.runLimbSampleAnalysis(id, analysis, True)