/lib/phasespace/src/examples/example1.py

https://github.com/hojonathanho/bulletsim
Python | 74 lines | 40 code | 18 blank | 16 comment | 15 complexity | 5a6fceb9edb7da7ba77846d451b51030 MD5 | raw file
  1. #!/usr/bin/python
  2. # example1.py
  3. # simple point tracking program
  4. import sys
  5. from OWL import *
  6. # change these to match your configuration
  7. MARKER_COUNT = 4
  8. SERVER_NAME = "localhost"
  9. INIT_FLAGS = 0
  10. if(owlInit(SERVER_NAME, INIT_FLAGS) < 0):
  11. print "init error: ", owlGetError()
  12. sys.exit(0)
  13. # create tracker 0
  14. tracker = 0
  15. owlTrackeri(tracker, OWL_CREATE, OWL_POINT_TRACKER)
  16. # set markers
  17. for i in range(MARKER_COUNT):
  18. owlMarkeri(MARKER(tracker, i), OWL_SET_LED, i)
  19. # activate tracker
  20. owlTracker(tracker, OWL_ENABLE)
  21. # flush requests and check for errors
  22. if(owlGetStatus() == 0):
  23. owl_print_error("error in point tracker setup", owlGetError())
  24. sys.exit(0)
  25. # set define frequency
  26. owlSetFloat(OWL_FREQUENCY, OWL_MAX_FREQUENCY)
  27. # start streaming
  28. owlSetInteger(OWL_STREAMING, OWL_ENABLE)
  29. # main loop
  30. while(1):
  31. markers = []
  32. # get some markers
  33. n = owlGetMarkers(markers, 32)
  34. # check for error
  35. err = owlGetError()
  36. if(err != OWL_NO_ERROR):
  37. owl_print_error("error", err)
  38. break
  39. # no data yet
  40. if(n == 0): continue
  41. if(n > 0):
  42. print n, "markers(s):"
  43. for i in range(n):
  44. if(markers[i].cond > 0):
  45. print "%d) %.2f %.2f %.2f" % (i, markers[i].x, markers[i].y, markers[i].z)
  46. print ""
  47. # cleanup
  48. owlDone();
  49. def owl_print_error(s, n):
  50. """Print OWL error."""
  51. if(n < 0): print "%s: %d" % (s, n)
  52. elif(n == OWL_NO_ERROR): print "%s: No Error" % s
  53. elif(n == OWL_INVALID_VALUE): print "%s: Invalid Value" % s
  54. elif(n == OWL_INVALID_ENUM): print "%s: Invalid Enum" % s
  55. elif(n == OWL_INVALID_OPERATION): print "%s: Invalid Operation" % s
  56. else: print "%s: 0x%x" % (s, n)