deplacement v6
Fork of Deplacement by
Deplacement.cpp@7:cc426369e073, 2017-02-23 (annotated)
- Committer:
- fab16
- Date:
- Thu Feb 23 09:18:05 2017 +0000
- Revision:
- 7:cc426369e073
- Parent:
- 6:ad9dd32c18c7
- Child:
- 8:751dfd02c59e
v4
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aure | 0:d6b2da5ef6cb | 1 | #include "Deplacement.h" |
aure | 1:662d3c47637f | 2 | #include "mbed.h" |
fab16 | 5:327f0df4ba8e | 3 | |
fab16 | 5:327f0df4ba8e | 4 | m3pi m3piD; |
aure | 0:d6b2da5ef6cb | 5 | |
aure | 1:662d3c47637f | 6 | Deplacement::Deplacement() //constructeur |
aure | 1:662d3c47637f | 7 | { |
aure | 4:bd8b50f91f81 | 8 | |
fab16 | 5:327f0df4ba8e | 9 | this->mseconds=30;// temps pour la rotation une fois valeur trouvé ne pas changer |
fab16 | 5:327f0df4ba8e | 10 | posx=0; |
fab16 | 5:327f0df4ba8e | 11 | posy=0; |
fab16 | 5:327f0df4ba8e | 12 | this->vitesse=0; //pointeur this |
fab16 | 6:ad9dd32c18c7 | 13 | } |
fab16 | 6:ad9dd32c18c7 | 14 | |
fab16 | 6:ad9dd32c18c7 | 15 | void Deplacement::init(float val){ |
fab16 | 6:ad9dd32c18c7 | 16 | m3piD.right_motor(val); |
fab16 | 6:ad9dd32c18c7 | 17 | m3piD.left_motor(val); |
aure | 1:662d3c47637f | 18 | } |
aure | 1:662d3c47637f | 19 | |
aure | 1:662d3c47637f | 20 | Deplacement::~Deplacement() |
aure | 0:d6b2da5ef6cb | 21 | { |
fab16 | 5:327f0df4ba8e | 22 | |
aure | 1:662d3c47637f | 23 | } |
aure | 1:662d3c47637f | 24 | ///////////////////////////////////////////////////// |
aure | 1:662d3c47637f | 25 | |
aure | 1:662d3c47637f | 26 | void Deplacement::setVitesse(float v) |
aure | 1:662d3c47637f | 27 | { |
fab16 | 5:327f0df4ba8e | 28 | this->vitesse=v; |
aure | 1:662d3c47637f | 29 | } |
aure | 1:662d3c47637f | 30 | |
aure | 1:662d3c47637f | 31 | ///////////////////////////////////////////////////// |
aure | 1:662d3c47637f | 32 | |
aure | 1:662d3c47637f | 33 | void Deplacement::tourner_droite() |
aure | 1:662d3c47637f | 34 | { |
aure | 2:7e0d789e1be8 | 35 | int copie=0; |
aure | 4:bd8b50f91f81 | 36 | |
aure | 4:bd8b50f91f81 | 37 | t.reset(); |
aure | 4:bd8b50f91f81 | 38 | t.start(); |
aure | 4:bd8b50f91f81 | 39 | |
fab16 | 5:327f0df4ba8e | 40 | while((t.read_ms())!=this->mseconds) |
fab16 | 5:327f0df4ba8e | 41 | m3piD.right(this->vitesse); |
aure | 2:7e0d789e1be8 | 42 | |
aure | 4:bd8b50f91f81 | 43 | t.stop(); |
aure | 4:bd8b50f91f81 | 44 | |
aure | 2:7e0d789e1be8 | 45 | posx=copie; |
aure | 2:7e0d789e1be8 | 46 | posx=posy; |
aure | 2:7e0d789e1be8 | 47 | posy=-copie; |
aure | 2:7e0d789e1be8 | 48 | |
aure | 1:662d3c47637f | 49 | } |
aure | 1:662d3c47637f | 50 | |
aure | 1:662d3c47637f | 51 | void Deplacement::tourner_gauche() |
aure | 1:662d3c47637f | 52 | { |
fab16 | 6:ad9dd32c18c7 | 53 | int copie=0; |
aure | 4:bd8b50f91f81 | 54 | |
aure | 4:bd8b50f91f81 | 55 | t.reset(); |
aure | 4:bd8b50f91f81 | 56 | t.start(); |
aure | 4:bd8b50f91f81 | 57 | |
fab16 | 5:327f0df4ba8e | 58 | while((t.read_ms())!=this->mseconds) |
fab16 | 5:327f0df4ba8e | 59 | m3piD.left(this->vitesse); |
aure | 2:7e0d789e1be8 | 60 | |
aure | 4:bd8b50f91f81 | 61 | t.stop(); |
aure | 4:bd8b50f91f81 | 62 | |
aure | 4:bd8b50f91f81 | 63 | |
aure | 2:7e0d789e1be8 | 64 | posx=copie; |
aure | 2:7e0d789e1be8 | 65 | posx=-posy; |
aure | 2:7e0d789e1be8 | 66 | posy=copie; |
fab16 | 6:ad9dd32c18c7 | 67 | |
aure | 1:662d3c47637f | 68 | } |
aure | 1:662d3c47637f | 69 | |
aure | 1:662d3c47637f | 70 | void Deplacement::avancer() |
aure | 1:662d3c47637f | 71 | { |
fab16 | 5:327f0df4ba8e | 72 | m3piD.forward(this->vitesse); |
aure | 2:7e0d789e1be8 | 73 | posy++; |
aure | 1:662d3c47637f | 74 | } |
aure | 1:662d3c47637f | 75 | |
aure | 1:662d3c47637f | 76 | void Deplacement::reculer() |
aure | 1:662d3c47637f | 77 | { |
fab16 | 5:327f0df4ba8e | 78 | m3piD.backward(this->vitesse); |
aure | 2:7e0d789e1be8 | 79 | posy--; |
aure | 1:662d3c47637f | 80 | } |
aure | 1:662d3c47637f | 81 | |
aure | 3:965871a8c5ff | 82 | void Deplacement::stop() |
aure | 3:965871a8c5ff | 83 | { |
fab16 | 5:327f0df4ba8e | 84 | m3piD.stop(); |
aure | 3:965871a8c5ff | 85 | } |
aure | 3:965871a8c5ff | 86 | |
aure | 2:7e0d789e1be8 | 87 | void Deplacement::RAZ() |
aure | 2:7e0d789e1be8 | 88 | { |
aure | 2:7e0d789e1be8 | 89 | posx=0; |
fab16 | 5:327f0df4ba8e | 90 | posy=0; |
fab16 | 5:327f0df4ba8e | 91 | this->vitesse=0; |
aure | 2:7e0d789e1be8 | 92 | |
fab16 | 5:327f0df4ba8e | 93 | } |
aure | 1:662d3c47637f | 94 | |
aure | 3:965871a8c5ff | 95 | float Deplacement::getVitesse() |
fab16 | 5:327f0df4ba8e | 96 | { |
fab16 | 5:327f0df4ba8e | 97 | return(this->vitesse); |
fab16 | 5:327f0df4ba8e | 98 | } |
fab16 | 5:327f0df4ba8e | 99 | |
aure | 3:965871a8c5ff | 100 | int Deplacement::getPosX() |
fab16 | 5:327f0df4ba8e | 101 | { |
fab16 | 5:327f0df4ba8e | 102 | return(this->posx); |
fab16 | 5:327f0df4ba8e | 103 | } |
fab16 | 5:327f0df4ba8e | 104 | |
aure | 3:965871a8c5ff | 105 | int Deplacement::getPosY() |
fab16 | 5:327f0df4ba8e | 106 | { |
fab16 | 5:327f0df4ba8e | 107 | return(this->posy); |
fab16 | 5:327f0df4ba8e | 108 | } |
aure | 1:662d3c47637f | 109 | |
fab16 | 6:ad9dd32c18c7 | 110 | void Deplacement::tourner_droite_t() |
fab16 | 6:ad9dd32c18c7 | 111 | { |
fab16 | 6:ad9dd32c18c7 | 112 | |
fab16 | 6:ad9dd32c18c7 | 113 | m3piD.left_motor(this->vitesse); |
fab16 | 6:ad9dd32c18c7 | 114 | m3piD.right_motor(-(this->vitesse)); |
fab16 | 6:ad9dd32c18c7 | 115 | } |
fab16 | 6:ad9dd32c18c7 | 116 | |
aure | 1:662d3c47637f | 117 | |
aure | 1:662d3c47637f | 118 | |
aure | 1:662d3c47637f | 119 | |
aure | 1:662d3c47637f | 120 |