Robot secondaire
Dependencies: RoboClaw mbed StepperMotor
Fork of RoboClaw by
Odometry/Odometry.h@34:e5500418b0e7, 2016-01-26 (annotated)
- Committer:
- IceTeam
- Date:
- Tue Jan 26 17:17:52 2016 +0000
- Revision:
- 34:e5500418b0e7
- Parent:
- 31:8bcc3a0bfa8a
Fonction TestEntraxe;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sype | 0:ad9600df4a70 | 1 | #ifndef ODOMETRY_H |
sype | 0:ad9600df4a70 | 2 | #define ODOMETRY_H |
sype | 0:ad9600df4a70 | 3 | |
sype | 0:ad9600df4a70 | 4 | #include "mbed.h" |
IceTeam | 31:8bcc3a0bfa8a | 5 | #include "../RoboClaw/RoboClaw.h" |
sype | 0:ad9600df4a70 | 6 | |
sype | 0:ad9600df4a70 | 7 | #define PI 3.1415926535897932384626433832795 |
sype | 10:ae3178aa94e9 | 8 | #define C 1.0 |
sype | 10:ae3178aa94e9 | 9 | |
IceTeam | 31:8bcc3a0bfa8a | 10 | /* Vitesse d'acceleration d'angle reduite de 8000->4000 */ |
IceTeam | 31:8bcc3a0bfa8a | 11 | #define accel_angle 4000 |
sype | 10:ae3178aa94e9 | 12 | #define vitesse_angle 16000 |
IceTeam | 31:8bcc3a0bfa8a | 13 | #define deccel_angle 4000 |
sype | 10:ae3178aa94e9 | 14 | |
sype | 10:ae3178aa94e9 | 15 | #define accel_dista 8000 |
sype | 10:ae3178aa94e9 | 16 | #define vitesse_dista 16000 |
sype | 10:ae3178aa94e9 | 17 | #define deccel_dista 8000 |
sype | 0:ad9600df4a70 | 18 | |
sype | 0:ad9600df4a70 | 19 | /* |
sype | 0:ad9600df4a70 | 20 | * Author : Benjamin Bertelone, reworked by Simon Emarre |
sype | 0:ad9600df4a70 | 21 | */ |
sype | 0:ad9600df4a70 | 22 | |
sype | 2:abdf8c6823a1 | 23 | extern Serial pc; |
sype | 10:ae3178aa94e9 | 24 | extern DigitalOut led; |
sype | 2:abdf8c6823a1 | 25 | |
IceTeam | 9:e39b218ab20d | 26 | /** Permet la gestion de l'odometrie du robot **/ |
sype | 0:ad9600df4a70 | 27 | class Odometry |
sype | 0:ad9600df4a70 | 28 | { |
IceTeam | 8:12d7123a500e | 29 | public: |
sype | 10:ae3178aa94e9 | 30 | /** Constructeur standard |
IceTeam | 8:12d7123a500e | 31 | * @param diameter_right Definit le diametre de la roue droite |
IceTeam | 8:12d7123a500e | 32 | * @param diameter_left Definit le diametre de la roue gauche |
IceTeam | 8:12d7123a500e | 33 | * @param v Definit l'entraxe du robot |
IceTeam | 8:12d7123a500e | 34 | * @param rc Definit une reference vers l'objet permettant l'asserv des moteurs |
sype | 10:ae3178aa94e9 | 35 | * @note Cet objet doit etre initialise en amont |
IceTeam | 8:12d7123a500e | 36 | */ |
sype | 10:ae3178aa94e9 | 37 | Odometry(double diameter_right, double diameter_left, double v, uint16_t quadrature, RoboClaw &rc); |
IceTeam | 8:12d7123a500e | 38 | |
IceTeam | 34:e5500418b0e7 | 39 | void TestEntraxe(int i); |
IceTeam | 34:e5500418b0e7 | 40 | |
IceTeam | 8:12d7123a500e | 41 | /** Les fonctions suivantes permettent de reinitialiser les valeurs de position de l'odometrie. |
IceTeam | 8:12d7123a500e | 42 | */ |
IceTeam | 8:12d7123a500e | 43 | void setPos(double x, double y, double theta); |
IceTeam | 8:12d7123a500e | 44 | void setX(double x); |
IceTeam | 8:12d7123a500e | 45 | void setY(double y); |
IceTeam | 8:12d7123a500e | 46 | void setTheta(double theta); |
IceTeam | 8:12d7123a500e | 47 | |
IceTeam | 8:12d7123a500e | 48 | /** Les fonctions suivantes permettent de deplacer le robot vers une position ou un angle voulu |
IceTeam | 8:12d7123a500e | 49 | */ |
sype | 12:d5e21f71c2a9 | 50 | void GotoXY(double x_goal, double y_goal); |
IceTeam | 8:12d7123a500e | 51 | void GotoXYT(double x_goal, double y_goal, double theta_goal); |
IceTeam | 8:12d7123a500e | 52 | void GotoThet(double theta_); |
IceTeam | 8:12d7123a500e | 53 | void GotoDist(double distance); |
IceTeam | 8:12d7123a500e | 54 | |
IceTeam | 8:12d7123a500e | 55 | double getX() { |
IceTeam | 8:12d7123a500e | 56 | return x; |
IceTeam | 8:12d7123a500e | 57 | } |
IceTeam | 8:12d7123a500e | 58 | double getY() { |
IceTeam | 8:12d7123a500e | 59 | return y; |
IceTeam | 8:12d7123a500e | 60 | } |
IceTeam | 8:12d7123a500e | 61 | double getTheta() { |
IceTeam | 8:12d7123a500e | 62 | return theta; // ]-PI;PI] |
IceTeam | 8:12d7123a500e | 63 | } |
IceTeam | 8:12d7123a500e | 64 | double getTheta_(double x, double y); |
IceTeam | 8:12d7123a500e | 65 | |
IceTeam | 8:12d7123a500e | 66 | double abs_d(double x) { |
IceTeam | 8:12d7123a500e | 67 | if(x<0) return -x; |
IceTeam | 8:12d7123a500e | 68 | else return x; |
IceTeam | 8:12d7123a500e | 69 | } |
IceTeam | 7:961c1acdf753 | 70 | |
sype | 10:ae3178aa94e9 | 71 | /* Les fonction suivantes sont actuellement inutilisables, elles pourraient buguer en cas d'utilisation. */ |
sype | 10:ae3178aa94e9 | 72 | |
IceTeam | 8:12d7123a500e | 73 | double getVitLeft() { |
IceTeam | 8:12d7123a500e | 74 | return m_vitLeft; |
IceTeam | 8:12d7123a500e | 75 | } |
IceTeam | 8:12d7123a500e | 76 | double getVitRight() { |
IceTeam | 8:12d7123a500e | 77 | return m_vitRight; |
IceTeam | 8:12d7123a500e | 78 | } |
IceTeam | 8:12d7123a500e | 79 | |
IceTeam | 8:12d7123a500e | 80 | double getDistLeft() { |
IceTeam | 8:12d7123a500e | 81 | return m_distLeft; |
IceTeam | 8:12d7123a500e | 82 | } |
IceTeam | 8:12d7123a500e | 83 | double getDistRight() { |
IceTeam | 8:12d7123a500e | 84 | return m_distRight; |
IceTeam | 8:12d7123a500e | 85 | } |
IceTeam | 8:12d7123a500e | 86 | |
IceTeam | 8:12d7123a500e | 87 | void setDistLeft(double dist) { |
IceTeam | 8:12d7123a500e | 88 | m_distLeft = dist; |
IceTeam | 8:12d7123a500e | 89 | } |
IceTeam | 8:12d7123a500e | 90 | void setDistRight(double dist) { |
IceTeam | 8:12d7123a500e | 91 | m_distRight = dist; |
IceTeam | 8:12d7123a500e | 92 | } |
IceTeam | 8:12d7123a500e | 93 | |
IceTeam | 8:12d7123a500e | 94 | double calcul_distance(double x, double y, double theta_goal); |
IceTeam | 8:12d7123a500e | 95 | |
IceTeam | 8:12d7123a500e | 96 | int32_t getPulsesLeft(void) { |
IceTeam | 8:12d7123a500e | 97 | return m_pulses_left; |
IceTeam | 8:12d7123a500e | 98 | } |
IceTeam | 8:12d7123a500e | 99 | int32_t getPulsesRight(void) { |
IceTeam | 8:12d7123a500e | 100 | return m_pulses_right; |
IceTeam | 8:12d7123a500e | 101 | } |
IceTeam | 8:12d7123a500e | 102 | double carre(double a) { |
IceTeam | 8:12d7123a500e | 103 | return a*a; |
IceTeam | 8:12d7123a500e | 104 | } |
sype | 12:d5e21f71c2a9 | 105 | |
sype | 12:d5e21f71c2a9 | 106 | void getEnc(); |
sype | 12:d5e21f71c2a9 | 107 | |
IceTeam | 8:12d7123a500e | 108 | /** La fonction retourne vraie quand le robot atteint l'angle voulu avec une marge d'erreur definie par la fonction |
IceTeam | 8:12d7123a500e | 109 | * @param theta_ valeur de l'angle devant etre atteint |
IceTeam | 8:12d7123a500e | 110 | */ |
sype | 10:ae3178aa94e9 | 111 | bool isArrived(void) {return arrived;} |
IceTeam | 8:12d7123a500e | 112 | /** Permet de mettre à jour les valeurs de l'odometrie |
IceTeam | 8:12d7123a500e | 113 | */ |
IceTeam | 8:12d7123a500e | 114 | void update_odo(void); |
IceTeam | 8:12d7123a500e | 115 | |
IceTeam | 8:12d7123a500e | 116 | private: |
IceTeam | 8:12d7123a500e | 117 | RoboClaw &roboclaw; |
IceTeam | 8:12d7123a500e | 118 | int32_t m_pulses_left; |
IceTeam | 8:12d7123a500e | 119 | int32_t m_pulses_right; |
sype | 10:ae3178aa94e9 | 120 | uint8_t pos_prog; |
IceTeam | 8:12d7123a500e | 121 | double x, y, theta; |
IceTeam | 8:12d7123a500e | 122 | double m_vitLeft, m_vitRight; |
IceTeam | 8:12d7123a500e | 123 | double m_distLeft, m_distRight; |
IceTeam | 8:12d7123a500e | 124 | |
IceTeam | 8:12d7123a500e | 125 | double m_distPerTick_left, m_distPerTick_right, m_v; |
IceTeam | 8:12d7123a500e | 126 | |
IceTeam | 8:12d7123a500e | 127 | double erreur_ang; |
sype | 10:ae3178aa94e9 | 128 | bool arrived; |
sype | 0:ad9600df4a70 | 129 | }; |
sype | 0:ad9600df4a70 | 130 | |
sype | 0:ad9600df4a70 | 131 | #endif |