deplacement v6
Fork of Deplacement by
Deplacement.cpp@12:5459169b6a52, 2017-03-23 (annotated)
- Committer:
- aure
- Date:
- Thu Mar 23 12:46:35 2017 +0000
- Revision:
- 12:5459169b6a52
- Parent:
- 11:5bc41c46cf28
fbuyfgygf
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 | 8:751dfd02c59e | 12 | this->vitesse=0.1; //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 | |
fab16 | 8:751dfd02c59e | 37 | m3piD.right(this->vitesse); |
fab16 | 8:751dfd02c59e | 38 | wait(0.9); |
aure | 4:bd8b50f91f81 | 39 | |
fab16 | 8:751dfd02c59e | 40 | m3piD.stop(); |
aure | 4:bd8b50f91f81 | 41 | |
aure | 2:7e0d789e1be8 | 42 | posx=copie; |
aure | 2:7e0d789e1be8 | 43 | posx=posy; |
aure | 2:7e0d789e1be8 | 44 | posy=-copie; |
aure | 2:7e0d789e1be8 | 45 | |
aure | 1:662d3c47637f | 46 | } |
aure | 1:662d3c47637f | 47 | |
aure | 1:662d3c47637f | 48 | void Deplacement::tourner_gauche() |
aure | 1:662d3c47637f | 49 | { |
fab16 | 8:751dfd02c59e | 50 | int copie=0; |
aure | 4:bd8b50f91f81 | 51 | |
fab16 | 8:751dfd02c59e | 52 | m3piD.left(this->vitesse); |
fab16 | 8:751dfd02c59e | 53 | wait(0.9); |
fab16 | 8:751dfd02c59e | 54 | m3piD.stop(); |
aure | 4:bd8b50f91f81 | 55 | |
aure | 4:bd8b50f91f81 | 56 | |
aure | 2:7e0d789e1be8 | 57 | posx=copie; |
aure | 2:7e0d789e1be8 | 58 | posx=-posy; |
aure | 2:7e0d789e1be8 | 59 | posy=copie; |
fab16 | 6:ad9dd32c18c7 | 60 | |
aure | 1:662d3c47637f | 61 | } |
aure | 1:662d3c47637f | 62 | |
aure | 12:5459169b6a52 | 63 | void Deplacement::avancer(float temps) |
aure | 1:662d3c47637f | 64 | { |
fab16 | 5:327f0df4ba8e | 65 | m3piD.forward(this->vitesse); |
fab16 | 11:5bc41c46cf28 | 66 | wait(temps); |
aure | 2:7e0d789e1be8 | 67 | posy++; |
fab16 | 8:751dfd02c59e | 68 | m3piD.stop(); |
aure | 1:662d3c47637f | 69 | } |
aure | 1:662d3c47637f | 70 | |
aure | 12:5459169b6a52 | 71 | void Deplacement::reculer(float temps) |
aure | 1:662d3c47637f | 72 | { |
fab16 | 9:832a3d20c4ee | 73 | m3piD.right(this->vitesse); |
fab16 | 9:832a3d20c4ee | 74 | wait(1.8); |
fab16 | 5:327f0df4ba8e | 75 | m3piD.backward(this->vitesse); |
fab16 | 11:5bc41c46cf28 | 76 | wait(temps); |
aure | 2:7e0d789e1be8 | 77 | posy--; |
fab16 | 8:751dfd02c59e | 78 | m3piD.stop(); |
fab16 | 8:751dfd02c59e | 79 | } |
fab16 | 8:751dfd02c59e | 80 | |
aure | 12:5459169b6a52 | 81 | void Deplacement::gauche(float temps){ |
fab16 | 8:751dfd02c59e | 82 | m3piD.left(this->vitesse); |
fab16 | 8:751dfd02c59e | 83 | wait(0.9); |
fab16 | 11:5bc41c46cf28 | 84 | avancer(temps); |
fab16 | 8:751dfd02c59e | 85 | } |
fab16 | 8:751dfd02c59e | 86 | |
aure | 12:5459169b6a52 | 87 | void Deplacement::droite(float temps){ |
fab16 | 8:751dfd02c59e | 88 | m3piD.right(this->vitesse); |
fab16 | 8:751dfd02c59e | 89 | wait(0.9); |
fab16 | 11:5bc41c46cf28 | 90 | avancer(temps); |
aure | 1:662d3c47637f | 91 | } |
aure | 1:662d3c47637f | 92 | |
aure | 3:965871a8c5ff | 93 | void Deplacement::stop() |
aure | 3:965871a8c5ff | 94 | { |
fab16 | 5:327f0df4ba8e | 95 | m3piD.stop(); |
aure | 3:965871a8c5ff | 96 | } |
aure | 3:965871a8c5ff | 97 | |
aure | 2:7e0d789e1be8 | 98 | void Deplacement::RAZ() |
aure | 2:7e0d789e1be8 | 99 | { |
aure | 2:7e0d789e1be8 | 100 | posx=0; |
fab16 | 5:327f0df4ba8e | 101 | posy=0; |
fab16 | 5:327f0df4ba8e | 102 | this->vitesse=0; |
aure | 2:7e0d789e1be8 | 103 | |
fab16 | 5:327f0df4ba8e | 104 | } |
aure | 1:662d3c47637f | 105 | |
aure | 3:965871a8c5ff | 106 | float Deplacement::getVitesse() |
fab16 | 5:327f0df4ba8e | 107 | { |
fab16 | 5:327f0df4ba8e | 108 | return(this->vitesse); |
fab16 | 5:327f0df4ba8e | 109 | } |
fab16 | 5:327f0df4ba8e | 110 | |
aure | 3:965871a8c5ff | 111 | int Deplacement::getPosX() |
fab16 | 5:327f0df4ba8e | 112 | { |
fab16 | 5:327f0df4ba8e | 113 | return(this->posx); |
fab16 | 5:327f0df4ba8e | 114 | } |
fab16 | 5:327f0df4ba8e | 115 | |
aure | 3:965871a8c5ff | 116 | int Deplacement::getPosY() |
fab16 | 5:327f0df4ba8e | 117 | { |
fab16 | 5:327f0df4ba8e | 118 | return(this->posy); |
fab16 | 5:327f0df4ba8e | 119 | } |
aure | 1:662d3c47637f | 120 | |
fab16 | 6:ad9dd32c18c7 | 121 | void Deplacement::tourner_droite_t() |
fab16 | 6:ad9dd32c18c7 | 122 | { |
fab16 | 6:ad9dd32c18c7 | 123 | |
fab16 | 6:ad9dd32c18c7 | 124 | m3piD.left_motor(this->vitesse); |
fab16 | 6:ad9dd32c18c7 | 125 | m3piD.right_motor(-(this->vitesse)); |
fab16 | 6:ad9dd32c18c7 | 126 | } |
fab16 | 6:ad9dd32c18c7 | 127 | |
fab16 | 10:00043b0d1e5e | 128 | void Deplacement::quartRotation(){ |
fab16 | 10:00043b0d1e5e | 129 | m3piD.right(this->vitesse); |
fab16 | 10:00043b0d1e5e | 130 | wait(0.9); |
fab16 | 10:00043b0d1e5e | 131 | m3piD.stop(); |
fab16 | 10:00043b0d1e5e | 132 | } |
fab16 | 10:00043b0d1e5e | 133 | |
aure | 1:662d3c47637f | 134 | |
aure | 1:662d3c47637f | 135 | |
aure | 1:662d3c47637f | 136 | |
aure | 1:662d3c47637f | 137 |