From b7e05e41463cedbee2b31fad9e5b3a00dfb4708b Mon Sep 17 00:00:00 2001 From: Meli Date: Fri, 13 Feb 2015 22:40:56 +0100 Subject: [PATCH 1/7] Adding communication with other device and detect its address for communication --- ball_detect/main.c | 57 +++++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/ball_detect/main.c b/ball_detect/main.c index b18e382..3ba5739 100644 --- a/ball_detect/main.c +++ b/ball_detect/main.c @@ -10,6 +10,12 @@ #define BALL_SENSOR_1 0 #define BALL_SENSOR_2 1 #define BALL_SENSOR_3 2 +#define DIP_SWITCH_1 0 +#define DIP_SWITCH_2 1 +#define DIP_SWITCH_3 2 +#define DIP_SWITCH_4 3 +#define DIP_SWITCH_5 4 +#define DIP_SWITCH_6 5 #define F_OSC F_CPU #define ULTRASONIC_SENSOR 4 #define waitForTX() while (!(UCSR0A & 1< vision_result[j]) { - small = vision_result[j]; - index = j; - } - } - sendc('0' + index); - sendc('\r'); - sendc('\n'); - _delay_ms(200); } return 0; } From 99f8052914432b32b9f1124c058f4b7bbca240c1 Mon Sep 17 00:00:00 2001 From: Meli Date: Fri, 13 Feb 2015 22:52:53 +0100 Subject: [PATCH 2/7] repair of structure of last commit --- ball_detect/main.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/ball_detect/main.c b/ball_detect/main.c index 3ba5739..663688f 100644 --- a/ball_detect/main.c +++ b/ball_detect/main.c @@ -38,10 +38,8 @@ void setup(void) { DDRD |= 1 << 3; //DIP-SWITCH INITIALIZATION - DDRC = 0; - PORTC |= \ - ((1 << DIP_SWITCH_1) | (1 << DIP_SWITCH_2) | (1 << DIP_SWITCH_3) | \ - (1 << DIP_SWITCH_4) | (1 << DIP_SWITCH_5) | (1 << DIP_SWITCH_6)); + DDRC = 0; + PORTC |= ((1 << DIP_SWITCH_1) | (1 << DIP_SWITCH_2) | (1 << DIP_SWITCH_3) | (1 << DIP_SWITCH_4) | (1 << DIP_SWITCH_5) | (1 << DIP_SWITCH_6)); //INTERRUPTS INIT DDRB = 0; @@ -79,10 +77,10 @@ ISR(USART_RX_vect) { uint32_t modulo, position; uint8_t read_char = UDR0, i, j; if(read_char == my_address) { - for(j = 2; j <= 0; j--) { + for(j = 2; j >= 0; j--) { modulo = vision_result[j]; position = 1000000; - for(i = 0;i < 7;i++) { + for(i = 0; i < 7; i++) { sendc('0' + ((modulo / position) % 10)); modulo %= position; position /= 10; From 75005da379ff98d12784aa9be09a7e7a4e5dde52 Mon Sep 17 00:00:00 2001 From: Meli Date: Sun, 15 Feb 2015 21:30:41 +0100 Subject: [PATCH 3/7] repair of lines with more than 80 characters Signed-off-by: Meli --- ball_detect/main.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ball_detect/main.c b/ball_detect/main.c index 663688f..c9e6a9f 100644 --- a/ball_detect/main.c +++ b/ball_detect/main.c @@ -39,11 +39,19 @@ void setup(void) { //DIP-SWITCH INITIALIZATION DDRC = 0; - PORTC |= ((1 << DIP_SWITCH_1) | (1 << DIP_SWITCH_2) | (1 << DIP_SWITCH_3) | (1 << DIP_SWITCH_4) | (1 << DIP_SWITCH_5) | (1 << DIP_SWITCH_6)); + PORTC |= ((1 << DIP_SWITCH_1) + | (1 << DIP_SWITCH_2) + | (1 << DIP_SWITCH_3) + | (1 << DIP_SWITCH_4) + | (1 << DIP_SWITCH_5) + | (1 << DIP_SWITCH_6)); //INTERRUPTS INIT DDRB = 0; - PORTB |= ((1 << BALL_SENSOR_1) | (1 << BALL_SENSOR_2) | (1 << BALL_SENSOR_3) | (1 << ULTRASONIC_SENSOR)); + PORTB |= ((1 << BALL_SENSOR_1) + | (1 << BALL_SENSOR_2) + | (1 << BALL_SENSOR_3) + | (1 << ULTRASONIC_SENSOR)); PCICR |= 1; PCMSK0 |= 0xF; From 722f13fe7bb0674a2af8272a7a75cb33a513894e Mon Sep 17 00:00:00 2001 From: Meli Date: Sun, 15 Feb 2015 21:39:35 +0100 Subject: [PATCH 4/7] repair of lines with more than 80 characters (tabs) Signed-off-by: Meli --- ball_detect/main.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ball_detect/main.c b/ball_detect/main.c index c9e6a9f..db1a58e 100644 --- a/ball_detect/main.c +++ b/ball_detect/main.c @@ -40,18 +40,18 @@ void setup(void) { //DIP-SWITCH INITIALIZATION DDRC = 0; PORTC |= ((1 << DIP_SWITCH_1) - | (1 << DIP_SWITCH_2) - | (1 << DIP_SWITCH_3) - | (1 << DIP_SWITCH_4) - | (1 << DIP_SWITCH_5) - | (1 << DIP_SWITCH_6)); + | (1 << DIP_SWITCH_2) + | (1 << DIP_SWITCH_3) + | (1 << DIP_SWITCH_4) + | (1 << DIP_SWITCH_5) + | (1 << DIP_SWITCH_6)); //INTERRUPTS INIT DDRB = 0; PORTB |= ((1 << BALL_SENSOR_1) - | (1 << BALL_SENSOR_2) - | (1 << BALL_SENSOR_3) - | (1 << ULTRASONIC_SENSOR)); + | (1 << BALL_SENSOR_2) + | (1 << BALL_SENSOR_3) + | (1 << ULTRASONIC_SENSOR)); PCICR |= 1; PCMSK0 |= 0xF; From b9875953fb196a87056651f8569a0c6356759efe Mon Sep 17 00:00:00 2001 From: Meli Date: Sun, 15 Feb 2015 21:42:34 +0100 Subject: [PATCH 5/7] applying one of deep dark secrets of C on declaration of global array Signed-off-by: Meli --- ball_detect/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ball_detect/main.c b/ball_detect/main.c index db1a58e..9a7050b 100644 --- a/ball_detect/main.c +++ b/ball_detect/main.c @@ -23,7 +23,7 @@ volatile int32_t ends_of_pulses[4]; volatile int32_t lenghts_of_pulses[4]; volatile int32_t starts_of_pulses[4]; -volatile int32_t vision_result[3] = {0,0,0}; +volatile int32_t vision_result[3]; volatile uint8_t pinstate, ct, changed_bits, portb_history = 0xFF, my_address; void setup(void) { From 7fa396ff4cee91a89ddbeb0439a0425b2c7e0c5f Mon Sep 17 00:00:00 2001 From: Meli Date: Sun, 15 Feb 2015 21:47:20 +0100 Subject: [PATCH 6/7] removing annoying irritating bad spaces Signed-off-by: Meli --- ball_detect/main.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ball_detect/main.c b/ball_detect/main.c index 9a7050b..90722d2 100644 --- a/ball_detect/main.c +++ b/ball_detect/main.c @@ -40,18 +40,18 @@ void setup(void) { //DIP-SWITCH INITIALIZATION DDRC = 0; PORTC |= ((1 << DIP_SWITCH_1) - | (1 << DIP_SWITCH_2) - | (1 << DIP_SWITCH_3) - | (1 << DIP_SWITCH_4) - | (1 << DIP_SWITCH_5) - | (1 << DIP_SWITCH_6)); + | (1 << DIP_SWITCH_2) + | (1 << DIP_SWITCH_3) + | (1 << DIP_SWITCH_4) + | (1 << DIP_SWITCH_5) + | (1 << DIP_SWITCH_6)); //INTERRUPTS INIT DDRB = 0; PORTB |= ((1 << BALL_SENSOR_1) - | (1 << BALL_SENSOR_2) - | (1 << BALL_SENSOR_3) - | (1 << ULTRASONIC_SENSOR)); + | (1 << BALL_SENSOR_2) + | (1 << BALL_SENSOR_3) + | (1 << ULTRASONIC_SENSOR)); PCICR |= 1; PCMSK0 |= 0xF; From df127035a99c0baaf365e2746bda4f5ea7f96719 Mon Sep 17 00:00:00 2001 From: Meli Date: Tue, 17 Feb 2015 22:45:13 +0100 Subject: [PATCH 7/7] Adding debug comunication mode Signed-off-by: Martin Melichercik --- ball_detect/main.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/ball_detect/main.c b/ball_detect/main.c index 90722d2..f64297d 100644 --- a/ball_detect/main.c +++ b/ball_detect/main.c @@ -85,16 +85,30 @@ ISR(USART_RX_vect) { uint32_t modulo, position; uint8_t read_char = UDR0, i, j; if(read_char == my_address) { - for(j = 2; j >= 0; j--) { + for(j = 0; j < 3; j++) { modulo = vision_result[j]; position = 1000000; + for(i = 0; i < 7; i++) { + sendc((modulo / position) % 10); + modulo %= position; + position /= 10; + } + } + } else if((read_char - 48) == my_address) { + for(j = 0; j < 3; j++) { + modulo = vision_result[j]; + position = 1000000; + sendc('0' + j); + sendc(' '); for(i = 0; i < 7; i++) { sendc('0' + ((modulo / position) % 10)); modulo %= position; position /= 10; } + sendc('\r'); + sendc('\n'); } - } + } } ISR(PCINT0_vect) {