test-samplerobot.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 PKG = 'hrpsys'
4 NAME = 'test-samplerobot'
5 
6 import imp ## for rosbuild
7 try:
8  imp.find_module(PKG)
9 except:
10  import roslib; roslib.load_manifest(PKG)
11 
12 
13 import os
14 import sys
15 import time
16 import unittest
17 import yaml
18 
19 import rostest
20 from hrpsys import rtm
21 from hrpsys.hrpsys_config import *
22 import OpenHRP
23 
24 rtm.nsport = 2809
25 
26 class SampleRobot(HrpsysConfigurator):
27  def getRTCList(self):
28  return [
29  ['seq', "SequencePlayer"],
30  ['sh', "StateHolder"],
31  ['fk', "ForwardKinematics"],
32  ['log', "DataLogger"],
33  ]
34 
35 
36 
37 class TestJointAngle(unittest.TestCase):
38 
39  @classmethod
40  def setUpClass(self):
41  h = SampleRobot()
42  h.init(robotname="SampleRobot(Robot)0")
43 
45  h = SampleRobot()
46  h.findComps()
47  print >>sys.stderr, "log=",h.log, "log_svc=",h.log_svc
48  self.assertTrue(h.log)
49  self.assertTrue(h.log_svc)
50 
51  def test_load_pattern(self):
52  h = SampleRobot()
53  h.findComps()
54  from subprocess import check_output
55  openhrp3_path = check_output(['rospack','find','openhrp3']).rstrip() # for rosbuild
56  PKG_CONFIG_PATH=""
57  if os.path.exists(os.path.join(openhrp3_path, "bin")) :
58  PKG_CONFIG_PATH='PKG_CONFIG_PATH=%s/lib/pkgconfig:$PKG_CONFIG_PATH'%(openhrp3_path)
59 
60  cmd = "%s pkg-config openhrp3.1 --variable=idl_dir"%(PKG_CONFIG_PATH)
61  os.path.join(check_output(cmd, shell=True).rstrip(), "../sample/controller/SampleController/etc/Sample")
62  h.loadPattern(os.path.join(check_output(cmd, shell=True).rstrip(), "../sample/controller/SampleController/etc/Sample"), 1)
63  self.assertEqual(h.waitInterpolation(), None)
64 
66  h = SampleRobot()
67  h.findComps()
68  self.assertTrue(h.setJointAngles(h.getJointAngles(),1))
69  self.assertEqual(h.waitInterpolation(), None)
70 
71  import random
72  a = [(360*random.random()-180) for i in xrange(len(h.getJointAngles()))]
73  self.assertTrue(h.setJointAngles(a,2))
74  self.assertEqual(h.waitInterpolation(), None)
75 
76  a = [0 for i in xrange(len(h.getJointAngles()))]
77  self.assertTrue(h.setJointAngles(a,2))
78  self.assertEqual(h.waitInterpolation(), None)
79 
80 #unittest.main()
81 if __name__ == '__main__':
82  rostest.run(PKG, NAME, TestJointAngle, sys.argv)
83 
84 


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