From 2af1abde7792a3b4269cdb2b6fb22dffabdda390 Mon Sep 17 00:00:00 2001 From: Silver Kuusik Date: Tue, 13 Nov 2018 21:37:55 +0100 Subject: [PATCH 1/7] Update config.json --- config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.json b/config.json index 7d07440..de81bcd 100755 --- a/config.json +++ b/config.json @@ -2,7 +2,7 @@ "status_led_pin": 22, "battery_coeff": 2.25, "sumo_id": "xxxxxxxx", - "firmware_version": 0.3, + "firmware_version": 0.3.1, "left_servo_tuning": 33, "right_servo_tuning": 33, "ultrasonic_distance": 40, From 3995321b0cd070e54b00da9da69141b83db2fde4 Mon Sep 17 00:00:00 2001 From: Silver Kuusik Date: Tue, 13 Nov 2018 21:38:23 +0100 Subject: [PATCH 2/7] Update config.json --- config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.json b/config.json index de81bcd..2a7ca7c 100755 --- a/config.json +++ b/config.json @@ -2,7 +2,7 @@ "status_led_pin": 22, "battery_coeff": 2.25, "sumo_id": "xxxxxxxx", - "firmware_version": 0.3.1, + "firmware_version": "0.3.1", "left_servo_tuning": 33, "right_servo_tuning": 33, "ultrasonic_distance": 40, From 80a6cb7522c40f39b9074c9ef45fb0af8a0b0551 Mon Sep 17 00:00:00 2001 From: Silver Kuusik Date: Thu, 27 Dec 2018 08:53:07 +0100 Subject: [PATCH 3/7] add left/right line values --- config.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config.json b/config.json index 2a7ca7c..eec8912 100755 --- a/config.json +++ b/config.json @@ -6,6 +6,8 @@ "left_servo_tuning": 33, "right_servo_tuning": 33, "ultrasonic_distance": 40, + "left_line_value": 1000, + "right_line_value": 1000, "left_line_threshold": 1000, "right_line_threshold": 1000, "sumo_server": "165.227.140.64:80", From b8406b4d9432c3f4f6fb02c9b8f0c92d380b5794 Mon Sep 17 00:00:00 2001 From: Silver Kuusik Date: Thu, 27 Dec 2018 08:54:28 +0100 Subject: [PATCH 4/7] add left/right line value --- hal.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hal.py b/hal.py index 5b3ed3c..f15987e 100755 --- a/hal.py +++ b/hal.py @@ -169,12 +169,12 @@ class Sumorobot(object): # Return the given line sensor value if dir == LEFT: - line = abs(self.get_line(LEFT) - self.config["left_line_threshold"]) > 1000 + line = abs(self.get_line(LEFT) - self.config["left_line_value"]) > self.config["left_line_threshold"] self.set_led(LEFT_LINE, line) last_line = LEFT return line elif dir == RIGHT: - line = abs(self.get_line(RIGHT) - self.config["right_line_threshold"]) > 1000 + line = abs(self.get_line(RIGHT) - self.config["right_line_value"]) > self.config["right_line_threshold"] self.set_led(RIGHT_LINE, line) last_line = RIGHT return line From d7ba4efa8ec64c7b4b94037cc3cc2a6dcf1b0f59 Mon Sep 17 00:00:00 2001 From: Silver Kuusik Date: Thu, 27 Dec 2018 08:56:16 +0100 Subject: [PATCH 5/7] Update main.py --- main.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 44d7270..c84fa85 100755 --- a/main.py +++ b/main.py @@ -88,9 +88,12 @@ def ws_handler(): sumorobot.move(STOP) # for terminating delays in code sumorobot.terminate = True - elif b'calibrate_line' in data: - sumorobot.calibrate_line() - #print('calibrate') + elif b'calibrate_line_value' in data: + sumorobot.calibrate_line_value() + #print('calibrate_line') + elif b'calibrate_line_threshold' in data: + sumorobot.calibrate_line_threshold() + #print('calibrate_threshold') elif b'Gone' in data: print("server said 410 Gone, attempting to reconnect...") #conn = uwebsockets.connect(url) From 25dd06f4ccada68c744675ffd274a509c3eca716 Mon Sep 17 00:00:00 2001 From: Silver Kuusik Date: Thu, 27 Dec 2018 08:58:49 +0100 Subject: [PATCH 6/7] add line value and threshold --- main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index c84fa85..6df6315 100755 --- a/main.py +++ b/main.py @@ -92,7 +92,8 @@ def ws_handler(): sumorobot.calibrate_line_value() #print('calibrate_line') elif b'calibrate_line_threshold' in data: - sumorobot.calibrate_line_threshold() + data = ujson.loads(data) + sumorobot.calibrate_line_threshold(int(data['val'])) #print('calibrate_threshold') elif b'Gone' in data: print("server said 410 Gone, attempting to reconnect...") From 0c580d8c98885a8a6f524e44c58be8412691204a Mon Sep 17 00:00:00 2001 From: Silver Kuusik Date: Thu, 27 Dec 2018 09:02:15 +0100 Subject: [PATCH 7/7] add line value and threshold calibration --- hal.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/hal.py b/hal.py index f15987e..6210bb6 100755 --- a/hal.py +++ b/hal.py @@ -143,10 +143,20 @@ class Sumorobot(object): return opponent # Function to update line calibration and write it to the config file - def calibrate_line(self): + def calibrate_line_value(self): # Read the line sensor values - self.config["left_line_threshold"] = self.adc_line_left.read() - self.config["right_line_threshold"] = self.adc_line_right.read() + self.config["left_line_value"] = self.adc_line_left.read() + self.config["right_line_value"] = self.adc_line_right.read() + # Update the config file + with open("config.part", "w") as config_file: + config_file.write(ujson.dumps(self.config)) + os.rename("config.part", "config.json") + + # Function to update line threshold calibration and write it to the config file + def calibrate_line_threshold(self, value): + # Read the line sensor values + self.config["left_line_threshold"] = value + self.config["right_line_threshold"] = value # Update the config file with open("config.part", "w") as config_file: config_file.write(ujson.dumps(self.config))