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/4] 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 473c0812e33a678ed8bb572d6c3138ccf254b9ac Mon Sep 17 00:00:00 2001 From: CasoMateo <67202211+CasoMateo@users.noreply.github.com> Date: Sat, 6 Mar 2021 02:27:59 +0100 Subject: [PATCH 2/4] Update Classes and Computation --- Classes and Computation | 42 ++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/Classes and Computation b/Classes and Computation index 3190065..af80138 100644 --- a/Classes and Computation +++ b/Classes and Computation @@ -1,7 +1,7 @@ from abc import ABC, abstractmethod import serial -ser = serial.Serial('COM', 9600) +ser = serial.Serial('COM3', 9600) class Motor: @@ -17,6 +17,9 @@ class Motor: class MotorDC(Motor): + def __init__(GND, VCC): + super().__init(GND, VCC) + def send_parameter(character): ser.write(character.encode()) @@ -46,23 +49,32 @@ class Sensor: def send_instructions(): - right, left = ser.read() + response = ser.read() - dir_ = {'right' = right, 'left' = left} + if response[0] == 'x': + distance_1 = '' - for direction, distance in dir_.items(): - max_ = right - direction_ = 'right' + for char in range(1, len(response)): + distance_1 += str(char) + + f_distance_1 = int(distance_1) - if distance > max_: - max_ = distance - direction_ = direction + else: + distance_2 = '' - if direction_ == 'right': - ser.write('y'.encode()) + for char in range(1, len(response)): + distance_1 += str(char) - else: - ser.write('x'.encode()) + f_distance_2 = int(distance_2) - return - + if f_distance_1 > f_distance_2: + ser.write('a'.encode()) + + else: + ser.write('b'.encode()) + + + + + + From 202ab80217adc5e8d029601a6a3bd4047deb6e1d Mon Sep 17 00:00:00 2001 From: CasoMateo <67202211+CasoMateo@users.noreply.github.com> Date: Sun, 18 Apr 2021 17:44:28 +0200 Subject: [PATCH 3/4] Update and rename Classes and Computation to ClassesComputation.py --- Classes and Computation => ClassesComputation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename Classes and Computation => ClassesComputation.py (93%) diff --git a/Classes and Computation b/ClassesComputation.py similarity index 93% rename from Classes and Computation rename to ClassesComputation.py index af80138..3f912f2 100644 --- a/Classes and Computation +++ b/ClassesComputation.py @@ -55,7 +55,7 @@ def send_instructions(): distance_1 = '' for char in range(1, len(response)): - distance_1 += str(char) + distance_1 += str(response[char]) f_distance_1 = int(distance_1) @@ -63,7 +63,7 @@ def send_instructions(): distance_2 = '' for char in range(1, len(response)): - distance_1 += str(char) + distance_1 += str(response[char]) f_distance_2 = int(distance_2) From 6eaa3df1dea48e992b041ab76d0427c899673fa9 Mon Sep 17 00:00:00 2001 From: CasoMateo <67202211+CasoMateo@users.noreply.github.com> Date: Mon, 3 May 2021 23:04:30 +0200 Subject: [PATCH 4/4] Update and rename ClassesComputation.py to computation.py --- ClassesComputation.py | 80 ------------------------------------------- computation.py | 33 ++++++++++++++++++ 2 files changed, 33 insertions(+), 80 deletions(-) delete mode 100644 ClassesComputation.py create mode 100644 computation.py diff --git a/ClassesComputation.py b/ClassesComputation.py deleted file mode 100644 index 3f912f2..0000000 --- a/ClassesComputation.py +++ /dev/null @@ -1,80 +0,0 @@ -from abc import ABC, abstractmethod -import serial - -ser = serial.Serial('COM3', 9600) - - -class Motor: - - def __init__(GND, VCC): - self.GND = GND - self.VCC = VCC - - @abstractmethod - def send_parameter(parameter): - pass - - -class MotorDC(Motor): - - def __init__(GND, VCC): - super().__init(GND, VCC) - - 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(): - - response = ser.read() - - if response[0] == 'x': - distance_1 = '' - - for char in range(1, len(response)): - distance_1 += str(response[char]) - - f_distance_1 = int(distance_1) - - else: - distance_2 = '' - - for char in range(1, len(response)): - distance_1 += str(response[char]) - - f_distance_2 = int(distance_2) - - if f_distance_1 > f_distance_2: - ser.write('a'.encode()) - - else: - ser.write('b'.encode()) - - - - - - diff --git a/computation.py b/computation.py new file mode 100644 index 0000000..d7f5ddc --- /dev/null +++ b/computation.py @@ -0,0 +1,33 @@ +import serial + +ser = serial.Serial('COM3', 9600) + +def compute(): + + response = ser.read() + + if response[0] == 'x': + distance_1 = '' + + for char in range(1, len(response)): + distance_1 += str(response[char]) + + f_distance_1 = int(distance_1) + + else: + distance_2 = '' + + for char in range(1, len(response)): + distance_1 += str(response[char]) + + f_distance_2 = int(distance_2) + + if f_distance_1 > f_distance_2: + ser.write('a'.encode()) + + else: + ser.write('b'.encode()) + + + +