Advertisement
Guest User

Untitled

a guest
Feb 13th, 2013
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.01 KB | None | 0 0
  1. #include "hardware.h"
  2. #include "armbotbuild.h"
  3. #include <Gait/GaitRunner.h>
  4.  
  5. #define SCHEDULER_MAX_JOBS 20 // Set the max number of scheduled jobs
  6.  
  7. int zeroAlreadyPressed = 0;
  8. int oneAlreadyPressed = 0;
  9. int twoAlreadyPressed = 0;
  10.  
  11. int lasttime = 0;
  12. int * data = 0;
  13.  
  14. ACTUATOR_LIST PROGMEM all[] = {&GripperGrabber.actuator,&GripperRotate.actuator,&GripperSideways.actuator,&GripperUpDown.actuator,&ElbowUpDown.actuator,&ShoulderUpDown.actuator,&ShoulderRotate.actuator };
  15.  
  16. G8_RUNNER gait = MAKE_G8_RUNNER(all, animations);
  17.  
  18. void appInitHardware(void) {
  19.     initHardware();
  20.     gaitRunnerInit(&gait);
  21. }
  22.  
  23. TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
  24.     rprintf("Robot Started\r\n");
  25.     gaitRunnerPlay(&gait, 2, 5000, 10, 1);
  26.     return 1000000;
  27. }
  28.  
  29. void checkSonar(void * data, TICK_COUNT lasttime, TICK_COUNT overflow){
  30.     rprintf("about to check sonar\r\n");
  31.     distanceRead(sonar);
  32.     rprintf("about to display sonar\r\n");
  33.     rprintf("Distance=%u\r\n",sonar.distance.cm);
  34.     scheduleJob(&checkSonar,data,lasttime,1000000);
  35.     rprintf("sonar rescheduled for 1 second\r\n");
  36. }
  37.  
  38. TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) {
  39.  
  40.     scheduleJob(&checkSonar,&data,lasttime, 0);
  41.  
  42.     if(SWITCH_pressed(&button0)){
  43.         if (zeroAlreadyPressed == 0) {
  44.         rprintf("Button 0 Pressed\r\n");
  45.         gaitRunnerPlay(&gait, 0, 5000, 30, 2);
  46.         gaitRunnerProcess(&gait);
  47.         zeroAlreadyPressed = 1;
  48.         }
  49.     }
  50.    
  51.     if(SWITCH_released(&button0)){
  52.         zeroAlreadyPressed = 0;
  53.     }
  54.  
  55.     if(SWITCH_pressed(&button1)){
  56.         if (oneAlreadyPressed == 0) {
  57.         rprintf("Button 1 Pressed\r\n");
  58.         gaitRunnerPlay(&gait, 1, 5000, 75, 1);
  59.         gaitRunnerProcess(&gait);
  60.         oneAlreadyPressed = 1;
  61.         }
  62.     }
  63.    
  64.     if(SWITCH_released(&button1)){
  65.         oneAlreadyPressed = 0;
  66.     }
  67.  
  68.     if(SWITCH_pressed(&button2)){
  69.         if (twoAlreadyPressed == 0) {
  70.         rprintf("Button 2 Pressed\r\n");
  71.         gaitRunnerPlay(&gait, 3, 5000, 22, 10);
  72.         gaitRunnerProcess(&gait);
  73.         twoAlreadyPressed = 1;
  74.         }
  75.     }
  76.    
  77.     if(SWITCH_released(&button2)){
  78.         twoAlreadyPressed = 0;
  79.     }
  80.  
  81.     return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement