Advertisement
safoura

Manager.py

Nov 28th, 2011
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. import sys
  2. import weDoCalls
  3. import time
  4.  
  5.  
  6. print "hello manager"
  7. weDo=weDoCalls.WeDoTalk()
  8. print "weDo connection"
  9. argBuffer=sys.stdin.readline()
  10. tokenList=[]
  11. tokenList=argBuffer.rsplit(",")
  12. tokenList.pop(len(tokenList)-1)
  13. print tokenList
  14.  
  15. i=0
  16.  
  17. while tokenList[i] is not None :#i < (len(tokenList)-1)
  18. print "manager->"+tokenList[i]
  19.  
  20. if tokenList[i].strip() == "MON":
  21. weDo.SetMotors(tokenList[i+1].strip())
  22. j=i+1
  23. elif tokenList[i].strip() == "FORWARD":
  24. weDo.Forward(tokenList[i+1].strip())
  25. j=i+1
  26. elif tokenList[i].strip() == "BACKWARD":
  27. weDo.Backward(tokenList[i+1].strip())
  28. j=i+1
  29. elif tokenList[i].strip() == "MOF":
  30. weDo.SetMotors(0)
  31. j=i+1
  32. elif tokenList[i].strip() == "TURN RIGHT":
  33. weDo.TurnRight(tokenList[i+1].strip())
  34. j=i+1
  35. elif tokenList[i].strip() == "TURN LEFT":
  36. weDo.TurnLeft(tokenList[i+1].strip())
  37. j=i+1
  38. elif tokenList[i].strip() == "BEEP":
  39. weDo.Beep()
  40. j=i
  41. elif tokenList[i].strip() == "SING":
  42. weDo.Sing()
  43. j=i
  44. elif tokenList[i].strip() == "SHAKE":
  45. weDo.Shake()
  46. j=i
  47. elif tokenList[i].strip() == "SPIN":
  48. weDo.Spin()
  49. j=i
  50. elif tokenList[i].strip() == "WAIT":
  51. weDo.Wait(tokenList[i+1].strip())
  52. j=i+1
  53. elif tokenList[i].strip() == "REP":
  54. j=i+2
  55. str=tokenList[i+1].strip()
  56. #while j<len(tokenList):
  57. while tokenList[j] != "ENDREPBLOCK":
  58. str=str+","
  59. str=str+tokenList[j].strip()
  60. j= j+1
  61.  
  62.  
  63. # while tokenList[j] != "ENDREP":
  64. # str=str+","
  65. # str=str+tokenList[j].strip()
  66. # j= j+1
  67. # str=str+","
  68. ## str=str+tokenList[j].strip()
  69. weDo.Repeat(str)
  70. elif tokenList[i].strip() == "IF":
  71. j=i+2
  72. str=tokenList[i+1].strip()
  73. #while j<len(tokenList):
  74. while tokenList[j] != "ENDIFBLOCK":
  75. str=str+","
  76. str=str+tokenList[j].strip()
  77. j= j+1
  78.  
  79. # while tokenList[j] != "ENDIF":
  80. # str=str+","
  81. # str=str+tokenList[j].strip()
  82. # j= j+1
  83. # str=str+","
  84. # str=str+tokenList[j].strip()
  85. # if j< (len(tokenList)-1):
  86. # if (tokenList[j+1] == "ELSE"):
  87. # j=j+1
  88.  
  89. # while tokenList[j] != "END-ELSE":
  90. # str=str+","
  91. # str=str+tokenList[j].strip()
  92. # j= j+1
  93. # str=str+","
  94. # str=str+tokenList[j].strip()
  95. # print "from manager " + str
  96. weDo.If(str)
  97. i=j+1
  98. time.sleep(0.2)
  99.  
  100.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement