deplacement v6
Fork of Deplacement by
Deplacement.cpp@6:ad9dd32c18c7, 2017-02-09 (annotated)
- Committer:
- fab16
- Date:
- Thu Feb 09 16:14:08 2017 +0000
- Revision:
- 6:ad9dd32c18c7
- Parent:
- 5:327f0df4ba8e
- Child:
- 7:cc426369e073
v3
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 | init(0.2); |
fab16 | 6:ad9dd32c18c7 | 14 | } |
fab16 | 6:ad9dd32c18c7 | 15 | |
fab16 | 6:ad9dd32c18c7 | 16 | void Deplacement::init(float val){ |
fab16 | 6:ad9dd32c18c7 | 17 | m3piD.right_motor(val); |
fab16 | 6:ad9dd32c18c7 | 18 | m3piD.left_motor(val); |
aure | 1:662d3c47637f | 19 | } |
aure | 1:662d3c47637f | 20 | |
aure | 1:662d3c47637f | 21 | Deplacement::~Deplacement() |
aure | 0:d6b2da5ef6cb | 22 | { |
fab16 | 5:327f0df4ba8e | 23 | |
aure | 1:662d3c47637f | 24 | } |
aure | 1:662d3c47637f | 25 | ///////////////////////////////////////////////////// |
aure | 1:662d3c47637f | 26 | |
aure | 1:662d3c47637f | 27 | void Deplacement::setVitesse(float v) |
aure | 1:662d3c47637f | 28 | { |
fab16 | 5:327f0df4ba8e | 29 | this->vitesse=v; |
aure | 1:662d3c47637f | 30 | } |
aure | 1:662d3c47637f | 31 | |
aure | 1:662d3c47637f | 32 | ///////////////////////////////////////////////////// |
aure | 1:662d3c47637f | 33 | |
aure | 1:662d3c47637f | 34 | void Deplacement::tourner_droite() |
aure | 1:662d3c47637f | 35 | { |
aure | 2:7e0d789e1be8 | 36 | int copie=0; |
aure | 4:bd8b50f91f81 | 37 | |
aure | 4:bd8b50f91f81 | 38 | t.reset(); |
aure | 4:bd8b50f91f81 | 39 | t.start(); |
aure | 4:bd8b50f91f81 | 40 | |
fab16 | 5:327f0df4ba8e | 41 | while((t.read_ms())!=this->mseconds) |
fab16 | 5:327f0df4ba8e | 42 | m3piD.right(this->vitesse); |
aure | 2:7e0d789e1be8 | 43 | |
aure | 4:bd8b50f91f81 | 44 | t.stop(); |
aure | 4:bd8b50f91f81 | 45 | |
aure | 2:7e0d789e1be8 | 46 | posx=copie; |
aure | 2:7e0d789e1be8 | 47 | posx=posy; |
aure | 2:7e0d789e1be8 | 48 | posy=-copie; |
aure | 2:7e0d789e1be8 | 49 | |
aure | 1:662d3c47637f | 50 | } |
aure | 1:662d3c47637f | 51 | |
aure | 1:662d3c47637f | 52 | void Deplacement::tourner_gauche() |
aure | 1:662d3c47637f | 53 | { |
fab16 | 6:ad9dd32c18c7 | 54 | int copie=0; |
aure | 4:bd8b50f91f81 | 55 | |
aure | 4:bd8b50f91f81 | 56 | t.reset(); |
aure | 4:bd8b50f91f81 | 57 | t.start(); |
aure | 4:bd8b50f91f81 | 58 | |
fab16 | 5:327f0df4ba8e | 59 | while((t.read_ms())!=this->mseconds) |
fab16 | 5:327f0df4ba8e | 60 | m3piD.left(this->vitesse); |
aure | 2:7e0d789e1be8 | 61 | |
aure | 4:bd8b50f91f81 | 62 | t.stop(); |
aure | 4:bd8b50f91f81 | 63 | |
aure | 4:bd8b50f91f81 | 64 | |
aure | 2:7e0d789e1be8 | 65 | posx=copie; |
aure | 2:7e0d789e1be8 | 66 | posx=-posy; |
aure | 2:7e0d789e1be8 | 67 | posy=copie; |
fab16 | 6:ad9dd32c18c7 | 68 | |
aure | 1:662d3c47637f | 69 | } |
aure | 1:662d3c47637f | 70 | |
aure | 1:662d3c47637f | 71 | void Deplacement::avancer() |
aure | 1:662d3c47637f | 72 | { |
fab16 | 5:327f0df4ba8e | 73 | m3piD.forward(this->vitesse); |
aure | 2:7e0d789e1be8 | 74 | posy++; |
aure | 1:662d3c47637f | 75 | } |
aure | 1:662d3c47637f | 76 | |
aure | 1:662d3c47637f | 77 | void Deplacement::reculer() |
aure | 1:662d3c47637f | 78 | { |
fab16 | 5:327f0df4ba8e | 79 | m3piD.backward(this->vitesse); |
aure | 2:7e0d789e1be8 | 80 | posy--; |
aure | 1:662d3c47637f | 81 | } |
aure | 1:662d3c47637f | 82 | |
aure | 3:965871a8c5ff | 83 | void Deplacement::stop() |
aure | 3:965871a8c5ff | 84 | { |
fab16 | 5:327f0df4ba8e | 85 | m3piD.stop(); |
aure | 3:965871a8c5ff | 86 | } |
aure | 3:965871a8c5ff | 87 | |
aure | 2:7e0d789e1be8 | 88 | void Deplacement::RAZ() |
aure | 2:7e0d789e1be8 | 89 | { |
aure | 2:7e0d789e1be8 | 90 | posx=0; |
fab16 | 5:327f0df4ba8e | 91 | posy=0; |
fab16 | 5:327f0df4ba8e | 92 | this->vitesse=0; |
aure | 2:7e0d789e1be8 | 93 | |
fab16 | 5:327f0df4ba8e | 94 | } |
aure | 1:662d3c47637f | 95 | |
aure | 3:965871a8c5ff | 96 | float Deplacement::getVitesse() |
fab16 | 5:327f0df4ba8e | 97 | { |
fab16 | 5:327f0df4ba8e | 98 | return(this->vitesse); |
fab16 | 5:327f0df4ba8e | 99 | } |
fab16 | 5:327f0df4ba8e | 100 | |
aure | 3:965871a8c5ff | 101 | int Deplacement::getPosX() |
fab16 | 5:327f0df4ba8e | 102 | { |
fab16 | 5:327f0df4ba8e | 103 | return(this->posx); |
fab16 | 5:327f0df4ba8e | 104 | } |
fab16 | 5:327f0df4ba8e | 105 | |
aure | 3:965871a8c5ff | 106 | int Deplacement::getPosY() |
fab16 | 5:327f0df4ba8e | 107 | { |
fab16 | 5:327f0df4ba8e | 108 | return(this->posy); |
fab16 | 5:327f0df4ba8e | 109 | } |
aure | 1:662d3c47637f | 110 | |
fab16 | 6:ad9dd32c18c7 | 111 | void Deplacement::tourner_droite_t() |
fab16 | 6:ad9dd32c18c7 | 112 | { |
fab16 | 6:ad9dd32c18c7 | 113 | |
fab16 | 6:ad9dd32c18c7 | 114 | m3piD.left_motor(this->vitesse); |
fab16 | 6:ad9dd32c18c7 | 115 | m3piD.right_motor(-(this->vitesse)); |
fab16 | 6:ad9dd32c18c7 | 116 | } |
fab16 | 6:ad9dd32c18c7 | 117 | |
aure | 1:662d3c47637f | 118 | |
aure | 1:662d3c47637f | 119 | |
aure | 1:662d3c47637f | 120 | |
aure | 1:662d3c47637f | 121 |