Commit 6a8060625fd11c8c0c9ae35f527016f3cf0e2bae
1 parent
d8927986
PercTeacher test robot concluant
Showing
1 changed file
with
22 additions
and
20 deletions
Show diff stats
PercTeacher/Sources/Robot/servoAndStepperControl.c
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | #include <util/delay.h> | 2 | #include <util/delay.h> |
3 | 3 | ||
4 | #define SERIAL_BAUDE_RATE 9600 | 4 | #define SERIAL_BAUDE_RATE 9600 |
5 | -#define DELAI_STEP 1000 | 5 | +#define DELAI_STEP 2 |
6 | #define PIN_MOTEUR_GAUCHE 0x40 // pin 12 | 6 | #define PIN_MOTEUR_GAUCHE 0x40 // pin 12 |
7 | #define PIN_MOTEUR_DROIT 0x20 // pin 11 | 7 | #define PIN_MOTEUR_DROIT 0x20 // pin 11 |
8 | 8 | ||
@@ -10,24 +10,20 @@ | @@ -10,24 +10,20 @@ | ||
10 | 10 | ||
11 | //gestion des moteurs | 11 | //gestion des moteurs |
12 | void init_pins(void){ | 12 | void init_pins(void){ |
13 | - // pin 12 et 11 | ||
14 | DDRB = PIN_MOTEUR_GAUCHE | PIN_MOTEUR_DROIT; | 13 | DDRB = PIN_MOTEUR_GAUCHE | PIN_MOTEUR_DROIT; |
15 | } | 14 | } |
16 | 15 | ||
17 | -void pas_moteur_gauche(void){ | ||
18 | - // pin 12 | ||
19 | - PORTB |= PIN_MOTEUR_GAUCHE; | ||
20 | - _delay_us(DELAI_STEP); | ||
21 | - PORTB &= ~PIN_MOTEUR_GAUCHE; | ||
22 | - _delay_us(DELAI_STEP); | ||
23 | -} | ||
24 | - | ||
25 | -void pas_moteur_droit(void){ | ||
26 | - // pin 11 | ||
27 | - PORTB |= PIN_MOTEUR_DROIT; | ||
28 | - _delay_us(DELAI_STEP); | ||
29 | - PORTB &= ~PIN_MOTEUR_DROIT; | ||
30 | - _delay_us(DELAI_STEP); | 16 | +void pas_moteur(int g, int d){ |
17 | + if (g) | ||
18 | + PORTB |= PIN_MOTEUR_GAUCHE; | ||
19 | + if (d) | ||
20 | + PORTB |= PIN_MOTEUR_DROIT; | ||
21 | + _delay_ms(DELAI_STEP); | ||
22 | + if (g) | ||
23 | + PORTB &= ~PIN_MOTEUR_GAUCHE; | ||
24 | + if (d) | ||
25 | + PORTB &= ~PIN_MOTEUR_DROIT; | ||
26 | + _delay_ms(DELAI_STEP); | ||
31 | } | 27 | } |
32 | 28 | ||
33 | //gestion de la liaison serie | 29 | //gestion de la liaison serie |
@@ -57,6 +53,9 @@ int main(void){ | @@ -57,6 +53,9 @@ int main(void){ | ||
57 | unsigned char deltaL2 = get_serial(); | 53 | unsigned char deltaL2 = get_serial(); |
58 | unsigned char deltaR1 = get_serial(); | 54 | unsigned char deltaR1 = get_serial(); |
59 | unsigned char deltaR2 = get_serial(); | 55 | unsigned char deltaR2 = get_serial(); |
56 | + | ||
57 | + | ||
58 | + send_serial('a'); | ||
60 | 59 | ||
61 | // conversion 2x8 bits => 16 bits | 60 | // conversion 2x8 bits => 16 bits |
62 | int deltaL = (deltaL1 << 8) + deltaL2; | 61 | int deltaL = (deltaL1 << 8) + deltaL2; |
@@ -64,12 +63,15 @@ int main(void){ | @@ -64,12 +63,15 @@ int main(void){ | ||
64 | 63 | ||
65 | int deltaMax = deltaL > deltaR ? deltaL : deltaR; | 64 | int deltaMax = deltaL > deltaR ? deltaL : deltaR; |
66 | for(int i=0; i<deltaMax; i++){ | 65 | for(int i=0; i<deltaMax; i++){ |
67 | - if(deltaL > i) | ||
68 | - pas_moteur_gauche(); | ||
69 | - if(deltaR > i) | ||
70 | - pas_moteur_droit(); | 66 | + if(deltaL > i && deltaR > i) |
67 | + pas_moteur(1, 1); | ||
68 | + else if(deltaL > i) | ||
69 | + pas_moteur(1, 0); | ||
70 | + else if(deltaR > i) | ||
71 | + pas_moteur(0, 1); | ||
71 | } | 72 | } |
72 | 73 | ||
74 | + send_serial('b'); | ||
73 | send_serial(0x01); | 75 | send_serial(0x01); |
74 | } | 76 | } |
75 | return 0; | 77 | return 0; |