Fork de Timer après le match à 61 points

Dependencies:   RoboClaw mbed

Fork of Timer by ARES

main.cpp

Committer:
IceTeam
Date:
2016-05-06
Revision:
90:78d2c1527c95
Parent:
89:46730de0d013
Child:
91:65fb6b9f3932

File content as of revision 90:78d2c1527c95:

#include "entete.h"
#include "AX12/AX12.h"

DigitalIn CAMP(PA_15);
DigitalIn START(PB_7);
DigitalOut LEDR(PC_2);
DigitalOut LEDV(PC_3);
DigitalIn button(USER_BUTTON);
int SCouleur = VERT;

BusOut drapeau (PC_8, PC_6, PC_5);
RoboClaw roboclaw(ADR, 460800, PA_11, PA_12);
AnalogIn Rcapt1(PA_4);
int RvalRcapt1 = 0;
AnalogIn Rcapt2(PB_0);
int RvalRcapt2 = 0;
AnalogIn Rcapt3(PC_1);
int RvalRcapt3 = 0;
int Ravance = 1;
DigitalIn start(PB_7);
AX12 umbrella(PA_9, PA_10, 2, 250000);
float R_SEUIL_SHARP = 1;

/* Debut du programme */
int main(void)
{
    Ticker ticker;
    Timeout end;
    ticker.attach(&Sharps, 0.01);

    umbrella.setMode(0);
    umbrella.setMaxTorque(200);
    umbrella.setGoal(150);
    wait(1);
    umbrella.setGoal(160);
    wait(1);
    umbrella.setGoal(150);
    wait(1);
    umbrella.setMaxTorque(0);
    
    depart();
    if (SCouleur == VERT) {
        end.attach(&endFonc, 60);
        GotoDist(9.0);
        GotoArr(9.2);
        R_SEUIL_SHARP = 0.25;
        GotoDist(2.5);
        GotoThet(-3.14159);
        GotoDist(4);
        R_SEUIL_SHARP = 1;
        GotoDist(3.5);
    }
    else if (SCouleur == VIOLET) {  
        end.attach(&endFonc, 60);
        GotoDist(9.0);
        GotoArr(9.2);
        R_SEUIL_SHARP = 0.25;
        GotoDist(2.5);
        GotoThet(3.14159);
        GotoDist(4);
        R_SEUIL_SHARP = 1;
        GotoDist(3.5);
    }
    else if (SCouleur == NOIR) {
        TestDist3(2,2);
        TestThet3(1,1);
    }

    while(1);
}

void Sharps() {
    if (Rcapt1.read() > R_SEUIL_SHARP) RvalRcapt1++;
    else RvalRcapt1--;
    RvalRcapt1 = RvalRcapt1 > 10 ? 10 : RvalRcapt1;
    RvalRcapt1 = RvalRcapt1 < 0 ? 0 : RvalRcapt1;
    
    if (Rcapt2.read() > R_SEUIL_SHARP) RvalRcapt2++;
    else RvalRcapt2--;
    RvalRcapt2 = RvalRcapt2 > 10 ? 10 : RvalRcapt2;
    RvalRcapt2 = RvalRcapt2 < 0 ? 0 : RvalRcapt2;
    
    if (Rcapt3.read() > R_SEUIL_SHARP) RvalRcapt3++;
    else RvalRcapt3--;
    RvalRcapt3 = RvalRcapt3 > 10 ? 10 : RvalRcapt3;
    RvalRcapt3 = RvalRcapt3 < 0 ? 0 : RvalRcapt3;
    
    if ((RvalRcapt1 >= 5 || RvalRcapt2 >= 5 || RvalRcapt3 >= 5))
        Ravance = 0;
    else 
        Ravance = 1;
        
    if (Ravance == 0)
        drapeau = 1;
    else 
        drapeau = 2;
}

void endFonc () {
    roboclaw.ForwardM1(0);
    roboclaw.ForwardM2(0);
    wait(1);
    umbrella.setMaxTorque(400);
    wait(1);
    umbrella.setGoal(300);
    while(1);
}