tablis_setup.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from six.moves import input
4 
5 import sys
6 import time
7 
8 from hrpsys import rtm
9 rtm.nshost = "localhost"
10 rtm.nsport = "15006"
11 rtm.initCORBA()
12 
13 from hrpsys.OpenHRP import * # NOQA
14 import OpenHRP # NOQA
15 
16 from haptics_controller import * # NOQA
18 
19 
20 def findComp(name):
21  timeout_count = 0
22  comp = None
23  while timeout_count < 10:
24  comp = rtm.findRTC(name)
25  if comp is not None and comp.isActive():
26  break
27  print("find Comp wait for " + name)
28  time.sleep(1)
29  timeout_count += 1
30  if comp is None:
31  print("Cannot find component: %s" % name)
32  return comp
33 
34 
36  Groups = {
37  'rleg': [
38  'RLEG_JOINT0',
39  'RLEG_JOINT1',
40  'RLEG_JOINT2',
41  'RLEG_JOINT3',
42  'RLEG_JOINT4',
43  'RLEG_JOINT5'
44  ],
45  'lleg': [
46  'LLEG_JOINT0',
47  'LLEG_JOINT1',
48  'LLEG_JOINT2',
49  'LLEG_JOINT3',
50  'LLEG_JOINT4',
51  'LLEG_JOINT5'
52  ],
53  'torso': [
54  'CHEST_JOINT0'
55  ],
56  'rarm': [
57  'RARM_JOINT0',
58  'RARM_JOINT1',
59  'RARM_JOINT2',
60  'RARM_JOINT3',
61  'RARM_JOINT4',
62  'RARM_JOINT5',
63  'RARM_JOINT6',
64  'RARM_JOINT7'
65  ],
66  'larm': [
67  'LARM_JOINT0',
68  'LARM_JOINT1',
69  'LARM_JOINT2',
70  'LARM_JOINT3',
71  'LARM_JOINT4',
72  'LARM_JOINT5',
73  'LARM_JOINT6',
74  'LARM_JOINT7'
75  ]}
76 
77  rh_svc = rtm.findService(
78  findComp("RobotHardware0"),
79  "RobotHardwareService",
80  "RobotHardwareService",
81  "service0"
82  )._narrow(OpenHRP.RobotHardwareService)
83  seq_svc = rtm.findService(
84  findComp("seq"),
85  "SequencePlayerService",
86  "SequencePlayerService",
87  "service0"
88  )._narrow(OpenHRP.SequencePlayerService)
89  sh_svc = rtm.findService(
90  findComp("sh"),
91  "StateHolderService",
92  "StateHolderService",
93  "service0"
94  )._narrow(OpenHRP.StateHolderService)
95  hc_svc = rtm.findService(
96  findComp("hc"),
97  "SimpleHapticsControllerService",
98  "SimpleHapticsControllerService",
99  "service0"
100  )._narrow(OpenHRP.SimpleHapticsControllerService)
101  log_svc = findComp("log").service("service0")._narrow(
102  OpenHRP.DataLoggerService)
103 
104  def servoOn(self, jname='all', tm=3):
105  self.servoOff()
106 
107  c = False
108  while (c != 'Y' and c != 'y'):
109  c = input("press 'Y' for servo ON and power ON. >> ")
110 
111  # urata system flag resetting for jaxon
112  self.rh_svc.power(jname, OpenHRP.RobotHardwareService.SWITCH_ON)
113  time.sleep(0.01)
114  self.rh_svc.power(jname, OpenHRP.RobotHardwareService.SWITCH_OFF)
115  time.sleep(0.02)
116 
117  self.rh_svc.setServoGainPercentage(jname, 0.0)
118  self.rh_svc.setServoTorqueGainPercentage(jname, 100)
119 
120  # reset JointGroups
121  for k, v in self.Groups.items():
122  self.seq_svc.removeJointGroup(k)
123  for k, v in self.Groups.items():
124  self.seq_svc.waitInterpolationOfGroup(k)
125  for k, v in self.Groups.items():
126  self.seq_svc.addJointGroup(k, v)
127 
128  # move to idle mode for filter type RTCs
129  for rtc_name in ["hc"]:
130  rtc = rtm.findRTC(rtc_name)
131  if rtc:
132  rtc.stop()
133  rtc.start()
134 
135  time.sleep(2)
136  self.sh_svc.goActual()
137  self.seq_svc.setBasePos([0, 0, 1.44], 0.01)
138  time.sleep(0.1)
139  self.rh_svc.power(jname, OpenHRP.RobotHardwareService.SWITCH_ON)
140  time.sleep(0.1)
141  self.rh_svc.servo(jname, OpenHRP.RobotHardwareService.SWITCH_ON)
142  return True
143 
144  def servoOff(self, jname='all'):
145  c = False
146  while (c != 'Y' and c != 'y'):
147  c = input("press 'Y' for servo OFF and power OFF. >> ")
148 
149  self.rh_svc.servo('all', OpenHRP.RobotHardwareService.SWITCH_OFF)
150  time.sleep(0.2)
151  if jname == 'all':
152  self.rh_svc.power('all', OpenHRP.RobotHardwareService.SWITCH_OFF)
153  return True
154 
156  # ast setting
157  hcp = self.hc_svc.getHapticsControllerParam()[1]
158  hcp.max_torque = [
159  20, 80, 80, 80, 20, 20,
160  20, 80, 80, 80, 20, 20,
161  40,
162  30, 30, 20, 20, 12, 8, 8, 6,
163  30, 30, 20, 20, 12, 8, 8, 6
164  ]
165  hcp.qref_dgain = 10.0 # simulator only
166  self.hc_svc.setHapticsControllerParam(hcp)
167 
168  def setupLogger(self):
169  self.log_svc.add("TimedDoubleSeq", "RobotHardware0_q")
170  rtm.connectPorts(
171  rtm.findRTC("RobotHardware0").port("q"),
172  rtm.findRTC("log").port("RobotHardware0_q")
173  )
174  self.log_svc.add("TimedDoubleSeq", "RobotHardware0_dq")
175  rtm.connectPorts(
176  rtm.findRTC("RobotHardware0").port("dq"),
177  rtm.findRTC("log").port("RobotHardware0_dq")
178  )
179  self.log_svc.add("TimedDoubleSeq", "RobotHardware0_tau")
180  rtm.connectPorts(
181  rtm.findRTC("RobotHardware0").port("tau"),
182  rtm.findRTC("log").port("RobotHardware0_tau")
183  )
184  self.log_svc.add("TimedLongSeqSeq", "RobotHardware0_servoState")
185  rtm.connectPorts(
186  rtm.findRTC("RobotHardware0").port("servoState"),
187  rtm.findRTC("log").port("RobotHardware0_servoState")
188  )
189  self.log_svc.add("TimedDoubleSeq", "hc_genTauOut")
190  rtm.connectPorts(
191  rtm.findRTC("hc").port("genTauOut"),
192  rtm.findRTC("log").port("hc_genTauOut")
193  )
194  for ee in ["rleg", "lleg", "rarm", "larm", "relbow", "lelbow"]:
195  self.log_svc.add("TimedPose3D", "hc_act" + ee + "PoseOut")
196  rtm.connectPorts(
197  rtm.findRTC("hc").port("act" + ee + "PoseOut"),
198  rtm.findRTC("log").port("hc_act" + ee + "PoseOut")
199  )
200  self.log_svc.maxLength(1000 * 60)
201  self.log_svc.clear()
202 
203  def init(self):
204  for j in self.Groups["rleg"] + self.Groups["lleg"] \
205  + self.Groups["torso"] + self.Groups["rarm"] \
206  + self.Groups["larm"]:
207  self.rh_svc.setJointControlMode(
208  j, OpenHRP.RobotHardwareService.TORQUE)
209  self.rh_svc.setServoErrorLimit(j, 0.0)
210  self.rh_svc.setServoTorqueGainPercentage(j, 100)
211  self.rh_svc.setServoGainPercentage(j, 0.0)
212 
213  self.setupLogger()
214  self.seq_svc.setBasePos([0, 0, 1.44], 2.0)
215  self.setHcParametersJAXON()
216 
217 
218 if __name__ == '__main__':
220 
221  if len(sys.argv) > 1 and sys.argv[1] == "init":
222  hcf.init()
tablis_setup.TABLIS_Configurator.setupLogger
def setupLogger(self)
Definition: tablis_setup.py:168
SimpleHapticsControllerService_idl
tablis_setup.TABLIS_Configurator.rh_svc
rh_svc
Definition: tablis_setup.py:77
tablis_setup.TABLIS_Configurator.hc_svc
hc_svc
Definition: tablis_setup.py:95
tablis_setup.TABLIS_Configurator.init
def init(self)
Definition: tablis_setup.py:203
tablis_setup.TABLIS_Configurator
Definition: tablis_setup.py:35
OpenHRP
tablis_setup.TABLIS_Configurator.Groups
dictionary Groups
Definition: tablis_setup.py:36
tablis_setup.TABLIS_Configurator.setHcParametersJAXON
def setHcParametersJAXON(self)
Definition: tablis_setup.py:155
tablis_setup.TABLIS_Configurator.log_svc
log_svc
Definition: tablis_setup.py:101
tablis_setup.TABLIS_Configurator.sh_svc
sh_svc
Definition: tablis_setup.py:89
tablis_setup.TABLIS_Configurator.servoOn
def servoOn(self, jname='all', tm=3)
Definition: tablis_setup.py:104
tablis_setup.TABLIS_Configurator.servoOff
def servoOff(self, jname='all')
Definition: tablis_setup.py:144
tablis_setup.TABLIS_Configurator.seq_svc
seq_svc
Definition: tablis_setup.py:83
tablis_setup.findComp
def findComp(name)
Definition: tablis_setup.py:20


eus_teleop
Author(s): Shingo Kitagawa
autogenerated on Mon Dec 9 2024 04:10:50