samplerobot_data_logger.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 try:
4  from hrpsys.hrpsys_config import *
5  import OpenHRP
6 except:
7  print "import without hrpsys"
8  import rtm
9  from rtm import *
10  from OpenHRP import *
11  import waitInput
12  from waitInput import *
13  import socket
14  import time
15 
16 def init ():
17  global hcf, initial_pose
18  hcf = HrpsysConfigurator()
19  hcf.getRTCList = hcf.getRTCListUnstable
20  hcf.log_use_own_ec = True ### use own ec for simulation
21  hcf.init ("SampleRobot(Robot)0", "$(PROJECT_DIR)/../model/sample1.wrl")
22  # set initial pose from sample/controller/SampleController/etc/Sample.pos
23  initial_pose = [-7.779e-005, -0.378613, -0.000209793, 0.832038, -0.452564, 0.000244781, 0.31129, -0.159481, -0.115399, -0.636277, 0, 0, 0, -7.77902e-005, -0.378613, -0.000209794, 0.832038, -0.452564, 0.000244781, 0.31129, 0.159481, 0.115399, -0.636277, 0, 0, 0, 0, 0, 0]
24  hcf.seq_svc.setJointAngles(initial_pose, 2.0)
25  hcf.waitInterpolation()
26 
28  print >> sys.stderr, "1. Save log"
29  # Save log files for each ports as /tmp/test-samplerobot-log.*
30  # file names are /tmp/test-samplerobot-log.[RTCName]_[PortName], c.f., /tmp/test-samplerobot-log.sh_qOut ... etc
31  hcf.saveLog("/tmp/test-samplerobot-log")
32  ret = os.path.exists("/tmp/test-samplerobot-log.sh_qOut")
33  if ret:
34  print >> sys.stderr, " save() =>OK"
35  assert(ret is True)
36 
38  print >> sys.stderr, "2. Clear buffer"
39  hcf.clearLog()
40  print >> sys.stderr, " clear() =>OK"
41  assert(True)
42 
44  print >> sys.stderr, "3. Set max ring-buffer length : 100 [loop] * 0.002 [s] = 0.2 [s] data"
45  hcf.setMaxLogLength(100)
46  hcf.seq_svc.setJointAngles(initial_pose, 0.2) # wait
47  hcf.waitInterpolation()
48  hcf.saveLog("/tmp/test-samplerobot-log")
49  from subprocess import check_output
50  ret = check_output(['wc', '-l', '/tmp/test-samplerobot-log.sh_qOut']).split(" ")[0] == '100'
51  if ret:
52  print >> sys.stderr, " maxLength() =>OK"
53  assert(ret is True)
54 
55 def demo ():
56  init()
57  demoSaveLog()
58  demoClearLog()
60 
61 if __name__ == '__main__':
62  demo()


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Thu May 6 2021 02:41:51