Commit bd56dbdb61d294b252dd4255816db16c64d6e4a9

Authored by pfrison
2 parents 278cdee0 9ce6804b

Merge branch 'master' of https://archives.plil.fr/pfrison/projet-crep

Showing 31 changed files with 284 additions and 42 deletions   Show diff stats
PercTeacher/Sources/Action.java renamed to PercTeacher/Sources/ApplicationJava/Action.java
PercTeacher/Sources/ActionList.java renamed to PercTeacher/Sources/ApplicationJava/ActionList.java
PercTeacher/Sources/ImportExport.java renamed to PercTeacher/Sources/ApplicationJava/ImportExport.java
PercTeacher/Sources/Interface.java renamed to PercTeacher/Sources/ApplicationJava/Interface.java
PercTeacher/Sources/InvalidActionListArrays.java renamed to PercTeacher/Sources/ApplicationJava/InvalidActionListArrays.java
PercTeacher/Sources/InvalidInputException.java renamed to PercTeacher/Sources/ApplicationJava/InvalidInputException.java
PercTeacher/Sources/Main.java renamed to PercTeacher/Sources/ApplicationJava/Main.java
PercTeacher/Sources/NoSerialPortException.java renamed to PercTeacher/Sources/ApplicationJava/NoSerialPortException.java
PercTeacher/Sources/SerialCom.java renamed to PercTeacher/Sources/ApplicationJava/SerialCom.java
PercTeacher/Sources/SerialComPortException.java renamed to PercTeacher/Sources/ApplicationJava/SerialComPortException.java
PercTeacher/Sources/SerialComWrongCallbackMethod.java renamed to PercTeacher/Sources/ApplicationJava/SerialComWrongCallbackMethod.java
PercTeacher/Sources/SerialCommands.java renamed to PercTeacher/Sources/ApplicationJava/SerialCommands.java
PercTeacher/Sources/SerialPortChooserDialog.java renamed to PercTeacher/Sources/ApplicationJava/SerialPortChooserDialog.java
PercTeacher/Sources/Util.java renamed to PercTeacher/Sources/ApplicationJava/Util.java
PercTeacher/Sources/icons/Thumbs.db renamed to PercTeacher/Sources/ApplicationJava/icons/Thumbs.db
No preview for this file type
PercTeacher/Sources/icons/move00.png renamed to PercTeacher/Sources/ApplicationJava/icons/move00.png

1.03 KB

PercTeacher/Sources/icons/move01.png renamed to PercTeacher/Sources/ApplicationJava/icons/move01.png

1.07 KB

PercTeacher/Sources/icons/move02.png renamed to PercTeacher/Sources/ApplicationJava/icons/move02.png

1.03 KB

PercTeacher/Sources/icons/move10.png renamed to PercTeacher/Sources/ApplicationJava/icons/move10.png

605 Bytes

PercTeacher/Sources/icons/move12.png renamed to PercTeacher/Sources/ApplicationJava/icons/move12.png

604 Bytes

PercTeacher/Sources/icons/move20.png renamed to PercTeacher/Sources/ApplicationJava/icons/move20.png

1.03 KB

PercTeacher/Sources/icons/move21.png renamed to PercTeacher/Sources/ApplicationJava/icons/move21.png

1016 Bytes

PercTeacher/Sources/icons/move22.png renamed to PercTeacher/Sources/ApplicationJava/icons/move22.png

1.04 KB

PercTeacher/Sources/icons/robot.png renamed to PercTeacher/Sources/ApplicationJava/icons/robot.png

4.42 KB

PercTeacher/Sources/Robot/makefile 0 → 100644
@@ -0,0 +1,36 @@ @@ -0,0 +1,36 @@
  1 +export CC = avr-gcc
  2 +
  3 +export MCU = atmega2560
  4 +export TARGET_ARCH = -mmcu=$(MCU)
  5 +
  6 +export CFLAGS = -Wall -I. -DF_CPU=16000000 -Os #-g
  7 +export LDFLAGS = -g $(TARGET_ARCH) -lm -Wl,--gc-sections # -Os
  8 +
  9 +TARGET = servoAndStepperControl
  10 +TERM = /dev/ttyACM0
  11 +CPPFLAGS = -mmcu=$(MCU)
  12 +PGMERISP = -c wiring -b 115200 -P $(TERM) -D
  13 +export DUDE = /usr/bin/avrdude -F -v -p $(MCU)
  14 +
  15 +C_SRC = $(wildcard *.c)
  16 +OBJS = $(C_SRC:.c=.o)
  17 +
  18 +all: $(TARGET).hex
  19 +
  20 +clean:
  21 + rm -f *.o *.hex *.elf
  22 +
  23 +%.o:%.c
  24 + $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
  25 +
  26 +$(TARGET).elf: $(OBJS)
  27 + $(CC) $(LDFLAGS) -o $@ $(OBJS)
  28 +
  29 +$(TARGET).hex: $(TARGET).elf
  30 + avr-objcopy -j .text -j .data -O ihex $(TARGET).elf $(TARGET).hex
  31 + avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex $(TARGET).elf eeprom.hex
  32 +
  33 +upload: $(TARGET).hex
  34 + stty -F $(TERM) hupcl # reset
  35 + $(DUDE) $(PGMERISP) -U flash:w:$(TARGET).hex
  36 + make clean
PercTeacher/Sources/Robot/servoAndStepperControl.c 0 → 100644
@@ -0,0 +1,79 @@ @@ -0,0 +1,79 @@
  1 +#include <avr/io.h>
  2 +#include <util/delay.h>
  3 +
  4 +#define SERIAL_BAUDE_RATE 9600
  5 +#define DELAI_STEP 2
  6 +#define PIN_MOTEUR_GAUCHE 0x40 // pin 12
  7 +#define PIN_MOTEUR_DROIT 0x20 // pin 11
  8 +
  9 +#define CPU_FREQ 16000000L
  10 +
  11 +//gestion des moteurs
  12 +void init_pins(void){
  13 + DDRB = PIN_MOTEUR_GAUCHE | PIN_MOTEUR_DROIT;
  14 +}
  15 +
  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);
  27 +}
  28 +
  29 +//gestion de la liaison serie
  30 +void init_serial(int speed){
  31 + UBRR0 = CPU_FREQ / (((unsigned long int) speed) << 4) - 1; //Set baud rate
  32 + UCSR0B = (1 << TXEN0 | 1 << RXEN0); //Enable transmitter & receiver
  33 + UCSR0C = (1 << UCSZ01 | 1 << UCSZ00); //Set 8 bits character and 1 stop bit
  34 + UCSR0A &= ~(1 << U2X0); //Set off UART baud doubler
  35 +}
  36 +
  37 +void send_serial(unsigned char c){
  38 + loop_until_bit_is_set(UCSR0A, UDRE0);
  39 + UDR0 = c;
  40 +}
  41 +
  42 +unsigned char get_serial(void){
  43 + loop_until_bit_is_set(UCSR0A, RXC0);
  44 + return UDR0;
  45 +}
  46 +
  47 +int main(void){
  48 + init_pins();
  49 + init_serial(SERIAL_BAUDE_RATE);
  50 +
  51 + while(1){
  52 + unsigned char deltaL1 = get_serial();
  53 + unsigned char deltaL2 = get_serial();
  54 + unsigned char deltaR1 = get_serial();
  55 + unsigned char deltaR2 = get_serial();
  56 +
  57 +
  58 + send_serial('a');
  59 +
  60 + // conversion 2x8 bits => 16 bits
  61 + int deltaL = (deltaL1 << 8) + deltaL2;
  62 + int deltaR = (deltaR1 << 8) + deltaR2;
  63 +
  64 + int deltaMax = deltaL > deltaR ? deltaL : deltaR;
  65 + for(int i=0; i<deltaMax; i++){
  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);
  72 + }
  73 +
  74 + send_serial('b');
  75 + send_serial(0x01);
  76 + }
  77 + return 0;
  78 +}
  79 +
tests/atmega2560/ledControl/ledControl.c
1 #include <avr/io.h> 1 #include <avr/io.h>
2 #include <util/delay.h> 2 #include <util/delay.h>
  3 +#include <math.h>
  4 +
  5 +#define NB_DRIVERS 3
  6 +#define MAX_VALUE 85 //TODO tbd !
  7 +#define DELAY 100
3 8
4 int main(void){ 9 int main(void){
5 - // SCLK PIN 37  
6 - // SIN PIN 35  
7 - DDRC = 0x03;  
8 - uint8_t LEDs = {10, 20, 30, 40, 50, 60, 70, 80, 90,  
9 - 100, 110, 120, 130, 140, 150, 160, 170, 180, 190  
10 - 200, 210, 220, 230, 240};  
11 - uint8_t ANDs = {0x001, 0x002, 0x004, 0x008, 0x010, 0x020, 0x040, 0x080,  
12 - 0x100, 0x200, 0x400, 0x800}; 10 + // Initialisation
  11 + unsigned int ledValues[NB_DRIVERS * DLED_CHANNELS];
  12 + init_LED_Drivers(NB_DRIVERS);
13 13
  14 + // Animation
  15 + unsigned int animTick = 0;
14 while(1){ 16 while(1){
15 - for(int i=0; i<24; i++){  
16 - uint16_t n = LEDs[i] << 4;  
17 - int clkStatus = 0;  
18 - for(int j=0; j<12; j++){  
19 - if(j == 6)  
20 - clkStatus = 1;  
21 - PORTC = (n & ANDs[j]) << 1 | clkStatus;  
22 - _delay_ms(1);  
23 - } 17 + // Build animation
  18 + for(int i=0; i<NB_DRIVERS * DLED_CHANNELS; i++){
  19 + double sinIn = (double) animTick / 8;
  20 + unsigned int val = (unsigned int) (0.5 + (sin(sinIn) * 0.5));
  21 + ledValues[i] = val * MAX_VALUE;
24 } 22 }
  23 + animTick++;
  24 + if(animTick >= 10000)
  25 + animTick = 0;
  26 +
  27 + set_LED_Drivers(groupes, NB_DRIVERS);
  28 + _delay_ms(100);
25 } 29 }
26 return 0; 30 return 0;
27 } 31 }
tests/atmega2560/ledControl/tlc5947.c 0 → 100644
@@ -0,0 +1,52 @@ @@ -0,0 +1,52 @@
  1 +#include <avr/io.h>
  2 +#include "tlc5947.h"
  3 +
  4 +#define DLED_CHANNELS 24
  5 +
  6 +#define DDR_DLED DDRD
  7 +#define PORT_DLED PORTD
  8 +
  9 +#define PIN_DLED_CLOCK 5
  10 +#define PIN_DLED_DATA 4
  11 +#define PIN_DLED_LATCH 6
  12 +
  13 +void init_LED_Drivers(int nb){
  14 + // LED drivers I/O as outputs
  15 + DDR_DLED |= (1<<PIN_DLED_CLOCK) | (1<<PIN_DLED_DATA) | (1<<PIN_DLED_LATCH);
  16 + // Set LATCH output low
  17 + PORT_DLED &= ~(1<<PIN_DLED_LATCH);
  18 +}
  19 +
  20 +
  21 +void set_LED_Drivers(unsigned int pwm[], int nb){
  22 + // Set LATCH output low
  23 + PORT_DLED &= ~(1<<PIN_DLED_LATCH);
  24 + // 24 channels per TLC5947
  25 + int i;
  26 + for(i=DLED_CHANNELS*nb-1; i>=0; i--){
  27 + // 12 bits per channel, send MSB first
  28 + int v=pwm[i];
  29 + int j;
  30 + for(j=0; j<12; j++){
  31 + // Set CLOCK output low
  32 + PORT_DLED &= ~(1<<PIN_DLED_CLOCK);
  33 +
  34 + // Set DATA as stated by bit #j of i
  35 + if(v & 0x0800)
  36 + PORT_DLED |= (1<<PIN_DLED_DATA);
  37 + else
  38 + PORT_DLED &= ~(1<<PIN_DLED_DATA);
  39 +
  40 + // Set CLOCK output HIGH
  41 + PORT_DLED |= (1<<PIN_DLED_CLOCK);
  42 + v <<= 1;
  43 + }
  44 + }
  45 + // Set CLOCK output low
  46 + PORT_DLED &= ~(1<<PIN_DLED_CLOCK);
  47 +
  48 + // Set LATCH output high
  49 + PORT_DLED |= (1<<PIN_DLED_LATCH);
  50 + // Set LATCH output low
  51 + PORT_DLED &= ~(1<<PIN_DLED_LATCH);
  52 +}
tests/atmega2560/ledControl/tlc5947.h 0 → 100644
@@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
  1 +#ifndef TLC5947
  2 +#define TLC5947
  3 +
  4 +void init_LED_Drivers(int nb);
  5 +void set_LED_Drivers(unsigned int pwm[], int nb);
  6 +
  7 +#endif
tests/atmega2560/ordonanceur/ordonanceur.c
@@ -84,10 +84,49 @@ asm volatile ( \ @@ -84,10 +84,49 @@ asm volatile ( \
84 "pop r0 \n\t" \ 84 "pop r0 \n\t" \
85 ); 85 );
86 86
  87 +/** Configure les ports */
  88 +void init_ports(){
  89 + //TODO DDRXs
  90 +}
  91 +
  92 +/** ----- Liaison serie ----- */
  93 +void init_serial(int speed){
  94 + UBRR0 = CPU_FREQ/(((unsigned long int)speed)<<4)-1; //Set baud rate
  95 + UCSR0B = (1<<TXEN0 | 1<<RXEN0); //Enable transmitter & receiver
  96 + UCSR0C = (1<<UCSZ01 | 1<<UCSZ00); //Set 8 bits character and 1 stop bit
  97 + UCSR0A &= ~(1 << U2X0); //Set off UART baud doubler
  98 +}
  99 +void send_serial(unsigned char c){
  100 + loop_until_bit_is_set(UCSR0A, UDRE0);
  101 + UDR0 = c;
  102 +}
  103 +unsigned char get_serial(void){
  104 + loop_until_bit_is_set(UCSR0A, RXC0);
  105 + return UDR0;
  106 +}
  107 +
  108 +/** ----- Taches ----- */
  109 +void task_print_a(void){
  110 + while(1){
  111 + send_serial('a');
  112 + _delay_ms(1000);
  113 + }
  114 +}
  115 +void task_print_b(void){
  116 + while(1){
  117 + send_serial('b');
  118 + _delay_ms(700);
  119 + }
  120 +}
  121 +
  122 +/** ----- Ordonnancement ----- */
87 struct task{ 123 struct task{
88 uint16_t sp_vise; 124 uint16_t sp_vise;
89 - uint8_t state;  
90 }; 125 };
  126 +uint8_t cpt = 0;
  127 +uint8_t premier_lancement = 0;
  128 +struct task print_a = {0x0300};
  129 +struct task print_b = {0x0500};
91 130
92 /** Démarre le timer pour l'ordonnancement */ 131 /** Démarre le timer pour l'ordonnancement */
93 void init_timer(){ 132 void init_timer(){
@@ -97,32 +136,43 @@ void init_timer(){ @@ -97,32 +136,43 @@ void init_timer(){
97 OCR1A = NB_TICK; 136 OCR1A = NB_TICK;
98 TIMSK1 |= _BV(OCIE1A); 137 TIMSK1 |= _BV(OCIE1A);
99 } 138 }
100 -  
101 -/** Configure les ports */  
102 -void init_ports(){  
103 - //TODO DDRXs  
104 -}  
105 -  
106 -/** Alumme la LED 13 pour témoigné du bon fonctionnement de la carte */  
107 -void temoin_allumage(){  
108 - DDRA = 0x01;  
109 - PORTA = 0x01;  
110 - _delay_ms(500);  
111 - PORTA = 0x00;  
112 -}  
113 -  
114 -/** Reception de l'interruption généré par le timer (changement de contexte) */ 139 +/** Changement de contexte */
115 ISR(TIMER1_COMPA_vect){ 140 ISR(TIMER1_COMPA_vect){
116 - // TODO 141 + if(premier_lancement == 0){
  142 + premier_lancement++;
  143 + sei();
  144 + SP = print_a.sp_vise;
  145 + task_print_a();
  146 + }else if(premier_lancement == 1){
  147 + SAVE_CONTEXT();
  148 + print_a.sp_vise = SP;
  149 + premier_lancement++;
  150 + sei();
  151 + SP = print_b.sp_vise;
  152 + task_print_b();
  153 + }else{
  154 + if(cpt==0){
  155 + SAVE_CONTEXT();
  156 + print_b.sp_vise = SP;
  157 + SP = print_a.sp_vise;
  158 + RESTORE_CONTEXT();
  159 + cpt++;
  160 + }else if(cpt==1){
  161 + SAVE_CONTEXT();
  162 + print_a.sp_vise = SP;
  163 + SP = print_b.sp_vise;
  164 + RESTORE_CONTEXT();
  165 + cpt = 0;
  166 + }
  167 + }
117 sei(); 168 sei();
118 } 169 }
119 170
120 int main(void){ 171 int main(void){
121 - temoin_allumage();  
122 -  
123 // Initialisation 172 // Initialisation
124 init_timer(); 173 init_timer();
125 - init_port(); 174 + init_ports();
  175 + init_serial(9600);
126 sei(); 176 sei();
127 177
128 while(1){} 178 while(1){}
tests/atmega2560/servoAndStepperControl/servoAndStepperControl.c
@@ -3,13 +3,27 @@ @@ -3,13 +3,27 @@
3 3
4 int main(void){ 4 int main(void){
5 // pin 13 5 // pin 13
6 - DDRB = 0x80; 6 + DDRB = 0xC0;
7 7
  8 + PORTB |= 0x40; // forward
  9 + int i = 0;
  10 + int sens = 0;
8 while(1){ 11 while(1){
9 - PORTB = 0x80;  
10 - _delay_us(1000);  
11 - PORTB = 0x00;  
12 - _delay_us(1000); 12 + // step
  13 + PORTB |= 0x80;
  14 + _delay_ms(5);
  15 + PORTB &= 0x7F;
  16 + _delay_ms(5);
  17 + // dir
  18 + i++;
  19 + if(i > 200){
  20 + i = 0;
  21 + sens = 1 - sens;
  22 + if(sens == 0)
  23 + PORTB |= 0x40; // forward
  24 + else
  25 + PORTB &= 0xBF; // backward
  26 + }
13 } 27 }
14 return 0; 28 return 0;
15 } 29 }