Revision 88afb834 devices/DiWheelDrive/main.cpp

View differences:

devices/DiWheelDrive/main.cpp
754 754
    // sleep(CAN::UPDATE_PERIOD);
755 755
    BaseThread::sleep(CAN::UPDATE_PERIOD);
756 756
  }
757
  chprintf(chp,"Sensors Calibrated: MaxDelta: %d, FL: 0x%x, FR: 0x%d\n", maxDelta, proxyL, proxyR);
757
  chprintf(chp,"Sensors Calibrated: MaxDelta: %d, FL: %d, FR: %d\n", maxDelta, proxyL, proxyR);
758 758

  
759 759
  global.threshProxyL = proxyL;
760 760
  global.threshProxyR = proxyR;
......
821 821
  int proxyR = global.threshProxyR;
822 822
  int maxDelta = 0;
823 823
  float KCrit = 0.0f;
824
  global.sensSamples = 0;
824 825
  LineFollow lf(&global);
825 826
 
826 827
  if (argc == 2){
......
832 833
    chprintf(chp, "Usage: dev_ziegler2 <K_crit> <steps>");
833 834
    return;
834 835
  }
836
  chprintf((BaseSequentialStream*)&global.sercanmux1, "Recodring starts in five seconds...\n");
837
  BaseThread::sleep(MS2ST(5000));
835 838
  // global.motorcontrol.setTargetRPM(rpmSpeed[constants::DiWheelDrive::LEFT_WHEEL] * 1000000, rpmSpeed[constants::DiWheelDrive::RIGHT_WHEEL] * 1000000);
836 839
  
837 840
  for(int s=0; s < steps; s++){
......
845 848
}
846 849

  
847 850

  
851

  
852
void recordMove(BaseSequentialStream *chp, int argc, char *argv[]){
853
  // int vcnl4020AmbientLight[4];
854
  int vcnl4020Proximity[4];
855
  int rpmSpeed[2] = {0};
856
  int steps = 0;
857
  int speed = 0;
858
  if (argc == 1){
859
      chprintf(chp, "%i steps \n", atoi(argv[0]));
860
      steps = atoi(argv[0]);
861
      speed = 30;
862
  }else if (argc == 2){
863
    steps = atoi(argv[0]);
864
    speed = atoi(argv[1]);
865
  }else{
866
    chprintf(chp, "No steps given!\n");
867
    return;
868
  }
869
  global.sensSamples = steps;
870
  chprintf((BaseSequentialStream*)&global.sercanmux1, "Recodring starts in five seconds...\n");
871
  BaseThread::sleep(MS2ST(5000));
872
  // int sensSamples = 0;
873
  // sensorRecord senseRec[1000];
874

  
875
  for (int j = 0; j < steps; j++) {
876
    for (int i = 0; i < 4; i++) {
877
        // vcnl4020AmbientLight[i] = global.vcnl4020[i].getAmbientLight();
878
        vcnl4020Proximity[i] = global.vcnl4020[i].getProximityScaledWoOffset();
879
    }
880

  
881
    int FL = global.vcnl4020[constants::DiWheelDrive::PROX_FRONT_LEFT].getProximityScaledWoOffset();
882
    int FR = global.vcnl4020[constants::DiWheelDrive::PROX_FRONT_RIGHT].getProximityScaledWoOffset();
883
    
884

  
885
    global.senseRec[j].FL = FL;
886
    global.senseRec[j].FR = FR;
887
    global.senseRec[j].delta = delta;
888
    // chprintf(chp,"FL: 0x%x, FR: 0x%x, Delta: %d, ProxyL: %x, ProxyR: %x, MaxDelta: %d\n", 
889
    //               vcnl4020Proximity[constants::DiWheelDrive::PROX_FRONT_LEFT],
890
    //               vcnl4020Proximity[constants::DiWheelDrive::PROX_FRONT_RIGHT],
891
    //               vcnl4020Proximity[constants::DiWheelDrive::PROX_FRONT_LEFT] - vcnl4020Proximity[constants::DiWheelDrive::PROX_FRONT_RIGHT]);
892
    global.motorcontrol.setTargetRPM(speed * 1000000, -speed * 1000000);
893
    BaseThread::sleep(CAN::UPDATE_PERIOD);
894
  }
895
  global.motorcontrol.setTargetRPM(0,0);
896
  for(int k=0; k<8;k++){
897
    global.robot.setLightColor(k, Color(Color::WHITE));
898
  }
899
  BaseThread::sleep(MS2ST(1000));
900
  for(int k=0; k<8;k++){
901
    global.robot.setLightColor(k, Color(Color::BLACK));
902
  }
903
}
904

  
905
void printMove(BaseSequentialStream *chp, int argc, char *argv[]){
906

  
907
  for (int j=0; j<global.sensSamples;j++){
908
    chprintf(chp,"FL:%d,FR:%d,Delta:%d\n",global.senseRec[j].FL, global.senseRec[j].FR, global.senseRec[j].delta);
909
  }
910

  
911
}
912

  
913

  
848 914
static const ShellCommand commands[] = {
849 915
  {"shutdown", shellRequestShutdown},
850 916
  {"wakeup", shellRequestWakeup},
......
875 941
  {"dev_ziegler2", zieglerMeth2},
876 942
  // TODO: Stop user process from execution to finish/force calibration before anything starts
877 943
  {"calibrate_line", calibrateLineSensores}, 
944
  {"record_move_l", recordMove},
945
  {"print_record", printMove},
878 946
  {NULL, NULL}
879 947
};
880 948

  

Also available in: Unified diff