7 print "import without hrpsys" 12 from waitInput
import *
17 global hcf, init_pose, reset_pose, wrench_command0, wrench_command1, hrpsys_version
18 hcf = HrpsysConfigurator()
19 hcf.getRTCList = hcf.getRTCListUnstable
20 hcf.init (
"SampleRobot(Robot)0",
"$(PROJECT_DIR)/../model/sample1.wrl")
22 for sen
in filter(
lambda x: x.type ==
"Force", hcf.sensors):
23 hcf.connectLoggerPort(hcf.es, sen.name+
"Out")
25 reset_pose = [0.0,-0.772215,0.0,1.8338,-1.06158,0.0,0.523599,0.0,0.0,-2.44346,0.15708,-0.113446,0.637045,0.0,-0.772215,0.0,1.8338,-1.06158,0.0,0.523599,0.0,0.0,-2.44346,-0.15708,-0.113446,-0.637045,0.0,0.0,0.0]
26 wrench_command0 = [0.0]*24
27 wrench_command1 = [1.0]*24
28 hrpsys_version = hcf.seq.ref.get_component_profile().version
29 print(
"hrpsys_version = %s"%hrpsys_version)
32 return sum([abs(i-j)
for (i,j)
in zip(angle1,angle2)])
38 hcf.setMaxLogLength(1);hcf.clearLog();time.sleep(0.1);hcf.saveLog(log_fname)
40 def checkParameterFromLog(port_name, log_fname="/tmp/test-samplerobot-emergency-stopper-check-param", save_log=True, rtc_name="es"):
43 return map(float, open(log_fname+
"."+rtc_name+
"_"+port_name,
"r").readline().split(" ")[1:-1])
47 return reduce(
lambda x,y: x+y, (
map(
lambda fs :
checkParameterFromLog(fs+
"Out", save_log=
False), [
'lfsensor',
'rfsensor',
'lhsensor',
'rhsensor'])))
51 print >> sys.stderr,
"1. test stopMotion and releaseMotion for joint angle" 52 hcf.es_svc.releaseMotion()
53 hcf.seq_svc.setJointAngles(init_pose, 1.0)
54 hcf.waitInterpolation()
56 tmp_angle1 = hcf.getActualState().angle
58 hcf.seq_svc.setJointAngles(reset_pose, play_time)
59 print >> sys.stderr,
" send angle_vector of %d [sec]" % play_time
61 print >> sys.stderr,
" check whether robot pose is changing" 62 tmp_angle2 = hcf.getActualState().angle
64 print >> sys.stderr,
" => robot is moving." 66 print >> sys.stderr,
" stop motion" 67 hcf.es_svc.stopMotion()
69 print >> sys.stderr,
" check whether robot pose remained still" 70 tmp_angle1 = hcf.getActualState().angle
72 tmp_angle2 = hcf.getActualState().angle
74 print >> sys.stderr,
" => robot is not moving. stopMotion is working succesfully." 76 print >> sys.stderr,
" release motion" 77 hcf.es_svc.releaseMotion()
78 print >> sys.stderr,
" check whether robot pose changed" 79 tmp_angle1 = hcf.getActualState().angle
80 hcf.waitInterpolation()
82 tmp_angle2 = hcf.getActualState().angle
84 print >> sys.stderr,
" => robot is moving. releaseMotion is working succesfully." 86 hcf.es_svc.releaseMotion()
87 hcf.seq_svc.setJointAngles(init_pose, 1.0)
88 hcf.waitInterpolation()
91 print >> sys.stderr,
"1. test stopMotion and releaseMotion with key interaction for joint angle" 92 pose_list = [reset_pose, init_pose] * 4
94 hcf.seq_svc.playPattern(pose_list, [[0,0,0]]*len(pose_list), [[0,0,0]]*len(pose_list), [play_time]*len(pose_list))
95 print >> sys.stderr,
" send angle_vector_sequence of %d [sec]" % (play_time*len(pose_list))
96 print >> sys.stderr,
" press Enter to stop / release motion" 99 print >> sys.stderr,
" stop motion" 100 hcf.es_svc.stopMotion()
101 if hcf.seq_svc.isEmpty():
break 103 print >> sys.stderr,
" release motion" 104 hcf.es_svc.releaseMotion()
105 if hcf.seq_svc.isEmpty():
break 106 hcf.es_svc.releaseMotion()
109 print >> sys.stderr,
"2. test stopMotion and releaseMotion for wrench" 110 hcf.es_svc.releaseMotion()
111 hcf.seq_svc.setJointAngles(init_pose, 1.0)
112 hcf.seq_svc.setWrenches(wrench_command0, 1.0)
113 hcf.waitInterpolation()
117 hcf.seq_svc.setWrenches(wrench_command1, play_time)
118 print >> sys.stderr,
" send wrench command of %d [sec]" % play_time
120 print >> sys.stderr,
" check whether wrench is changing" 123 print >> sys.stderr,
" => wrench is changing." 125 print >> sys.stderr,
" stop motion" 126 hcf.es_svc.stopMotion()
128 print >> sys.stderr,
" check whether wrench remained still" 133 print >> sys.stderr,
" => wrench is not changing. stopMotion is working succesfully." 135 print >> sys.stderr,
" release motion" 136 hcf.es_svc.releaseMotion()
137 print >> sys.stderr,
" check whether wrench changed" 139 hcf.waitInterpolation()
143 print >> sys.stderr,
" => wrench is changing. releaseMotion is working succesfully." 145 hcf.es_svc.releaseMotion()
146 hcf.seq_svc.setWrenches(wrench_command0, 1.0)
147 hcf.waitInterpolation()
150 print >> sys.stderr,
"3. test transition to release mode when deactivated" 151 print >> sys.stderr,
" stop motion" 152 hcf.es_svc.stopMotion()
153 hcf.hes_svc.stopMotion()
154 if((hcf.es_svc.getEmergencyStopperParam()[1].is_stop_mode ==
True)
and (hcf.hes_svc.getEmergencyStopperParam()[1].is_stop_mode ==
True)):
155 print >> sys.stderr,
" emergency stopper become stop mode succesfully" 156 print >> sys.stderr,
" deactivate and activate es and hes" 161 if((hcf.es_svc.getEmergencyStopperParam()[1].is_stop_mode ==
False)
and (hcf.hes_svc.getEmergencyStopperParam()[1].is_stop_mode ==
False)):
162 print >> sys.stderr,
" emergency stopper become release mode succesfully" 163 assert((hcf.es_svc.getEmergencyStopperParam()[1].is_stop_mode ==
False)
and (hcf.hes_svc.getEmergencyStopperParam()[1].is_stop_mode ==
False))
165 def demo(key_interaction=False):
167 from distutils.version
import StrictVersion
168 if StrictVersion(hrpsys_version) >= StrictVersion(
'315.6.0'):
176 if __name__ ==
'__main__':
def demoEmergencyStopReleaseWhenDeactivated()
def demoEmergencyStopWrench()
def arrayDistance(angle1, angle2)
def arrayApproxEqual(angle1, angle2, thre=1e-3)
def demoEmergencyStopJointAngle()
def checkParameterFromLog(port_name, log_fname="/tmp/test-samplerobot-emergency-stopper-check-param", save_log=True, rtc_name="es")
def demoEmergencyStopJointAngleWithKeyInteracton()
def demo(key_interaction=False)
def saveLogForCheckParameter(log_fname="/tmp/test-samplerobot-emergency-stopper-check-param")