Robot secondaire
Dependencies: RoboClaw mbed StepperMotor
Fork of RoboClaw by
Functions/func.cpp@48:03da1aead032, 2016-04-28 (annotated)
- Committer:
- sype
- Date:
- Thu Apr 28 08:11:25 2016 +0000
- Revision:
- 48:03da1aead032
- Parent:
- 46:5658af4e5149
- Child:
- 51:1056dd73a748
Int?gration de "l'algo" carte boutons, maintenant le bouton bleu (utilisateur) est remplac? par le jumper pr?sent sur la carte (on le retire pour d?marrer) et le changement de camp du robot se fait par le bouton pr?sent sur cette carte
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sype | 41:b5a2fbc20beb | 1 | #include "func.h" |
sype | 41:b5a2fbc20beb | 2 | |
sype | 41:b5a2fbc20beb | 3 | void pressed(void) |
sype | 41:b5a2fbc20beb | 4 | { |
sype | 46:5658af4e5149 | 5 | if(SIMON_i==0) { |
sype | 46:5658af4e5149 | 6 | roboclaw.ForwardM1(0); |
sype | 46:5658af4e5149 | 7 | roboclaw.ForwardM2(0); |
sype | 46:5658af4e5149 | 8 | SIMON_i++; |
sype | 41:b5a2fbc20beb | 9 | } |
sype | 41:b5a2fbc20beb | 10 | } |
sype | 41:b5a2fbc20beb | 11 | |
sype | 41:b5a2fbc20beb | 12 | void unpressed(void) |
sype | 41:b5a2fbc20beb | 13 | { |
sype | 46:5658af4e5149 | 14 | if(SIMON_i==1) { |
sype | 46:5658af4e5149 | 15 | SIMON_i--; |
sype | 41:b5a2fbc20beb | 16 | } |
sype | 41:b5a2fbc20beb | 17 | } |
sype | 41:b5a2fbc20beb | 18 | |
sype | 41:b5a2fbc20beb | 19 | void ELpressed(void) |
sype | 41:b5a2fbc20beb | 20 | { |
sype | 46:5658af4e5149 | 21 | bleu = 1; |
sype | 46:5658af4e5149 | 22 | SIMON_EL = true; |
sype | 41:b5a2fbc20beb | 23 | } |
sype | 41:b5a2fbc20beb | 24 | void ELunpressed(void) |
sype | 41:b5a2fbc20beb | 25 | { |
sype | 46:5658af4e5149 | 26 | bleu = 0; |
sype | 46:5658af4e5149 | 27 | SIMON_EL = false; |
sype | 41:b5a2fbc20beb | 28 | } |
sype | 41:b5a2fbc20beb | 29 | |
sype | 41:b5a2fbc20beb | 30 | void EZpressed(void) |
sype | 41:b5a2fbc20beb | 31 | { |
sype | 46:5658af4e5149 | 32 | blanc = 1; |
sype | 46:5658af4e5149 | 33 | SIMON_EZ = true; |
sype | 41:b5a2fbc20beb | 34 | } |
sype | 41:b5a2fbc20beb | 35 | void EZunpressed(void) |
sype | 41:b5a2fbc20beb | 36 | { |
sype | 46:5658af4e5149 | 37 | blanc = 0; |
sype | 46:5658af4e5149 | 38 | SIMON_EZ = false; |
sype | 41:b5a2fbc20beb | 39 | } |
sype | 41:b5a2fbc20beb | 40 | |
sype | 41:b5a2fbc20beb | 41 | void ERpressed(void) |
sype | 41:b5a2fbc20beb | 42 | { |
sype | 46:5658af4e5149 | 43 | rouge = 1; |
sype | 46:5658af4e5149 | 44 | SIMON_ER = true; |
sype | 41:b5a2fbc20beb | 45 | } |
sype | 41:b5a2fbc20beb | 46 | void ERunpressed(void) |
sype | 41:b5a2fbc20beb | 47 | { |
sype | 46:5658af4e5149 | 48 | rouge = 0; |
sype | 46:5658af4e5149 | 49 | SIMON_ER = 0; |
sype | 41:b5a2fbc20beb | 50 | } |
sype | 41:b5a2fbc20beb | 51 | |
sype | 41:b5a2fbc20beb | 52 | void JPO(void) |
sype | 41:b5a2fbc20beb | 53 | { |
sype | 41:b5a2fbc20beb | 54 | char c = logger.getc(); |
sype | 41:b5a2fbc20beb | 55 | if(c=='z') { |
sype | 46:5658af4e5149 | 56 | if (SIMON_state != 1) { |
sype | 46:5658af4e5149 | 57 | SIMON_state = 1; |
sype | 41:b5a2fbc20beb | 58 | logger.printf("Avant (Z) \r\n"); |
sype | 46:5658af4e5149 | 59 | roboclaw.SpeedAccelM1(accel_angle, vitesse_angle); |
sype | 46:5658af4e5149 | 60 | roboclaw.SpeedAccelM2(accel_angle, vitesse_angle); |
sype | 41:b5a2fbc20beb | 61 | } |
sype | 41:b5a2fbc20beb | 62 | } else if(c == 's') { |
sype | 46:5658af4e5149 | 63 | if (SIMON_state != 2) { |
sype | 46:5658af4e5149 | 64 | SIMON_state = 2; |
sype | 41:b5a2fbc20beb | 65 | logger.printf("Stop (S) \r\n"); |
sype | 46:5658af4e5149 | 66 | roboclaw.SpeedAccelM1(accel_angle, 0); |
sype | 46:5658af4e5149 | 67 | roboclaw.SpeedAccelM2(accel_angle, 0); |
sype | 41:b5a2fbc20beb | 68 | } |
sype | 41:b5a2fbc20beb | 69 | } else if(c == 'd') { |
sype | 46:5658af4e5149 | 70 | if (SIMON_state != 3) { |
sype | 46:5658af4e5149 | 71 | SIMON_state = 3; |
sype | 41:b5a2fbc20beb | 72 | logger.printf("Droite (D) \r\n"); |
sype | 46:5658af4e5149 | 73 | roboclaw.SpeedAccelM1(accel_angle, -vitesse_angle); |
sype | 46:5658af4e5149 | 74 | roboclaw.SpeedAccelM2(accel_angle, vitesse_angle); |
sype | 41:b5a2fbc20beb | 75 | } |
sype | 41:b5a2fbc20beb | 76 | } else if(c == 'q') { |
sype | 46:5658af4e5149 | 77 | if (SIMON_state != 4) { |
sype | 46:5658af4e5149 | 78 | SIMON_state = 4; |
sype | 41:b5a2fbc20beb | 79 | logger.printf("Gauche (Q)\r\n"); |
sype | 46:5658af4e5149 | 80 | roboclaw.SpeedAccelM1(accel_angle, vitesse_angle); |
sype | 46:5658af4e5149 | 81 | roboclaw.SpeedAccelM2(accel_angle, -vitesse_angle); |
sype | 41:b5a2fbc20beb | 82 | } |
sype | 41:b5a2fbc20beb | 83 | } else if(c == 'x') { |
sype | 46:5658af4e5149 | 84 | if (SIMON_state != 5) { |
sype | 46:5658af4e5149 | 85 | SIMON_state = 5; |
sype | 46:5658af4e5149 | 86 | roboclaw.SpeedAccelM1(accel_angle, -vitesse_angle); |
sype | 46:5658af4e5149 | 87 | roboclaw.SpeedAccelM2(accel_angle, -vitesse_angle); |
sype | 41:b5a2fbc20beb | 88 | } |
sype | 41:b5a2fbc20beb | 89 | } else { |
sype | 46:5658af4e5149 | 90 | if (SIMON_state != 0) { |
sype | 46:5658af4e5149 | 91 | roboclaw.SpeedAccelM1M2(accel_angle, 0, accel_angle, 0); |
sype | 46:5658af4e5149 | 92 | SIMON_state = 0; |
sype | 41:b5a2fbc20beb | 93 | } |
sype | 41:b5a2fbc20beb | 94 | } |
sype | 41:b5a2fbc20beb | 95 | } |
sype | 41:b5a2fbc20beb | 96 | |
sype | 41:b5a2fbc20beb | 97 | void goHome(void) |
sype | 41:b5a2fbc20beb | 98 | { |
sype | 46:5658af4e5149 | 99 | //while(EZ==false) ZMot.step(1, 0, DELAY); |
sype | 46:5658af4e5149 | 100 | while(SIMON_ER==false) RMot.step(1, 0, DELAY); |
sype | 46:5658af4e5149 | 101 | RMot.step(10, 1, DELAY+0.01); |
sype | 41:b5a2fbc20beb | 102 | RMot.step(5, 0, DELAY); |
sype | 46:5658af4e5149 | 103 | while(SIMON_EL==false) LMot.step(1, 0, DELAY); |
sype | 46:5658af4e5149 | 104 | LMot.step(10, 1, DELAY+0.01); |
sype | 41:b5a2fbc20beb | 105 | LMot.step(5, 0, DELAY); |
sype | 41:b5a2fbc20beb | 106 | } |
sype | 41:b5a2fbc20beb | 107 | |
sype | 41:b5a2fbc20beb | 108 | void checkAround(void) |
sype | 41:b5a2fbc20beb | 109 | { |
sype | 41:b5a2fbc20beb | 110 | if(capt1 > SEUIL+0.1) bleu = 1; |
sype | 41:b5a2fbc20beb | 111 | else bleu = 0; |
sype | 41:b5a2fbc20beb | 112 | if(capt2 > SEUIL) blanc = 1; |
sype | 41:b5a2fbc20beb | 113 | else blanc = 0; |
sype | 41:b5a2fbc20beb | 114 | if(capt3 > SEUIL+0.1) rouge = 1; |
sype | 41:b5a2fbc20beb | 115 | else rouge = 0; |
sype | 41:b5a2fbc20beb | 116 | } |
sype | 41:b5a2fbc20beb | 117 | |
sype | 48:03da1aead032 | 118 | /*void init_ax12(void) |
sype | 41:b5a2fbc20beb | 119 | { |
sype | 41:b5a2fbc20beb | 120 | left_hand.setMode(0); |
sype | 41:b5a2fbc20beb | 121 | wait_ms(10); |
sype | 41:b5a2fbc20beb | 122 | right_hand.setMode(0); |
sype | 41:b5a2fbc20beb | 123 | wait_ms(50); |
sype | 41:b5a2fbc20beb | 124 | left_hand.setMode(0); |
sype | 41:b5a2fbc20beb | 125 | wait_ms(10); |
sype | 41:b5a2fbc20beb | 126 | right_hand.setMode(0); |
sype | 41:b5a2fbc20beb | 127 | wait_ms(50); |
sype | 41:b5a2fbc20beb | 128 | right_hand.setGoal(0); |
sype | 41:b5a2fbc20beb | 129 | left_hand.setGoal(0); |
sype | 41:b5a2fbc20beb | 130 | wait(2); |
sype | 41:b5a2fbc20beb | 131 | right_hand.setGoal(180); |
sype | 41:b5a2fbc20beb | 132 | left_hand.setGoal(180); |
sype | 41:b5a2fbc20beb | 133 | wait(2); |
sype | 48:03da1aead032 | 134 | }*/ |
sype | 44:b1fd7489369f | 135 | |
sype | 44:b1fd7489369f | 136 | void init_interrupt(void) |
sype | 44:b1fd7489369f | 137 | { |
sype | 46:5658af4e5149 | 138 | CAMP.fall(&changeCamp); |
sype | 48:03da1aead032 | 139 | START.rise(&go); |
sype | 44:b1fd7489369f | 140 | mybutton.fall(&pressed); |
sype | 44:b1fd7489369f | 141 | mybutton.rise(&unpressed); |
sype | 44:b1fd7489369f | 142 | EndL.fall(&ELpressed); |
sype | 44:b1fd7489369f | 143 | EndL.rise(&ELunpressed); |
sype | 44:b1fd7489369f | 144 | EndZ.fall(&EZpressed); |
sype | 44:b1fd7489369f | 145 | EndZ.rise(&EZunpressed); |
sype | 44:b1fd7489369f | 146 | EndR.fall(&ERpressed); |
sype | 44:b1fd7489369f | 147 | EndR.rise(&ERunpressed); |
sype | 48:03da1aead032 | 148 | ticker.attach_us(&update_main, dt); // 100 Hz |
sype | 46:5658af4e5149 | 149 | } |
sype | 46:5658af4e5149 | 150 | |
sype | 46:5658af4e5149 | 151 | void changeCamp(void) |
sype | 46:5658af4e5149 | 152 | { |
sype | 48:03da1aead032 | 153 | if(SCouleur==VERT) { |
sype | 48:03da1aead032 | 154 | SCouleur = VIOLET; |
sype | 48:03da1aead032 | 155 | LEDR = 1; |
sype | 48:03da1aead032 | 156 | LEDV = 0; |
sype | 48:03da1aead032 | 157 | } |
sype | 48:03da1aead032 | 158 | else { |
sype | 48:03da1aead032 | 159 | SCouleur = VERT; |
sype | 48:03da1aead032 | 160 | LEDV = 1; |
sype | 48:03da1aead032 | 161 | LEDR = 0; |
sype | 48:03da1aead032 | 162 | } |
sype | 46:5658af4e5149 | 163 | } |
sype | 46:5658af4e5149 | 164 | |
sype | 48:03da1aead032 | 165 | void go(void) |
sype | 45:b53ae54062c6 | 166 | { |
sype | 48:03da1aead032 | 167 | SStart = 1; |
sype | 41:b5a2fbc20beb | 168 | } |