Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hironx_ros_bridge/src/hironx_ros_bridge/command_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

import os
try: # Python2
from urlparse import urlparse
from urllib.parse import urlparse
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block is expected to fail on python3 environment.

except ImportError: # Python3
from urllib.parse import urlparse

Expand Down
67 changes: 34 additions & 33 deletions hironx_ros_bridge/src/hironx_ros_bridge/hironx_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import time

import roslib
from functools import reduce
roslib.load_manifest("hrpsys")
from hrpsys.hrpsys_config import *

Expand All @@ -48,7 +49,7 @@
# all connection(?) conect respenct giopMaxMsgSize
# But on 18.04 (omniorb4-dev 4.2) wnneed to set ORBgiopMaxMsgSize=2147483648
# for each clients
if not os.environ.has_key('ORBgiopMaxMsgSize'):
if 'ORBgiopMaxMsgSize' not in os.environ:
os.environ['ORBgiopMaxMsgSize'] = '2147483648'

import OpenHRP
Expand Down Expand Up @@ -81,7 +82,7 @@ def delete_module(modname, paranoid=None):
else:
these_symbols = paranoid[:]
del modules[modname]
for mod in modules.values():
for mod in list(modules.values()):
try:
delattr(mod, modname)
except AttributeError:
Expand Down Expand Up @@ -249,7 +250,7 @@ def setTargetPose(self, gname, pos, rpy, tm, frame_name=None):
# This method should be removed as part of
# https://github.com/start-jsk/rtmros_hironx/pull/470, once
# https://github.com/fkanehiro/hrpsys-base/pull/1063 resolves.
if gname.upper() not in map (lambda x : x[0].upper(), self.Groups):
if gname.upper() not in [x[0].upper() for x in self.Groups]:
print("setTargetPose failed. {} is not available in the kinematic groups. "
"Check available Groups (by e.g. self.Groups/robot.Groups). ".format(gname))
return False
Expand Down Expand Up @@ -347,13 +348,13 @@ def init(self, robotname="HiroNX(Robot)0", url=""):

print(self.configurator_name + "finding RTCManager and RobotHardware")
HrpsysConfigurator.waitForRTCManagerAndRoboHardware(self, robotname=robotname)
print self.configurator_name, "Hrpsys controller version info: "
print(self.configurator_name, "Hrpsys controller version info: ")
if self.ms :
print self.configurator_name, " ms = ", self.ms
print(self.configurator_name, " ms = ", self.ms)
if self.ms and self.ms.ref :
print self.configurator_name, " ref = ", self.ms.ref
print(self.configurator_name, " ref = ", self.ms.ref)
if self.ms and self.ms.ref and len(self.ms.ref.get_component_profiles()) > 0:
print self.configurator_name, " version = ", self.ms.ref.get_component_profiles()[0].version
print(self.configurator_name, " version = ", self.ms.ref.get_component_profiles()[0].version)
if self.ms and self.ms.ref and len(self.ms.ref.get_component_profiles()) > 0 and StrictVersion(self.ms.ref.get_component_profiles()[0].version) < StrictVersion('315.2.0'):
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), 'hrpsys_315_1_9/hrpsys'))
delete_module('ImpedanceControllerService_idl')
Expand Down Expand Up @@ -505,7 +506,7 @@ def getRTCList(self):
elif "AbsoluteForceSensor" in self.ms.get_factory_names():
rtclist.append(['rmfo', "AbsoluteForceSensor"])
else:
print "Component rmfo is not loadable."
print("Component rmfo is not loadable.")
return rtclist

# hand interface
Expand Down Expand Up @@ -562,7 +563,7 @@ def setHandEffort(self, effort=100):
@type effort: int
'''

for i in [v for vs in self.HandGroups.values() for v in vs]: # flatten
for i in [v for vs in list(self.HandGroups.values()) for v in vs]: # flatten
self.sc_svc.setMaxTorque(i, effort)

def setHandWidth(self, hand, width, tm=1, effort=None):
Expand All @@ -582,7 +583,7 @@ def setHandWidth(self, hand, width, tm=1, effort=None):
if hand:
self.setHandJointAngles(hand, self.hand_width2angles(width), tm)
else:
for h in self.HandGroups.keys():
for h in list(self.HandGroups.keys()):
self.setHandJointAngles(h, self.hand_width2angles(width), tm)

def moveHand(self, hand, av, tm=1): # direction av: + for open, - for close
Expand Down Expand Up @@ -633,7 +634,7 @@ def setSelfGroups(self):
# natural if it accepts it.
for item in self.Groups:
self.seq_svc.addJointGroup(item[0], item[1])
for k, v in self.HandGroups.iteritems():
for k, v in self.HandGroups.items():
if self.sc_svc:
self.sc_svc.addJointGroup(k, v)

Expand Down Expand Up @@ -677,7 +678,7 @@ def isServoOn(self, jname='any'):
return False
else:
jid = eval('self.' + jname)
print self.configurator_name, s_s[jid]
print(self.configurator_name, s_s[jid])
if s_s[jid][0] & 1 == 0:
return False
return True
Expand Down Expand Up @@ -793,25 +794,25 @@ def servoOn(self, jname='all', destroy=1, tm=3):
time.sleep(2)
# time.sleep(7)
if not self.isServoOn(jname):
print self.configurator_name, 'servo on failed.'
print(self.configurator_name, 'servo on failed.')
raise
except:
print self.configurator_name, 'exception occured'
print(self.configurator_name, 'exception occured')

try:
angles = self.flat2Groups(map(numpy.rad2deg,
self.getActualState().angle))
print 'Move to Actual State, Just a minute.'
angles = self.flat2Groups(list(map(numpy.rad2deg,
self.getActualState().angle)))
print('Move to Actual State, Just a minute.')
for i in range(len(self.Groups)):
self.setJointAnglesOfGroup(self.Groups[i][0], angles[i], tm,
wait=False)
for i in range(len(self.Groups)):
self.seq_svc.waitInterpolationOfGroup(self.Groups[i][0])
except:
print self.configurator_name, 'post servo on motion trouble'
print(self.configurator_name, 'post servo on motion trouble')

# turn on hand motors
print 'Turn on Hand Servo'
print('Turn on Hand Servo')
if self.sc_svc:
is_servoon = self.sc_svc.servoOn()
print('Hands Servo on: ' + str(is_servoon))
Expand All @@ -838,10 +839,10 @@ def servoOff(self, jname='all', wait=True):
'''
# do nothing for simulation
if self.simulation_mode:
print self.configurator_name, 'omit servo off'
print(self.configurator_name, 'omit servo off')
return 0

print 'Turn off Hand Servo'
print('Turn off Hand Servo')
if self.sc_svc:
self.sc_svc.servoOff()
# if the servos aren't on switch power off
Expand All @@ -866,13 +867,13 @@ def servoOff(self, jname='all', wait=True):
self.rh_svc.power('all', SWITCH_OFF)

# turn off hand motors
print 'Turn off Hand Servo'
print('Turn off Hand Servo')
if self.sc_svc:
self.sc_svc.servoOff()

return 2
except:
print self.configurator_name, 'servo off: communication error'
print(self.configurator_name, 'servo off: communication error')
return -1

def checkEncoders(self, jname='all', option=''):
Expand Down Expand Up @@ -911,15 +912,15 @@ def checkEncoders(self, jname='all', option=''):
try:
waitInputConfirm(msg)
except:
print "If you're connecting to the robot from remote, " + \
"make sure tunnel X (eg. -X option with ssh)."
print("If you're connecting to the robot from remote, " + \
"make sure tunnel X (eg. -X option with ssh).")
self.rh_svc.power('all', SWITCH_OFF)
return 0

is_result_hw = True
print self.configurator_name, 'calib-joint ' + jname + ' ' + option
print(self.configurator_name, 'calib-joint ' + jname + ' ' + option)
self.rh_svc.initializeJointAngle(jname, option)
print self.configurator_name, 'done'
print(self.configurator_name, 'done')
is_result_hw = is_result_hw and self.rh_svc.power('all', SWITCH_OFF)
self.goActual() # This needs to happen before turning servo on.
time.sleep(0.1)
Expand All @@ -928,7 +929,7 @@ def checkEncoders(self, jname='all', option=''):
# The step described in the following msg is confirmed by the manufacturer 12/14/2015
print("Turning servos ({}) failed. This is likely because of issues happening in lower level. Please check if the Kawada's proprietary tool NextageOpenSupervisor returns without issue or not. If the issue persists, contact the manufacturer.".format(jname))
# turn on hand motors
print 'Turn on Hand Servo'
print('Turn on Hand Servo')
if self.sc_svc:
self.sc_svc.servoOn()

Expand Down Expand Up @@ -966,7 +967,7 @@ def startImpedance_315_1(self, arm,
ic_sensor_name = 'lhsensor'
ic_target_name = 'LARM_JOINT5'
else:
print 'startImpedance: argument must be rarm or larm.'
print('startImpedance: argument must be rarm or larm.')
return

self.ic_svc.setImpedanceControllerParam(
Expand Down Expand Up @@ -996,7 +997,7 @@ def stopImpedance_315_1(self, arm):
elif arm == 'larm':
ic_sensor_name = 'lhsensor'
else:
print 'startImpedance: argument must be rarm or larm.'
print('startImpedance: argument must be rarm or larm.')
return
self.ic_svc.deleteImpedanceControllerAndWait(ic_sensor_name)

Expand Down Expand Up @@ -1161,8 +1162,8 @@ def getJointAnglesOfGroup(self, limb):
for i in range(len(groups)):
if groups[i][0] == limb:
return angles[i]
print self.configurator_name, 'could not find limb name ' + limb
print self.configurator_name, ' in' + filter(lambda x: x[0], groups)
print(self.configurator_name, 'could not find limb name ' + limb)
print(self.configurator_name, ' in' + [x for x in groups if x[0]])

def clearOfGroup(self, limb):
'''!@brief
Expand All @@ -1174,5 +1175,5 @@ def clearOfGroup(self, limb):
'software version ' + self.seq_version)
HrpsysConfigurator.clearOfGroup(self, limb)
angles = self.getJointAnglesOfGroup(limb)
print self.configurator_name, 'clearOfGroup(' + limb + ') will send ' + str(angles) + ' to update seqplay until https://github.com/fkanehiro/hrpsys-base/pull/1141 is available'
print(self.configurator_name, 'clearOfGroup(' + limb + ') will send ' + str(angles) + ' to update seqplay until https://github.com/fkanehiro/hrpsys-base/pull/1141 is available')
self.setJointAnglesOfGroup(limb, angles, 0.1, wait=True)
8 changes: 4 additions & 4 deletions hironx_ros_bridge/src/hironx_ros_bridge/old_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ def setTargetAngular(self, group_name, x, y, z, r, p, w, rate=10.0, wait=True):
scaling_factor_translation = 50
scaling_factor_rotation = 5
x_now, y_now, z_now, r_now, p_now, w_now = self.getCurrentConfiguration(joint_name)
translation_distances = map(abs, [x-x_now * scaling_factor_translation,
translation_distances = list(map(abs, [x-x_now * scaling_factor_translation,
y-y_now * scaling_factor_translation,
z-z_now * scaling_factor_translation])
rotation_distances = map(abs, [r-r_now * scaling_factor_rotation,
z-z_now * scaling_factor_translation]))
rotation_distances = list(map(abs, [r-r_now * scaling_factor_rotation,
p-p_now * scaling_factor_rotation,
w-w_now * scaling_factor_rotation])
w-w_now * scaling_factor_rotation]))
max_dist = max(translation_distances + rotation_distances) # This is just concatenated
mvmt_time = max_dist / rate

Expand Down