merge head

This commit is contained in:
Silver Kuusik 2018-12-29 22:27:26 +01:00
commit d63bda4681
3 changed files with 25 additions and 9 deletions

View File

@ -2,10 +2,12 @@
"status_led_pin": 22, "status_led_pin": 22,
"battery_coeff": 2.25, "battery_coeff": 2.25,
"sumo_id": "xxxxxxxx", "sumo_id": "xxxxxxxx",
"firmware_version": 0.3, "firmware_version": "0.3.1",
"left_servo_tuning": 33, "left_servo_tuning": 33,
"right_servo_tuning": 33, "right_servo_tuning": 33,
"ultrasonic_distance": 40, "ultrasonic_distance": 40,
"left_line_value": 1000,
"right_line_value": 1000,
"left_line_threshold": 1000, "left_line_threshold": 1000,
"right_line_threshold": 1000, "right_line_threshold": 1000,
"sumo_server": "165.227.140.64:80", "sumo_server": "165.227.140.64:80",

20
hal.py
View File

@ -143,10 +143,20 @@ class Sumorobot(object):
return opponent return opponent
# Function to update line calibration and write it to the config file # 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 # Read the line sensor values
self.config["left_line_threshold"] = self.adc_line_left.read() self.config["left_line_value"] = self.adc_line_left.read()
self.config["right_line_threshold"] = self.adc_line_right.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 # Update the config file
with open("config.part", "w") as config_file: with open("config.part", "w") as config_file:
config_file.write(ujson.dumps(self.config)) config_file.write(ujson.dumps(self.config))
@ -169,12 +179,12 @@ class Sumorobot(object):
# Return the given line sensor value # Return the given line sensor value
if dir == LEFT: 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) self.set_led(LEFT_LINE, line)
last_line = LEFT last_line = LEFT
return line return line
elif dir == RIGHT: 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) self.set_led(RIGHT_LINE, line)
last_line = RIGHT last_line = RIGHT
return line return line

10
main.py
View File

@ -88,9 +88,13 @@ def ws_handler():
sumorobot.move(STOP) sumorobot.move(STOP)
# for terminating delays in code # for terminating delays in code
sumorobot.terminate = True sumorobot.terminate = True
elif b'calibrate_line' in data: elif b'calibrate_line_value' in data:
sumorobot.calibrate_line() sumorobot.calibrate_line_value()
#print('main.py: calibrate_line') #print('main.py: calibrate_line_value')
elif b'calibrate_line_threshold' in data:
data = ujson.loads(data)
sumorobot.calibrate_line_threshold(int(data['val']))
#print('main.py: calibrate_line_threshold')
elif b'Gone' in data: elif b'Gone' in data:
print("main.py: server said 410 Gone, attempting to reconnect...") print("main.py: server said 410 Gone, attempting to reconnect...")
#conn = uwebsockets.connect(url) #conn = uwebsockets.connect(url)