int main( void ){ TRISB=0x0FEF; PORTB=0; initStepper(); stepperSpeed(30000); while(1){ takeSteps(100,FWD); while(PTCONbits.PTEN); }; }//end main
void initAllPeripherals() { /*init analog*/ initAdcPortA(); /*init stepper motors*/ initStepper(); /*init dc motors*/ initDcMotorControl(); /*init Uart*/ initSerialPortC(); /*init Lcd*/ initLcd(LCD_DISP_ON); gotoLcd(4); putsLcd("WELCOME!"); gotoLcd(65); putsLcd("Init Completed!"); }
/** * @fn int main(void) * @brief Fonction main du programme. */ int main(void) { // Déclaration des variables locales. match oldMatchStatus = OVER; // Etat précédent duu match (pour les actions d'entrée) actionType choix; //<! Pointeur vers l'action en cours. positionInteger positionInitiale; //<! Position initiale du robot sur la table team equipe; //<! Equipe actuelle. // propIsObstacleType test; pllConfig(); // Configuration de la PLL de l'horloge interne pour tourner à 40MIPS assignSPIO(); // Assignation des pins du dSPIC. timerSetup(5, 50); TMR5 = 0; // Initialisation du CAN CanInitialisation(CN_LOGIQUE); propulsionInitCan(); CanDeclarationProduction(CN_LOGIQUE*0x10, &matchStatus, sizeof(matchStatus)); CanDeclarationProduction(CN_LOGIQUE*0x10, &mesureSharp, sizeof(mesureSharp)); ACTIVATE_CAN_INTERRUPTS = 1; //msTimerInit(); // Initialisation du timer des millisecondes, n'est utilisé que pour waitXms (TODO: enlever en mêm temps que waitXms) while(1) { if (getMatchTimerFlag()) { matchStatus = OVER; } // Machine d'état de la logique switch (matchStatus) { case INIT: // Etat initial, phase précédant le match if (matchStatus != oldMatchStatus) { oldMatchStatus = matchStatus; CanEnvoiProduction(&matchStatus); matchTimerInit(); // Initialisation du timer de match initADC(); //initBLE(); initStepper(); if (EnvoiSharpActif == 1){ timerStart(5); IEC1bits.T5IE = 1; } sendPosition(positionInitiale); } if (!GOUPILLE_OTEE) { matchStatus = PRE_MATCH; } break; case PRE_MATCH: // Le robot attend le début du match. On peut encore choisir la couleur if (matchStatus != oldMatchStatus) { oldMatchStatus = matchStatus; CanEnvoiProduction(&matchStatus); } //if (BOUTON_EQUIPE == JAUNE) { // equipe = JAUNE; // positionInitiale = positionInitialeJaune; //ordreActions = actionsJaune; //} else { equipe = VERT; positionInitiale = positionInitialeVert; //} // TRANSITIONS // réparer la goupille ENCORE // if (GOUPILLE_OTEE) { // si la goupille est retirée, le match commence __delay_ms(1000); StartMatchTimer(); // on lance le timer de match (90s)) propulsionEnable(); // on active la propulsion // msTimerStart(); while(propulsionGetStatus() != STANDING); // on attend que l'ordre soit exécuté propulsionSetPosition(positionInitiale); // On initialise la position de la propulsion while(!compareXYAlpha(propulsionGetPosition(), positionInitiale)); // on attend que l'ordre soit exécuté choix = choixAction(); // Sélection de la prochaine action => c'est dans cette fonction qu'il faut mettre de l'IA matchStatus = ONGOING; // } break; case ONGOING: // Le match est lancé if (matchStatus != oldMatchStatus) { oldMatchStatus = matchStatus; CanEnvoiProduction(&matchStatus); } if (getTaskRequest()){ setTaskRequest(0); Scheduler(getPetitRobot()); } infoAction = choix.ptr2Fct(choix.dest,choix.methode); if (canReceivedOrderFlag) { canReceivedOrderFlag = 0; if (canReceivedCommand == LOGI_SHARP_MESURE) { EnvoiSharpActif = canReceivedData[0]; } } switch(infoAction.statut) { case ACTION_PAS_COMMENCEE: case ACTION_EN_COURS: // on attend la fin de l'action break; case ACTION_FINIE: case ACTION_REMISE: sendPosition(propulsionGetPosition()); choix = choixAction(); // Sélection de la prochaine action => c'est dans cette fonction qu'il faut mettre de l'IA break; case ACTION_ERREUR: matchStatus = ERROR; default: break; } break; case OVER: if (matchStatus != oldMatchStatus) { oldMatchStatus = matchStatus; CanEnvoiProduction(&matchStatus); propulsionDisable(); } if (!GOUPILLE_OTEE) { matchStatus = INIT; } break; case ERROR: if (matchStatus != oldMatchStatus) { oldMatchStatus = matchStatus; CanEnvoiProduction(&matchStatus); } choix = gestionErreur(choix); matchStatus = ONGOING; break; default: matchStatus = ERROR; break; } } return 0; }
int main(void) { //Variable Declarations initSolenoid(); /* initialize solenoid valve */ TIM_TIMERCFG_Type timerCfg; initTimeStruct(); RTC_TIME_Type* watertime = malloc(sizeof(RTC_TIME_Type)); uint8 fed = 0; uint8 watered = 0; watertime->HOUR = 5; watertime->MIN = 0; //Initialize timer0 for delays TIM_ConfigStructInit(TIM_TIMER_MODE, &timerCfg); /* initialize timer config struct */ TIM_Init(LPC_TIM0, TIM_TIMER_MODE, &timerCfg); /* initialize timer0 */ //Initialize Real Time Clock RTC_Init(LPC_RTC); RTC_Cmd(LPC_RTC, ENABLE); RTC_ResetClockTickCounter(LPC_RTC); // Initialize Peripherals INIT_SDRAM(); /* initialize SDRAM */ servoInit(); /* initialize FSR servo motor for panning camera */ initStepper(); /* initialize stepper motor for dispensing food */ initFSR(); /* initialize force sensitive resistor circuit for food and water full signals */ initWiFi(AUTO_CONNECT); /* initialize WiFi module -- must be attached*/ audio_initialize(); audio_reset(); //audio_test(); audio_setupMP3(); int i = 0, retval; uint32 length; /* length variable for photo */ printf("Entering while loop\n\r"); //audio_storeVoice(); // Enter an infinite loop while(1) { if(STATE == DISPENSING_FOOD){ printf("Entering food dispense state\n\r"); /* Execute commands to dispense food */ //spinUntilFull(); spinStepper(300); reverseSpin(250); STATE = CONNECTED; } if(STATE == DISPENSING_WATER){ printf("Entering water dispense state\n\r"); /* Execute commands to dispense water */ fillWater(); STATE = CONNECTED; } if(STATE == CAPTURING){ printf("Entering camera taking state\n\r"); /* Initialize camera and set it up to take a picture */ if(cameraInit()) printf("Camera not initialized!\n\r"); retval = stopFrame(); length = getBufferLength(); printf("length: %i\n\r", length); /* Send length to Android application */ int temp_len = length; while(temp_len){ uart1PutChar(temp_len % 10); temp_len = temp_len / 10; } /* Send photo and finish set up */ getAndSendPhoto(length); resumeFrame(); STATE = CONNECTED; } if(STATE == TALKING1){ audio_playVoice(1); STATE = CONNECTED; } if(STATE == TALKING2){ audio_playVoice(2); STATE = CONNECTED; } if(STATE == TALKING3){ audio_playVoice(3); STATE = CONNECTED; } if(STATE == PAN_LEFT){ /* Execute commands to pan servo left */ panServo(LEFT); STATE = CONNECTED; } if(STATE == PAN_RIGHT){ /* Execute commands to pan servo right */ panServo(RIGHT); STATE = CONNECTED; } if(STATE == SCHEDULING){ /* Execute commands to schedule a feeding time */ STATE = CONNECTED; } /* Scheduling */ RTC_GetFullTime(LPC_RTC, time); //Fill water bowl at predetermined time if (time->HOUR == watertime->HOUR + 1 && watered == 1) watered = 0; if (watertime->HOUR == time->HOUR && watertime->MIN < time->MIN && watered == 0) { fillWater(); watered = 1; } //Feed dog on schedule if any cannot feed dog two consecutive hours for(i = 0; i < scheduled_feeds; i++) { if (time->HOUR == feedtime[i]->HOUR + 1 && fed == 1) fed = 0; if (feedtime[i]->HOUR == time->HOUR && feedtime[i]->MIN < time->MIN && fed == 0) { spinUntilFull(); fed = 1; } } } return 0; }