Advertisement
Guest User

Untitled

a guest
Feb 14th, 2013
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.57 KB | None | 0 0
  1.  #include "hardware.h"
  2.     #include "armbotbuild.h"
  3.     #include <Gait/GaitRunner.h>
  4.      
  5.     int zeroAlreadyPressed = 0;
  6.     int oneAlreadyPressed = 0;
  7.     int twoAlreadyPressed = 0;
  8.      
  9.     int lasttime = 0;
  10.     int * data = 0;
  11.      
  12.     int i = 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 0;
  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.                                     distanceRead(sonar);
  46.                                     rprintf("Distance=%u\r\n",sonar.distance.cm);
  47.                     gaitRunnerPlay(&gait, 0, 5000, 30, 2);
  48.                     gaitRunnerProcess(&gait);
  49.                     zeroAlreadyPressed = 1;
  50.                     }
  51.             }
  52.            
  53.             if(SWITCH_released(&button0)){
  54.                     zeroAlreadyPressed = 0;
  55.             }
  56.      
  57.             if(SWITCH_pressed(&button1)){
  58.                     if (oneAlreadyPressed == 0) {
  59.                     rprintf("Button 1 Pressed\r\n");
  60.                                     distanceRead(sonar);
  61.                                     rprintf("Distance=%u\r\n",sonar.distance.cm);
  62.                     gaitRunnerPlay(&gait, 1, 5000, 75, 1);
  63.                     gaitRunnerProcess(&gait);
  64.                     oneAlreadyPressed = 1;
  65.                     }
  66.             }
  67.      
  68.     //              {
  69.     //      int i;
  70.     //              for (i = 0; i < 5; i++)
  71.     //              {
  72.     //                      delay_ms(50);
  73.     //              }
  74.      
  75.     if( i >=5000) {
  76.                     distanceRead(sonar);
  77.                     rprintf("Distance=%u\r\n",sonar.distance.cm);
  78.                     i = 0;
  79.     }
  80.     i++;
  81.      
  82.     //      return 0;
  83.     //              }
  84.      
  85.             if(SWITCH_released(&button1)){
  86.                     oneAlreadyPressed = 0;
  87.             }
  88.      
  89.             if(SWITCH_pressed(&button2)){
  90.                     if (twoAlreadyPressed == 0) {
  91.                     rprintf("Button 2 Pressed\r\n");
  92.                                     distanceRead(sonar);
  93.                                     rprintf("Distance=%u\r\n",sonar.distance.cm);
  94.                     gaitRunnerPlay(&gait, 3, 5000, 22, 10);
  95.                     gaitRunnerProcess(&gait);
  96.                     twoAlreadyPressed = 1;
  97.                     }
  98.             }
  99.            
  100.             if(SWITCH_released(&button2)){
  101.                     twoAlreadyPressed = 0;
  102.             }
  103.      
  104.             return 0;
  105.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement