From 0c580d8c98885a8a6f524e44c58be8412691204a Mon Sep 17 00:00:00 2001 From: Silver Kuusik Date: Thu, 27 Dec 2018 09:02:15 +0100 Subject: [PATCH] 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))