Time is good

Dependencies:   RoboClaw mbed

Fork of Robot2016_2-0 by ARES

Functions/func.cpp

Committer:
IceTeam
Date:
2016-05-05
Revision:
78:c28bdbf29b6e
Parent:
77:f19cc7f81f2a

File content as of revision 78:c28bdbf29b6e:

#include <cmath>

#include "func.h"

int max(int a, int b)
{
    return (a>b)?a:b;
}

int max(int a, int b, int c)
{
    return max(a,max(b,c));
}

int min(int a, int b)
{
    return (a<b)?a:b;
}

void init_interrupt(void)
{
    ticker.attach_us(&update_main, dt); // 100 Hz
}

void pressed(void)
{
    if(SIMON_i==0) {
        roboclaw.ForwardM1(0);
        roboclaw.ForwardM2(0);
        SIMON_i++;
    }
}

void unpressed(void)
{
    if(SIMON_i==1) {
        SIMON_i--;
    }
}

void checkAround(void)
{
    SDroite += (capt1.read() > seuils[0]?1:-1);
    SDroite = min(SDroite, 5);
    SDroite = max(SDroite, -5);
    
    SDevant += (capt2.read() > seuils[1]?1:-1);
    SDevant = min(SDevant, 5);
    SDevant = max(SDevant, -5);
    
    SGauche += (capt3.read() > seuils[2]?1:-1);
    SGauche = min(SGauche, 5);
    SGauche = max(SGauche, -5);
    
    drapeau[0] = SGauche>0;
    drapeau[1] = SDevant>0;
    drapeau[2] = SDroite>0;
    
    logger.printf("Sharps : %d %d %d\r\n", SGauche, SDevant, SDroite);
}

/*void init_ax12(void)
{
    left_hand.setMode(0);
    wait_ms(10);
    right_hand.setMode(0);
    wait_ms(50);
    left_hand.setMode(0);
    wait_ms(10);
    right_hand.setMode(0);
    wait_ms(50);
    right_hand.setGoal(0);
    left_hand.setGoal(0);
    wait(2);
    right_hand.setGoal(180);
    left_hand.setGoal(180);
    wait(2);
}*/

void changeCamp(void)
{
    if(SCouleur==VERT) {
        SCouleur = VIOLET;
        LEDR = 1;
        LEDV = 0;
    } else {
        SCouleur = VERT;
        LEDV = 1;
        LEDR = 0;
    }
}

void depart(void)
{
    while(button==1) {
        if(CAMP==0) {
            changeCamp();
        }
        wait_ms(100);
    }

    if(SCouleur == VERT)logger.printf("Couleur VERT !\n\r");
    else logger.printf("Couleur ROUGE !\n\r");

    while(START==0) {
        drapeau = SSchema;
        if(CAMP==0) {
            SSchema++;
            if(SSchema == 6) SSchema = 1;
            drapeau = SSchema;
        }
        wait_ms(100);
    }
    logger.printf("Schema numero : %d !\n\r", SSchema);
}