From adf0c7c0e369df34dd28c9a8c0e95893ebf0dc9b Mon Sep 17 00:00:00 2001 From: CasoMateo <67202211+CasoMateo@users.noreply.github.com> Date: Sat, 27 Feb 2021 20:48:00 +0100 Subject: [PATCH 1/6] Classes and Computation We compute the data we acquired from Arduino to decide on what path the robot should take. --- Classes and Computation | 68 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Classes and Computation diff --git a/Classes and Computation b/Classes and Computation new file mode 100644 index 0000000..3190065 --- /dev/null +++ b/Classes and Computation @@ -0,0 +1,68 @@ +from abc import ABC, abstractmethod +import serial + +ser = serial.Serial('COM', 9600) + + +class Motor: + + def __init__(GND, VCC): + self.GND = GND + self.VCC = VCC + + @abstractmethod + def send_parameter(parameter): + pass + + +class MotorDC(Motor): + + def send_parameter(character): + + ser.write(character.encode()) + print(f"sent: {character}") + +class Servomotor(Motor): + + def __init__(GND, VCC, PWM_pin): + super().__init__(GND, VCC) + PWM_pin = PWM_pin + + def send_parameter(character): + + ser.write(character.encode()) + print(f"sent: {character}") + +class Sensor: + + def __init__(voltage_capacity, GND, VCC, trigger_pin, echo_pin, max_distance): + self.voltage_capacity = voltage_capacity + self.GND = GND + self.VCC = VCC + self.trigger_pin = trigger_pin + self.echo_pin = echo_pin + self.max_distance = max_distance + + + def send_instructions(): + + right, left = ser.read() + + dir_ = {'right' = right, 'left' = left} + + for direction, distance in dir_.items(): + max_ = right + direction_ = 'right' + + if distance > max_: + max_ = distance + direction_ = direction + + if direction_ == 'right': + ser.write('y'.encode()) + + else: + ser.write('x'.encode()) + + return + From 0912f94673282aa72aa85b59246226f3dcd4401c Mon Sep 17 00:00:00 2001 From: CasoMateo <67202211+CasoMateo@users.noreply.github.com> Date: Sat, 27 Feb 2021 20:49:46 +0100 Subject: [PATCH 2/6] Delete Classes and Computation --- Classes and Computation | 68 ----------------------------------------- 1 file changed, 68 deletions(-) delete mode 100644 Classes and Computation diff --git a/Classes and Computation b/Classes and Computation deleted file mode 100644 index 3190065..0000000 --- a/Classes and Computation +++ /dev/null @@ -1,68 +0,0 @@ -from abc import ABC, abstractmethod -import serial - -ser = serial.Serial('COM', 9600) - - -class Motor: - - def __init__(GND, VCC): - self.GND = GND - self.VCC = VCC - - @abstractmethod - def send_parameter(parameter): - pass - - -class MotorDC(Motor): - - def send_parameter(character): - - ser.write(character.encode()) - print(f"sent: {character}") - -class Servomotor(Motor): - - def __init__(GND, VCC, PWM_pin): - super().__init__(GND, VCC) - PWM_pin = PWM_pin - - def send_parameter(character): - - ser.write(character.encode()) - print(f"sent: {character}") - -class Sensor: - - def __init__(voltage_capacity, GND, VCC, trigger_pin, echo_pin, max_distance): - self.voltage_capacity = voltage_capacity - self.GND = GND - self.VCC = VCC - self.trigger_pin = trigger_pin - self.echo_pin = echo_pin - self.max_distance = max_distance - - - def send_instructions(): - - right, left = ser.read() - - dir_ = {'right' = right, 'left' = left} - - for direction, distance in dir_.items(): - max_ = right - direction_ = 'right' - - if distance > max_: - max_ = distance - direction_ = direction - - if direction_ == 'right': - ser.write('y'.encode()) - - else: - ser.write('x'.encode()) - - return - From caa5b2c7a874314713ffebdc3802495dfac05730 Mon Sep 17 00:00:00 2001 From: CasoMateo <67202211+CasoMateo@users.noreply.github.com> Date: Sat, 27 Feb 2021 20:51:16 +0100 Subject: [PATCH 3/6] Data acquisition Here, we obtain information from the robot to later send it to Python in order to figure out what the best "next move is". --- Data adquisition | 109 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 Data adquisition diff --git a/Data adquisition b/Data adquisition new file mode 100644 index 0000000..7c8dd7f --- /dev/null +++ b/Data adquisition @@ -0,0 +1,109 @@ +#include + +int in1 = 10; +int in2 = 9; +int in3 = 6; +int in4 = 5; +int EnA = 11; +int velocity = 30; +int EchoPin = 2; +int TriggerPin = 7; + +Servo servomotor = 3; + +void setup() { + + Serial.begin(9600); + + pinMode(in1, OUTPUT); + pinMode(in2, OUTPUT); + pinMode(in3, OUTPUT); + pinMode(in4, OUTPUT); + pinMode(EnA, OUTPUT); + pinMode(TriggerPin, OUTPUT); + pinMode(EchoPin, OUTPUT); + +} + + +void loop() { + + if int ping(int TriggerPin, int EchoPin, 90) >= 30 { + analogWrite(EnA, velocity); + digitalWrite(in1, HIGH); + digitalWrite(in2, LOW); + digitalWrite(in3, HIGH); + digitalWrite(in4, LOW); + + } + + frenar_motores(); + + Serial.write(ping(int TriggerPin, int EchoPin, 0);, (ping(int TriggerPin, int EchoPin, 180);); + + + if(Serial.available > 0) { + message = Serial.read(); + + if message == 'x' { + + analogWrite(EnA, velocity); + digitalWrite(in3, HIGH); + digitalWrite(in4, LOW); + + } + + if message == 'y' { + + analogWrite(EnA, velocity); + digitalWrite(in1, HIGH); + digitalWrite(in2, LOW); + + } + + } + + int subir_velocidad() { + + if velocity <= 240 { + + int velocity += 10; + } + } + + int bajar_velocidad() { + + if velocity >= 30 { + + int velocity -= 10 + } + } + + int frenar_motores() { + + digitalWrite(in1, LOW); + digitalWrite(in2, LOW); + digitalWrite(in3, LOW); + digitalWrite(in4, LOW); + + } + + + int ping(int TriggerPin, int EchoPin, int position_) { + servomotor.write(position_); + + long duration, distanceCm; + + digitalWrite(TriggerPin, LOW); + delayMicroseconds(4); + digitalWrite(TriggerPin, HIGH); + delayMicroseconds(10); + digitalWrite(TriggerPin, LOW); + + duration = pulseIn(EchoPin, HIGH); + + distanceCm = duration * 10 / 292/ 2; + return distanceCm; + +} + From 4bf91c16356c118cba5953a0653da9bc654b853a Mon Sep 17 00:00:00 2001 From: CasoMateo <67202211+CasoMateo@users.noreply.github.com> Date: Sat, 6 Mar 2021 02:25:05 +0100 Subject: [PATCH 4/6] Update Data adquisition --- Data adquisition | 78 ++++++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/Data adquisition b/Data adquisition index 7c8dd7f..daf305a 100644 --- a/Data adquisition +++ b/Data adquisition @@ -9,7 +9,7 @@ int velocity = 30; int EchoPin = 2; int TriggerPin = 7; -Servo servomotor = 3; +Servo servomotor; void setup() { @@ -22,13 +22,41 @@ void setup() { pinMode(EnA, OUTPUT); pinMode(TriggerPin, OUTPUT); pinMode(EchoPin, OUTPUT); + servomotor.attach(3); } + +int ping(int TriggerPin, int EchoPin, int position_) { + servomotor.write(position_); + + long duration, distanceCm; + + digitalWrite(TriggerPin, LOW); + delayMicroseconds(4); + digitalWrite(TriggerPin, HIGH); + delayMicroseconds(10); + digitalWrite(TriggerPin, LOW); + + duration = pulseIn(EchoPin, HIGH); + + distanceCm = duration * 10 / 292/ 2; + return distanceCm; + +} + +int frenar_motores() { + + digitalWrite(in1, LOW); + digitalWrite(in2, LOW); + digitalWrite(in3, LOW); + digitalWrite(in4, LOW); + +} void loop() { - if int ping(int TriggerPin, int EchoPin, 90) >= 30 { + if (ping(TriggerPin, EchoPin, 90) >= 30) { analogWrite(EnA, velocity); digitalWrite(in1, HIGH); digitalWrite(in2, LOW); @@ -39,13 +67,15 @@ void loop() { frenar_motores(); - Serial.write(ping(int TriggerPin, int EchoPin, 0);, (ping(int TriggerPin, int EchoPin, 180);); + Serial.write('x' + ping(TriggerPin, EchoPin, 0)); + Serial.write('y' + ping(TriggerPin, EchoPin, 180)); - if(Serial.available > 0) { + if(Serial.available() > 0) { + int message; message = Serial.read(); - if message == 'x' { + if (message == 'a') { analogWrite(EnA, velocity); digitalWrite(in3, HIGH); @@ -53,57 +83,33 @@ void loop() { } - if message == 'y' { + if (message == 'b') { analogWrite(EnA, velocity); digitalWrite(in1, HIGH); digitalWrite(in2, LOW); - } + } } + } int subir_velocidad() { - if velocity <= 240 { + if (velocity <= 240) { - int velocity += 10; + int velocity = velocity + 10; } } int bajar_velocidad() { - if velocity >= 30 { + if (velocity >= 30) { - int velocity -= 10 + int velocity = velocity - 10; } } - int frenar_motores() { - - digitalWrite(in1, LOW); - digitalWrite(in2, LOW); - digitalWrite(in3, LOW); - digitalWrite(in4, LOW); - } - - int ping(int TriggerPin, int EchoPin, int position_) { - servomotor.write(position_); - - long duration, distanceCm; - - digitalWrite(TriggerPin, LOW); - delayMicroseconds(4); - digitalWrite(TriggerPin, HIGH); - delayMicroseconds(10); - digitalWrite(TriggerPin, LOW); - - duration = pulseIn(EchoPin, HIGH); - - distanceCm = duration * 10 / 292/ 2; - return distanceCm; - -} From e1bd346bed6bbad93aa3ede5421ec3a1d0c261b5 Mon Sep 17 00:00:00 2001 From: CasoMateo <67202211+CasoMateo@users.noreply.github.com> Date: Sat, 6 Mar 2021 02:37:34 +0100 Subject: [PATCH 5/6] Update Data adquisition --- Data adquisition | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Data adquisition b/Data adquisition index daf305a..82e735f 100644 --- a/Data adquisition +++ b/Data adquisition @@ -5,6 +5,7 @@ int in2 = 9; int in3 = 6; int in4 = 5; int EnA = 11; +int EnB = 12; int velocity = 30; int EchoPin = 2; int TriggerPin = 7; @@ -58,6 +59,7 @@ void loop() { if (ping(TriggerPin, EchoPin, 90) >= 30) { analogWrite(EnA, velocity); + analogWrite(EnB, velocity); digitalWrite(in1, HIGH); digitalWrite(in2, LOW); digitalWrite(in3, HIGH); @@ -77,7 +79,7 @@ void loop() { if (message == 'a') { - analogWrite(EnA, velocity); + analogWrite(EnB, velocity); digitalWrite(in3, HIGH); digitalWrite(in4, LOW); @@ -110,6 +112,7 @@ void loop() { } } + From 9942b8aec2cf9b9f28603aa25cf242c4d03f0739 Mon Sep 17 00:00:00 2001 From: CasoMateo <67202211+CasoMateo@users.noreply.github.com> Date: Mon, 3 May 2021 23:01:38 +0200 Subject: [PATCH 6/6] Update and rename Data adquisition to dataAquisition.cpp --- Data adquisition | 118 --------------------------------------------- dataAquisition.cpp | 98 +++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 118 deletions(-) delete mode 100644 Data adquisition create mode 100644 dataAquisition.cpp diff --git a/Data adquisition b/Data adquisition deleted file mode 100644 index 82e735f..0000000 --- a/Data adquisition +++ /dev/null @@ -1,118 +0,0 @@ -#include - -int in1 = 10; -int in2 = 9; -int in3 = 6; -int in4 = 5; -int EnA = 11; -int EnB = 12; -int velocity = 30; -int EchoPin = 2; -int TriggerPin = 7; - -Servo servomotor; - -void setup() { - - Serial.begin(9600); - - pinMode(in1, OUTPUT); - pinMode(in2, OUTPUT); - pinMode(in3, OUTPUT); - pinMode(in4, OUTPUT); - pinMode(EnA, OUTPUT); - pinMode(TriggerPin, OUTPUT); - pinMode(EchoPin, OUTPUT); - servomotor.attach(3); - -} - -int ping(int TriggerPin, int EchoPin, int position_) { - servomotor.write(position_); - - long duration, distanceCm; - - digitalWrite(TriggerPin, LOW); - delayMicroseconds(4); - digitalWrite(TriggerPin, HIGH); - delayMicroseconds(10); - digitalWrite(TriggerPin, LOW); - - duration = pulseIn(EchoPin, HIGH); - - distanceCm = duration * 10 / 292/ 2; - return distanceCm; - -} - -int frenar_motores() { - - digitalWrite(in1, LOW); - digitalWrite(in2, LOW); - digitalWrite(in3, LOW); - digitalWrite(in4, LOW); - -} - - -void loop() { - - if (ping(TriggerPin, EchoPin, 90) >= 30) { - analogWrite(EnA, velocity); - analogWrite(EnB, velocity); - digitalWrite(in1, HIGH); - digitalWrite(in2, LOW); - digitalWrite(in3, HIGH); - digitalWrite(in4, LOW); - - } - - frenar_motores(); - - Serial.write('x' + ping(TriggerPin, EchoPin, 0)); - Serial.write('y' + ping(TriggerPin, EchoPin, 180)); - - - if(Serial.available() > 0) { - int message; - message = Serial.read(); - - if (message == 'a') { - - analogWrite(EnB, velocity); - digitalWrite(in3, HIGH); - digitalWrite(in4, LOW); - - } - - if (message == 'b') { - - analogWrite(EnA, velocity); - digitalWrite(in1, HIGH); - digitalWrite(in2, LOW); - - } - - } - } - - int subir_velocidad() { - - if (velocity <= 240) { - - int velocity = velocity + 10; - } - } - - int bajar_velocidad() { - - if (velocity >= 30) { - - int velocity = velocity - 10; - } - } - - - - - diff --git a/dataAquisition.cpp b/dataAquisition.cpp new file mode 100644 index 0000000..dbcafa7 --- /dev/null +++ b/dataAquisition.cpp @@ -0,0 +1,98 @@ +#include + +int in1 = 10; +int in2 = 9; +int in3 = 6; +int in4 = 5; +const int EchoPin = 11; +const int TriggerPin = 4; +long duration; +int distance; + +Servo servomotor; + +void setup() { + + Serial.begin(9600); + + pinMode(in1, OUTPUT); + pinMode(in2, OUTPUT); + pinMode(in3, OUTPUT); + pinMode(in4, OUTPUT); + pinMode(TriggerPin, OUTPUT); + pinMode(EchoPin, INPUT); + servomotor.attach(3); + + +} +int ping(int TriggerPin, int EchoPin, int position_) { + + servomotor.write(position_); + + digitalWrite(TriggerPin, LOW); + delayMicroseconds(2); + digitalWrite(TriggerPin, HIGH); + delayMicroseconds(10); + digitalWrite(TriggerPin, LOW); + + duration = pulseIn(EchoPin, HIGH); + + distance = duration * 0.034 / 2; + + return distance; +} + +int stop_() { + + digitalWrite(in1, LOW); + digitalWrite(in2, LOW); + digitalWrite(in3, LOW); + digitalWrite(in4, LOW); + +} + +void loop() { + int cm; + cm = ping(TriggerPin, EchoPin, 90); + + if (cm >= 50) { + digitalWrite(in1, HIGH); + digitalWrite(in2, LOW); + digitalWrite(in3, HIGH); + digitalWrite(in4, LOW); + + } + + else { + stop_(); + + Serial.write('x' + ping(TriggerPin, EchoPin, 0)); + Serial.write('y' + ping(TriggerPin, EchoPin, 180)); + + + if(Serial.available() > 0) { + int message; + message = Serial.read(); + + if (message == 'a') { + + digitalWrite(in3, HIGH); + digitalWrite(in4, LOW); + + } + + if (message == 'b') { + + digitalWrite(in1, HIGH); + digitalWrite(in2, LOW); + + } + } + } +} + + + + + +