Script demo_sheetPlan_py
[hide private]
[frames] | no frames]

Source Code for Script script-demo_sheetPlan_py

 1  from joy import * 
 2   
3 -class SheetPlanApp( JoyApp ):
4 SHEET = loadCSV("demos/M4ModLab.csv") 5
6 - def __init__(self,bind,*arg,**kw):
7 JoyApp.__init__(self,*arg,**kw) 8 self.bind = bind
9
10 - def onStart( self ):
11 self.plan = SheetPlan( self, self.SHEET, **self.bind)
12
13 - def onEvent(self, evt):
14 if evt.type==KEYDOWN and evt.key in [27,ord('q')]: 15 self.stop() 16 elif evt.type==KEYDOWN or evt.type==JOYBUTTONDOWN: 17 self.plan.start()
18 19 if __name__=="__main__": 20 print """ 21 Demo of SheetPlan class 22 ----------------------- 23 24 Can be used in three modes: 25 26 In default, debug mode -- outputs to the screen 27 28 With a robot, use the --withRobot or -r switches and set up your JoyApp.yml to map some robot nodes to 'front' and 'rear'. Those nodes will move according to the gait table in the csv file. 29 30 With scratch, use the --withScratch or -s switches, after starting Scratch with the demo-plans.sb Scratch project in another window. Click on the green flag to start the cat drawing. The cat will move according to the gait table in the csv file. 31 32 When any key is pressed, starts the SheetPlan moving through the gait table. 33 34 The application can be terminated with 'q' or [esc] 35 """ 36 import sys 37 app = None 38 if len(sys.argv)>1: 39 if sys.argv[1]=='--withRobot' or sys.argv[1]=='-r': 40 app = SheetPlanApp(bind=dict( 41 x='front/@set_pos', y='rear/@set_pos'), 42 robot={} ) 43 elif sys.argv[1]=='--withScratch' or sys.argv[1]=='-s': 44 app = SheetPlanApp(bind=dict( 45 x='>catX', y='>catY'), 46 scr={} ) 47 if app is None: 48 app = SheetPlanApp(bind=dict(x="#x ", y="#y ")) 49 app.run() 50