ProsthesisNetworkControl.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 import sys, traceback, Ice
3 import IceStorm
4 import time
5 
6 #from bmp280 import BMP280
7 
8 
9 def main():
10  status = 0
11  ic = None
12  prosthesis = None
13  ########################################################## ICE part
14  try:
15  properties = Ice.createProperties(sys.argv)
16  properties.load("./default.generated.cfg")
17  properties.load("./default.cfg")
18 
19  init_data = Ice.InitializationData()
20  init_data.properties = properties
21 
22  ic = Ice.initialize(init_data)
23 
24  Ice.loadSlice('-I%s %s -DMININTERFACE' % (Ice.getSliceDir(), 'KITProstheticHandInterface.ice'))
25 
26  print("loadSlice")
27  import KITProsthesis
28 
29 
30  obj = ic.stringToProxy("IceStorm/TopicManager")
31 
32  print("stringToProxy")
33  base = ic.stringToProxy("KITProsthesisControl -t -e 1.1:tcp -h localhost -p 10000 -t 60000")
34  print("base = ", base.ice_toString())
35  print("cast proxy")
36  prosthesis = KITProsthesis.KITProstheticHandInterfacePrx.checkedCast(base)
37  if not prosthesis:
38  raise RuntimeError("Invalid proxy")
39 
40  except:
41  traceback.print_exc()
42  status = 1
43 
44  if prosthesis is not None:
45  def graspAndStatus(grasp, sleep = 3):
46  prosthesis.sendGrasp(grasp)
47  val = prosthesis.getSensorValues()
48  print("state ", val.state)
49  print("thumbPWM ", val.thumbPWM)
50  print("thumbPos ", val.thumbPos)
51  print("fingerPWM ", val.fingerPWM)
52  print("fingerPos ", val.fingerPos)
53  time.sleep(sleep)
54 
55  graspAndStatus(0)
56  graspAndStatus(1)
57  graspAndStatus(0)
58 
59  if ic:
60  #clean up
61  try:
62  ic.destroy()
63  except:
64  traceback.print_exc()
65  status = 1
66 
67  sys.exit(status)
68 
69 main()
rapidxml::print
OutIt print(OutIt out, const xml_node< Ch > &node, int flags=0)
Prints XML to given output iterator.
Definition: rapidxml_print.hpp:507
Ice::createProperties
Ice::PropertiesPtr createProperties()
ProsthesisNetworkControl.main
def main()
Definition: ProsthesisNetworkControl.py:9