Script demo_gaitCyclePlan_py
|
|
1 from joy import *
2
4 SHEET = loadCSV("M4ModLab.csv")
5
8
10 if self.robot is not None:
11 self.plan = GaitCyclePlan( self, self.SHEET, maxFreq = 0.3,
12 x='front/@set_pos', y='rear/@set_pos')
13 elif self.scr is not None:
14 self.plan = GaitCyclePlan( self, self.SHEET, maxFreq = 0.3,
15 x=('>catX',lambda x : x/2), y=('>catY',lambda x : -x/2))
16 else:
17 raise RuntimeError("Must initialize either Scratch or Robot outputs")
18 self.plan.onStart = curry(progress,">>> START")
19 self.plan.onStop = curry(progress,">>> STOP")
20 self.plan.setFrequency(0.2)
21
23 if evt.type==KEYDOWN:
24 if evt.key in [ord('q'),27]:
25 self.stop()
26
27 elif evt.key==ord(' '):
28 self.plan.setPeriod(0)
29 progress('Stopped motion')
30
31 elif evt.key in (ord(','),ord('.')):
32 f = self.plan.getFrequency()
33
34 if evt.key==ord(','):
35 f -= 0.03
36 else:
37 f += 0.03
38 self.plan.setFrequency(f)
39 progress('Frequency changed to %.2f Hz' % self.plan.getFrequency())
40
41 elif evt.key==ord('h'):
42 progress( "HELP: ',' to decrease/reverse period; '.' opposite; ' ' stop; 'q' end program; 'h' this help; other keys start Plan" )
43
44 elif evt.key in range(ord('0'),ord('9')+1):
45 self.plan.setFrequency(0)
46 phi = ('1234567890'.find(chr(evt.key)))/9.0
47 self.plan.moveToPhase( phi )
48 progress('Moved to phase %.2f' % phi)
49 else:
50 progress( "Starting cycles...." )
51 self.plan.start()
52
53 if evt.type!=TIMEREVENT:
54 JoyApp.onEvent(self,evt)
55
56 if __name__=="__main__":
57 print """
58 Demo of SheetPlan class
59 -----------------------
60
61 Use this demo with the demo-plans.sb Scratch project.
62
63 When any key is pressed, starts a SheetPlan making the
64 cat move around a square.
65
66 The application can be terminated with 'q' or [esc]
67 """
68 import joy
69 app=GaitCyclePlanApp()
70 app.run()
71