Commit 9a37146148e100f503ef0dd919f4233b64795e18

Authored by pfrison
1 parent 004b9394

Programme robot

Robot/deplacement.c
... ... @@ -6,27 +6,36 @@
6 6 #define STEP_DROIT 0x20 // pin 12
7 7 #define DIR_DROIT 0x10 // pin 11
8 8  
  9 +// valeurs a remplacer par ceux donne par PercTeacher
9 10 const uint8_t deltaL[] = {};
10 11 const uint8_t delaiL[] = {};
11 12 const uint8_t deltaR[] = {};
12 13 const uint8_t delaiR[] = {};
13   -
14   -#define GAUCHE 0
15   -#define DROIT 1
  14 +#define N_DEPLACEMENT 0
16 15  
17 16 void init_deplacements(void){
18 17 DDRH |= STEP_GAUCHE | DIR_GAUCHE;
19 18 DDRB |= STEP_DROIT | DIR_DROIT;
20 19 }
21 20  
22   -uint16_t* deplacement_commande_suivante(uint16_t num){
  21 +static uint16_t* deplacement_commande_suivante(uint16_t num){
23 22 return {deltaL[num], delaiL[num], deltaR[num], delaiR[num]};
24 23 }
25 24  
26   -void deplacement_moteur_gauche(uint16_t delta, uint16_t delai){ deplacement_moteur(GAUCHE, delta, delai); }
27   -void deplacement_moteur_droit(uint16_t delta, uint16_t delai){ deplacement_moteur(DROIT, delta, delai); }
  25 +void deplacement(uint8_t mot){
  26 + int i;
  27 + for(i=0; i<N_DEPLACEMENT; i++){
  28 + uint16_t *commande = deplacement_commande_suivante(i);
  29 + if(mot == GAUCHE)
  30 + deplacement_moteur(mot, commande[0], commande[1]);
  31 + else
  32 + deplacement_moteur(mot, commande[2], commande[3]);
  33 + }
  34 +}
  35 +
28 36 static void deplacement_moteur(uint8_t mot, uint16_t delta, uint16_t delai){
29   - for(uint16_t i=0; i<delta; i++){
  37 + uint16_t i;
  38 + for(i=0; i<delta; i++){
30 39 if (mot == GAUCHE)
31 40 PORTH |= STEP_GAUCHE;
32 41 else if (mot == DROIT)
... ...
Robot/deplacement.h
1 1 #ifndef DEPLACEMENT
2 2 #define DEPLACEMENT
3 3  
4   -void init_deplacements(void){
5   - DDRH |= STEP_GAUCHE | DIR_GAUCHE;
6   - DDRB |= STEP_DROIT | DIR_DROIT;
7   -}
  4 +#define GAUCHE 0
  5 +#define DROIT 1
8 6  
9   -uint16_t* deplacement_commande_suivante(uint16_t num){
10   - return {deltaL[num], delaiL[num], deltaR[num], delaiR[num]};
11   -}
12   -
13   -void deplacement_moteur_gauche(uint16_t delta, uint16_t delai){ deplacement_moteur(GAUCHE, delta, delai); }
14   -void deplacement_moteur_droit(uint16_t delta, uint16_t delai){ deplacement_moteur(DROIT, delta, delai); }
15   -static void deplacement_moteur(uint8_t mot, uint16_t delta, uint16_t delai){
16   - for(uint16_t i=0; i<delta; i++){
17   - if (mot == GAUCHE)
18   - PORTH |= STEP_GAUCHE;
19   - else if (mot == DROIT)
20   - PORTB |= STEP_DROIT;
21   - _delay_ms(delai);
22   - if (mot == GAUCHE)
23   - PORTH &= ~STEP_GAUCHE;
24   - else if (mot == DROIT)
25   - PORTB &= ~STEP_DROIT;
26   - _delay_ms(delai);
27   - }
28   -}
  7 +void init_deplacements(void);
  8 +void deplacement(uint8_t mot);
29 9  
30 10 #endif
31 11 \ No newline at end of file
... ...
Robot/main.c
... ... @@ -4,18 +4,23 @@
4 4  
5 5 #include "serial.h"
6 6 #include "main.h"
  7 +#include "deplacement.h"
  8 +#include "tlc5947.h"
7 9  
8 10 #define NB_TICK 104 //1563
9 11  
10 12 /** ----- Taches ----- */
11   -void task_deplacement(void){
12   -
  13 +void task_deplacement_gauche(void){
  14 + deplacement(GAUCHE);
13 15 }
14   -void task_print_b(void){
15   - while(1){
16   - send_serial('b');
17   - _delay_ms(700);
18   - }
  16 +void task_deplacement_droit(void){
  17 + deplacement(DROIT);
  18 +}
  19 +void task_com_bluetooth(void){
  20 + // TODO
  21 +}
  22 +void task_leds(void){
  23 + // TODO
19 24 }
20 25  
21 26 /** ----- Ordonnancement ----- */
... ... @@ -24,8 +29,10 @@ struct task{
24 29 };
25 30 uint8_t cpt = 0;
26 31 uint8_t premier_lancement = 0;
27   -struct task deplacement = {0x0300};
28   -struct task print_b = {0x0500};
  32 +struct task deplacement_gauche = {0x0300};
  33 +struct task deplacement_droit = {0x0500};
  34 +struct task com_bluetooth = {0x0700};
  35 +struct task leds = {0x0900};
29 36  
30 37 // Démarre le timer pour l'ordonnancement
31 38 void init_timer(){
... ... @@ -41,26 +48,52 @@ ISR(TIMER1_COMPA_vect){
41 48 if(premier_lancement == 0){
42 49 premier_lancement++;
43 50 sei();
44   - SP = deplacement.sp_vise;
45   - task_deplacement();
  51 + SP = deplacement_gauche.sp_vise;
  52 + task_deplacement_gauche();
46 53 }else if(premier_lancement == 1){
47 54 SAVE_CONTEXT();
48   - deplacement.sp_vise = SP;
  55 + deplacement_gauche.sp_vise = SP;
  56 + premier_lancement++;
  57 + sei();
  58 + SP = deplacement_droit.sp_vise;
  59 + task_deplacement_droit();
  60 + }else if(premier_lancement == 2){
  61 + SAVE_CONTEXT();
  62 + deplacement_droit.sp_vise = SP;
49 63 premier_lancement++;
50 64 sei();
51   - SP = print_b.sp_vise;
52   - task_print_b();
  65 + SP = com_bluetooth.sp_vise;
  66 + task_com_bluetooth();
  67 + }else if(premier_lancement == 3){
  68 + SAVE_CONTEXT();
  69 + com_bluetooth.sp_vise = SP;
  70 + premier_lancement++;
  71 + sei();
  72 + SP = leds.sp_vise;
  73 + task_leds();
53 74 }else{
54 75 if(cpt==0){
55 76 SAVE_CONTEXT();
56   - print_b.sp_vise = SP;
57   - SP = deplacement.sp_vise;
  77 + com_bluetooth.sp_vise = SP;
  78 + SP = deplacement_gauche.sp_vise;
58 79 RESTORE_CONTEXT();
59 80 cpt++;
60 81 }else if(cpt==1){
61 82 SAVE_CONTEXT();
62   - deplacement.sp_vise = SP;
63   - SP = print_b.sp_vise;
  83 + deplacement_gauche.sp_vise = SP;
  84 + SP = deplacement_droit.sp_vise;
  85 + RESTORE_CONTEXT();
  86 + cpt++;
  87 + }else if(cpt==2){
  88 + SAVE_CONTEXT();
  89 + deplacement_droit.sp_vise = SP;
  90 + SP = com_bluetooth.sp_vise;
  91 + RESTORE_CONTEXT();
  92 + cpt++;
  93 + }else if(cpt==3){
  94 + SAVE_CONTEXT();
  95 + com_bluetooth.sp_vise = SP;
  96 + SP = leds.sp_vise;
64 97 RESTORE_CONTEXT();
65 98 cpt = 0;
66 99 }
... ... @@ -72,6 +105,7 @@ int main(void){
72 105 // Initialisation
73 106 init_timer();
74 107 init_serial(9600);
  108 + init_deplacement();
75 109 sei();
76 110  
77 111 while(1){}
... ...
Robot/tlc5947.c 0 → 100644
... ... @@ -0,0 +1,59 @@
  1 +#include <avr/io.h>
  2 +
  3 +#include "tlc5947.h"
  4 +
  5 +#define DDR_DLED_CLOCK DDRE
  6 +#define PORT_DLED_CLOCK PORTE
  7 +
  8 +#define DDR_DLED_DATA DDRG
  9 +#define PORT_DLED_DATA PORTG
  10 +
  11 +#define DDR_DLED_LATCH DDRB
  12 +#define PORT_DLED_LATCH PORTB
  13 +
  14 +#define PIN_DLED_CLOCK 0x08
  15 +#define PIN_DLED_DATA 0x20
  16 +#define PIN_DLED_LATCH 0x10
  17 +
  18 +void init_LED_Drivers(int nb){
  19 + // LED drivers I/O as outputs
  20 + DDR_DLED_CLOCK |= PIN_DLED_CLOCK;
  21 + DDR_DLED_DATA |= PIN_DLED_DATA;
  22 + DDR_DLED_LATCH |= PIN_DLED_LATCH;
  23 + // Set LATCH output low
  24 + PORT_DLED_LATCH &= ~PIN_DLED_LATCH;
  25 +}
  26 +
  27 +
  28 +void set_LED_Drivers(unsigned int pwm[], int nb){
  29 + // Set LATCH output low
  30 + PORT_DLED_LATCH &= ~PIN_DLED_LATCH;
  31 + // 24 channels per TLC5947
  32 + int i;
  33 + for(i=DLED_CHANNELS*nb-1; i>=0; i--){
  34 + // 12 bits per channel, send MSB first
  35 + int v=pwm[i];
  36 + int j;
  37 + for(j=0; j<12; j++){
  38 + // Set CLOCK output low
  39 + PORT_DLED_CLOCK &= ~PIN_DLED_CLOCK;
  40 +
  41 + // Set DATA as stated by bit #j of i
  42 + if(v & 0x0800)
  43 + PORT_DLED_DATA |= PIN_DLED_DATA;
  44 + else
  45 + PORT_DLED_DATA &= ~PIN_DLED_DATA;
  46 +
  47 + // Set CLOCK output HIGH
  48 + PORT_DLED_CLOCK |= PIN_DLED_CLOCK;
  49 + v <<= 1;
  50 + }
  51 + }
  52 + // Set CLOCK output low
  53 + PORT_DLED_CLOCK &= ~PIN_DLED_CLOCK;
  54 +
  55 + // Set LATCH output high
  56 + PORT_DLED_LATCH |= PIN_DLED_LATCH;
  57 + // Set LATCH output low
  58 + PORT_DLED_LATCH &= ~PIN_DLED_LATCH;
  59 +}
... ...
Robot/tlc5947.h 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +#ifndef TLC5947
  2 +#define TLC5947
  3 +
  4 +#define DLED_CHANNELS 24
  5 +
  6 +void init_LED_Drivers(int nb);
  7 +void set_LED_Drivers(unsigned int pwm[], int nb);
  8 +
  9 +#endif
... ...