Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Classes/Robot.cpp
- Committer:
- theolp
- Date:
- 2019-06-05
- Revision:
- 21:9ff2eab240fb
- Parent:
- 20:a1b5d032b422
- Child:
- 23:bb1535360a98
File content as of revision 21:9ff2eab240fb:
#include "mbed.h"
#include "Robot.h"
#include "CAN_asser.h"
#include "Deplacement.h"
#include "Laser.h"
#include "Rouleau.h"
#include <string>
using namespace std;
//********** CNY70 **********//
/*
CNY70 de gauche branché sur CNY 0 : le plus à droite (peut changer)
CNY70 de droite branché sur CNY 1 : deuxième en partant de la droite (peut changer)
PINS:
CNY 0 -> A2
CNY 1 -> A3
CNY 2 -> A4
CNY 3 -> A5
*/
/**********************************/
DigitalIn Robot::Jack(PA_15);
Robot::Robot() : laserG(Laser(PB_1)), laserD(Laser(PC_5)), laserA(Laser(PC_4)),
rouleau(Rouleau(D5, D4, D6)), /*Pins order : PWM, Ejecte, Gobe*/
BPs(DigitalIn(PC_2, PullDown)),
CNY_G(AnalogIn(A2)), CNY_D(AnalogIn(A3)) //Infos plus haut pour les pins
{
can_init();
this->setPos(500,0,0);
}
bool Robot::aBalle()
{
return BPs.read();
}
/// Fonctions Odometrie ///
void Robot::setPos(unsigned short x, unsigned short y, signed short theta) const
{
SetOdometrie(ODOMETRIE_POSITION, y, x, theta); // Oui les x et les y sont inversés...
}
/// retourne l'adresse de la premiere case d'un tableau contenant dans l'ordre la position en x et en y et l'angle theta ///
short Robot::pos(T_POS pos)
{
return this->deplacement.getPos(pos);
}
/// Toutes les fonctions de déplacement ///
bool Robot::avance(signed short dist)
{
return deplacement.avance(dist);
}
bool Robot::tourne(signed short angle)
{
return deplacement.tourne(angle);
}
bool Robot::GoToXYT(unsigned short x, unsigned short y, unsigned short t, signed char sens) //sens = 0 par défaut
{
return deplacement.GoToXYT(x,y,t,sens);
}
void Robot::setSpeed(unsigned short vitesse, unsigned short acceleration) const
{
SendSpeed(vitesse,acceleration);
}
void Robot::stop()
{
deplacement.stop();
}
/// Fonction distance lasers ///
float Robot::getDist(int laserENUM, string unite) //="cm" par défaut
{
switch(laserENUM) {
case Laser::Gauche:
return this->laserG.getDist(unite);
case Laser::Droit:
return this->laserD.getDist(unite);
case Laser::Arriere:
return this->laserA.getDist(unite);
}
return 0;
}
/// Fonction CNY surBlanc ou pas ///
bool Robot::surBlanc( T_CNY cny )
{
static const float SEUIL_CNY_G = 0.7f,
SEUIL_CNY_D = 0.7f;
if( cny == Robot::CNY_GAUCHE )
return ( this->CNY_G >= SEUIL_CNY_G );
else if( cny == Robot::CNY_DROIT )
return ( this->CNY_D >= SEUIL_CNY_D );
else return false;
}
/// Fonctions Rouleau ///
void Robot::ejecte(int vitesse) // vitesse max = 100
{
rouleau.ejecte(vitesse);
}
void Robot::gobe(int vitesse) // vitesse max = 100
{
rouleau.gobe(vitesse);
}
void Robot::stopRouleau()
{
rouleau.stop();
}