From 01e0e7b7b34e136045bd83af05f5eb28e9d4d146 Mon Sep 17 00:00:00 2001 From: pfrison Date: Fri, 12 Apr 2019 10:34:04 +0200 Subject: [PATCH] modification PercTeacher java et test moteurs sur le robot (pcb) --- PercTeacher/Sources/ApplicationJava/SerialCommands.java | 10 ++++++++++ tests/atmega2560/servoAndStepperControl/servoAndStepperControl.c | 18 +++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/PercTeacher/Sources/ApplicationJava/SerialCommands.java b/PercTeacher/Sources/ApplicationJava/SerialCommands.java index 882a8ed..96e850e 100644 --- a/PercTeacher/Sources/ApplicationJava/SerialCommands.java +++ b/PercTeacher/Sources/ApplicationJava/SerialCommands.java @@ -2,9 +2,19 @@ public class SerialCommands { public static void sendDeltas(SerialCom serialCom, int deltaLeft, int deltaRight) { byte dataL1 = (byte) ((deltaLeft & 0xFF00) >> 8); + if(deltaLeft < 0) + dataL1 &= 0x7F; + else + dataL1 |= 0x80; byte dataL2 = (byte) (deltaLeft & 0xFF); + byte dataR1 = (byte) ((deltaRight & 0xFF00) >> 8); + if(deltaRight < 0) + dataR1 &= 0x7F; + else + dataR1 |= 0x80; byte dataR2 = (byte) (deltaRight & 0xFF); + byte[] data = new byte[] {dataL1, dataL2, dataR1, dataR2}; serialCom.send(data); diff --git a/tests/atmega2560/servoAndStepperControl/servoAndStepperControl.c b/tests/atmega2560/servoAndStepperControl/servoAndStepperControl.c index 6a4bf4b..2f764f1 100644 --- a/tests/atmega2560/servoAndStepperControl/servoAndStepperControl.c +++ b/tests/atmega2560/servoAndStepperControl/servoAndStepperControl.c @@ -3,26 +3,26 @@ int main(void){ // pin 13 - DDRB = 0xC0; + DDRB = 0x60; - PORTB |= 0x40; // forward + PORTB |= 0x20; // forward int i = 0; int sens = 0; while(1){ // step - PORTB |= 0x80; - _delay_ms(5); - PORTB &= 0x7F; - _delay_ms(5); + PORTB |= 0x40; + _delay_ms(2); + PORTB &= 0xBF; + _delay_ms(2); // dir i++; - if(i > 200){ + if(i > 1000){ i = 0; sens = 1 - sens; if(sens == 0) - PORTB |= 0x40; // forward + PORTB |= 0x20; // forward else - PORTB &= 0xBF; // backward + PORTB &= 0xDF; // backward } } return 0; -- libgit2 0.21.2