Commit 7d3291092c4c5e84913547dea2a7796823040828
1 parent
a89c030d
PercTeacher programme robot
Showing
26 changed files
with
110 additions
and
0 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
... | ... | @@ -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 | ... | ... |
... | ... | @@ -0,0 +1,74 @@ |
1 | +#include <avr/io.h> | |
2 | +#include <util/delay.h> | |
3 | + | |
4 | +#define SERIAL_BAUDE_RATE 9600 | |
5 | +#define DELAI_STEP 1000 | |
6 | +#define PIN_MOTEUR_GAUCHE 0x40 // pin 12 | |
7 | +#define PIN_MOTEUR_DROIT 0x20 // pin 11 | |
8 | + | |
9 | +//gestion des moteurs | |
10 | +void init_pins(void){ | |
11 | + // pin 12 et 11 | |
12 | + DDRB = PIN_MOTEUR_GAUCHE | PIN_MOTEUR_DROIT; | |
13 | +} | |
14 | + | |
15 | +void pas_moteur_gauche(void){ | |
16 | + // pin 12 | |
17 | + PORTB |= PIN_MOTEUR_GAUCHE; | |
18 | + _delay_us(DELAI_STEP); | |
19 | + PORTB &= ~PIN_MOTEUR_GAUCHE; | |
20 | + _delay_us(DELAI_STEP); | |
21 | +} | |
22 | + | |
23 | +void pas_moteur_droit(void){ | |
24 | + // pin 11 | |
25 | + PORTB |= PIN_MOTEUR_DROIT; | |
26 | + _delay_us(DELAI_STEP); | |
27 | + PORTB &= ~PIN_MOTEUR_DROIT; | |
28 | + _delay_us(DELAI_STEP); | |
29 | +} | |
30 | + | |
31 | +//gestion de la liaison serie | |
32 | +void init_serial(int speed){ | |
33 | + UBRR0 = CPU_FREQ / (((unsigned long int) speed) << 4) - 1; //Set baud rate | |
34 | + UCSR0B = (1 << TXEN0 | 1 << RXEN0); //Enable transmitter & receiver | |
35 | + UCSR0C = (1 << UCSZ01 | 1 << UCSZ00); //Set 8 bits character and 1 stop bit | |
36 | + UCSR0A &= ~(1 << U2X0); //Set off UART baud doubler | |
37 | +} | |
38 | + | |
39 | +void send_serial(unsigned char c){ | |
40 | + loop_until_bit_is_set(UCSR0A, UDRE0); | |
41 | + UDR0 = c; | |
42 | +} | |
43 | + | |
44 | +unsigned char get_serial(void){ | |
45 | + loop_until_bit_is_set(UCSR0A, RXC0); | |
46 | + return UDR0; | |
47 | +} | |
48 | + | |
49 | +int main(void){ | |
50 | + init_pins(); | |
51 | + init_serial(SERIAL_BAUDE_RATE); | |
52 | + | |
53 | + while(1){ | |
54 | + unsigned char deltaL1 = get_serial(); | |
55 | + unsigned char deltaL2 = get_serial(); | |
56 | + unsigned char deltaR1 = get_serial(); | |
57 | + unsigned char deltaR2 = get_serial(); | |
58 | + | |
59 | + // conversion 2x8 bits => 16 bits | |
60 | + int deltaL = deltaL1 << 8 + deltaL2; | |
61 | + int deltaR = deltaR1 << 8 + deltaR2; | |
62 | + | |
63 | + int deltaMax = deltaL > deltaR ? deltaL : deltaR; | |
64 | + for(int i=0; i<deltaMax; i++){ | |
65 | + if(deltaL > i) | |
66 | + pas_moteur_gauche(); | |
67 | + if(deltaR > i) | |
68 | + pas_moteur_droit(); | |
69 | + } | |
70 | + | |
71 | + } | |
72 | + return 0; | |
73 | +} | |
74 | + | ... | ... |