def calculate_last_drive(coords): direction = data_storage.get_direction() if direction == 0: last_drive = [coords[0], coords[1] - 1, coords[2]] elif direction == 1: last_drive = [coords[0] - 1, coords[1], coords[2]] elif direction == 2: last_drive = [coords[0], coords[1] + 1, coords[2]] elif direction == 3: last_drive = [coords[0] + 1, coords[1], coords[2]] return last_drive
def update_coords(coords): direction = data_storage.get_direction() new_coords = None if direction == 0: new_coords = [coords[0], coords[1] + 1, coords[2]] elif direction == 1: new_coords = [coords[0] + 1, coords[1], coords[2]] elif direction == 2: new_coords = [coords[0], coords[1] - 1, coords[2]] elif direction == 3: new_coords = [coords[0] - 1, coords[1], coords[2]] return new_coords
def update_direction(rotation): direction = data_storage.get_direction() if rotation == 90: direction += 1 elif rotation == 180: direction += 2 elif rotation == -90: direction -= 1 if direction > 4: direction -= 4 elif direction < 0: direction += 4 data_storage.set_direction(direction)
def calculate_action(parameter_wallsdata, parameter_victimsdata, parameter_environmentdata, parameter_motorsdata, parameter_current_tile, parameter_tasks): global glob_wallsdata global glob_victimsdata global glob_environmentdata global glob_motorsdata global direction global status global wanted_direction glob_wallsdata = parameter_wallsdata glob_victimsdata = parameter_victimsdata glob_environmentdata = parameter_environmentdata glob_motorsdata = parameter_motorsdata current_tile = parameter_current_tile tasks = parameter_tasks status = 0 direction = data_storage.get_direction() wanted_direction = data_storage.get_wanted_direction() if status == 0: check_rotation(glob_environmentdata) if status == 0: black_tile(glob_environmentdata) if status == 0: ramp_check(glob_environmentdata) if status == 0: map_update(glob_wallsdata) if status == 0: victims_check(glob_victimsdata) if status == 0: check_checkpoint(glob_environmentdata) data_storage.set_direction(direction) return current_tile, tasks
def analyze(data, which_type): if which_type == 'all': threshold = 10 walls = {} if data['ir']['left_back'] <= threshold and data['ir'][ 'left_front'] <= threshold: walls['left'] = 1 else: walls['left'] = 0 if data['ir']['front_left'] <= threshold and data['ir'][ 'front_left'] <= threshold: walls['front'] = 1 else: walls['front'] = 0 if data['ir']['right_front'] <= threshold and data['ir'][ 'right_back'] <= threshold: walls['right'] = 1 else: walls['right'] = 0 walls['back'] = 0 direction = data_storage.get_direction() if direction == 0: pass elif direction == 1: temp_walls = walls walls['front'] = temp_walls['left'] walls['right'] = temp_walls['front'] walls['back'] = temp_walls['right'] walls['left'] = temp_walls['back'] elif direction == 2: temp_walls = walls walls['front'] = temp_walls['back'] walls['right'] = temp_walls['left'] walls['back'] = temp_walls['front'] walls['left'] = temp_walls['right'] elif direction == 3: temp_walls = walls walls['front'] = temp_walls['right'] walls['right'] = temp_walls['back'] walls['back'] = temp_walls['left'] walls['left'] = temp_walls['front'] temp_border = 25 victims = {} if data['temp']['left_back'] >= temp_border and data['temp'][ 'left_front'] >= temp_border: victims['type'] = 'heat' victims['direction'] = 'left' victims['specs'] = None elif data['temp']['right_front'] >= temp_border and data['temp'][ 'right_back'] >= temp_border: victims['type'] = 'heat' victims['direction'] = 'right' victims['specs'] = None else: victims['type'] = None victims['direction'] = None victims['specs'] = None grayscale_border = 25 checkpoint_border = 75 tilt_border = 10 environment = {} if data['grayscale']['grayscale'] >= checkpoint_border: environment['floor'] = 'black' elif not data['grayscale']['grayscale'] > checkpoint_border and data[ 'grayscale']['grayscale'] >= grayscale_border: environment['floor'] = 'checkpoint' else: environment['floor'] = 'checkpoint' if data['gyro']['tilt'] >= tilt_border: environment['tilt'] = 'ramp_up' elif data['gyro']['tilt'] <= (tilt_border * -1): environment['tilt'] = 'ramp_down' else: environment['tilt'] = 'straight' environment['rotation'] = data['gyro']['rotation'] return walls, victims, environment, data['encoder'] elif which_type == 'walls': threshold = 10 walls = {} if data['ir']['left_back'] <= threshold and data['ir'][ 'left_front'] <= threshold: walls['left'] = 1 else: walls['left'] = 0 if data['ir']['front_left'] <= threshold and data['ir'][ 'front_left'] <= threshold: walls['front'] = 1 else: walls['front'] = 0 if data['ir']['right_front'] <= threshold and data['ir'][ 'right_back'] <= threshold: walls['right'] = 1 else: walls['right'] = 0 walls['back'] = 0 direction = data_storage.get_direction() if direction == 0: pass elif direction == 1: temp_walls = walls walls['front'] = temp_walls['left'] walls['right'] = temp_walls['front'] walls['back'] = temp_walls['right'] walls['left'] = temp_walls['back'] elif direction == 2: temp_walls = walls walls['front'] = temp_walls['back'] walls['right'] = temp_walls['left'] walls['back'] = temp_walls['front'] walls['left'] = temp_walls['right'] elif direction == 3: temp_walls = walls walls['front'] = temp_walls['right'] walls['right'] = temp_walls['back'] walls['back'] = temp_walls['left'] walls['left'] = temp_walls['front'] return walls elif which_type == 'victims': temp_border = 25 victims = {} if data['temp']['left_back'] >= temp_border and data['temp'][ 'left_front'] >= temp_border: victims['type'] = 'heat' victims['direction'] = 'left' victims['specs'] = None elif data['temp']['right_front'] >= temp_border and data['temp'][ 'right_back'] >= temp_border: victims['type'] = 'heat' victims['direction'] = 'right' victims['specs'] = None else: victims['type'] = None victims['direction'] = None victims['specs'] = None return victims elif which_type == 'environment': grayscale_border = 75 tilt_border = 10 environment = {} if data['grayscale']['grayscale'] >= grayscale_border: environment['floor'] = 'black' else: environment['floor'] = 'white' if data['gyro']['tilt'] >= tilt_border: environment['tilt'] = 'ramp_up' elif data['gyro']['tilt'] <= (tilt_border * -1): environment['tilt'] = 'ramp_down' else: environment['tilt'] = 'straight' environment['rotation'] = data['gyro']['rotation'] return environment elif which_type == 'motors': return data['encoder']
# maze 2020 logic module # Setup import data_storage import tile import wall glob_wallsdata = None glob_victimsdata = None glob_environmentdata = None glob_motorsdata = None current_tile = None tasks = None status = 0 direction = data_storage.get_direction() wanted_direction = data_storage.get_wanted_direction() # Modules def check_rotation(environmentdata): global status threshold = 15 if environmentdata['rotation'] <= data_storage.get_wanted_rotation( ) - threshold: tasks.add('Adjust more') pass elif environmentdata['rotation'] >= data_storage.get_wanted_rotation( ) + threshold: tasks.add('Adjust less') pass
def analyze(data, which_type): print('Arduinodata analyze function started') if which_type == 'all': print('Type is all') threshold = 10 walls = {} print('Infrared value left_back is:') print(data['ir']['left_back']) print('Infrared value left_front is:') print(data['ir']['left_front']) if data['ir']['left_back'] <= threshold and data['ir'][ 'left_front'] <= threshold: print('There is a freaking WALL on the left!') walls['left'] = 1 else: print('There is no wall on the left!') walls['left'] = 0 print('Infrared value front_left is:') print(data['ir']['front_left']) print('Infrared value front_right is:') print(data['ir']['front_right']) if data['ir']['front_left'] <= threshold and data['ir'][ 'front_right'] <= threshold: print('There is a freaking WALL in the front') walls['front'] = 1 else: print('There is no wall in the front!') walls['front'] = 0 print('Infrared value right_front is:') print(data['ir']['right_front']) print('Infrared value right_back is:') print(data['ir']['right_back']) if data['ir']['right_front'] <= threshold and data['ir'][ 'right_back'] <= threshold: print('There is a freaking WALL on the right!') walls['right'] = 1 else: print('There is no wall on the right!') walls['right'] = 0 walls['back'] = 0 print( 'There is no wall in the back because that is where we are from!') print('Getting direction out of data_storage module') direction = data_storage.get_direction() print(direction) print('Calculating walls for the new direction') if direction == 0: print('Direction is already correct!') pass elif direction == 1: print('Turn everything by 90 degrees') temp_walls = walls walls['front'] = temp_walls['left'] walls['right'] = temp_walls['front'] walls['back'] = temp_walls['right'] walls['left'] = temp_walls['back'] print(walls) elif direction == 2: print('Turn everything by 180 degrees') temp_walls = walls walls['front'] = temp_walls['back'] walls['right'] = temp_walls['left'] walls['back'] = temp_walls['front'] walls['left'] = temp_walls['right'] print(walls) elif direction == 3: print('Turn everything by 270 degrees') temp_walls = walls walls['front'] = temp_walls['right'] walls['right'] = temp_walls['back'] walls['back'] = temp_walls['left'] walls['left'] = temp_walls['front'] print(walls) temp_border = 25 victims = {} if data['temp']['left_back'] >= temp_border and data['temp'][ 'left_front'] >= temp_border: victims['type'] = 'heat' victims['direction'] = 'left' victims['specs'] = None elif data['temp']['right_front'] >= temp_border and data['temp'][ 'right_back'] >= temp_border: victims['type'] = 'heat' victims['direction'] = 'right' victims['specs'] = None else: victims['type'] = None victims['direction'] = None victims['specs'] = None grayscale_border = 25 checkpoint_border = 75 tilt_border = 10 environment = {} if data['grayscale']['grayscale'] >= checkpoint_border: environment['floor'] = 'black' elif not data['grayscale']['grayscale'] > checkpoint_border and data[ 'grayscale']['grayscale'] >= grayscale_border: environment['floor'] = 'checkpoint' else: environment['floor'] = 'checkpoint' if data['gyro']['tilt'] >= tilt_border: environment['tilt'] = 'ramp_up' elif data['gyro']['tilt'] <= (tilt_border * -1): environment['tilt'] = 'ramp_down' else: environment['tilt'] = 'straight' environment['rotation'] = data['gyro']['rotation'] return walls, victims, environment, data['encoder'] elif which_type == 'walls': threshold = 10 walls = {} if data['ir']['left_back'] <= threshold and data['ir'][ 'left_front'] <= threshold: walls['left'] = 1 else: walls['left'] = 0 if data['ir']['front_left'] <= threshold and data['ir'][ 'front_left'] <= threshold: walls['front'] = 1 else: walls['front'] = 0 if data['ir']['right_front'] <= threshold and data['ir'][ 'right_back'] <= threshold: walls['right'] = 1 else: walls['right'] = 0 walls['back'] = 0 direction = data_storage.get_direction() if direction == 0: pass elif direction == 1: temp_walls = walls walls['front'] = temp_walls['left'] walls['right'] = temp_walls['front'] walls['back'] = temp_walls['right'] walls['left'] = temp_walls['back'] elif direction == 2: temp_walls = walls walls['front'] = temp_walls['back'] walls['right'] = temp_walls['left'] walls['back'] = temp_walls['front'] walls['left'] = temp_walls['right'] elif direction == 3: temp_walls = walls walls['front'] = temp_walls['right'] walls['right'] = temp_walls['back'] walls['back'] = temp_walls['left'] walls['left'] = temp_walls['front'] return walls elif which_type == 'victims': temp_border = 25 victims = {} if data['temp']['left_back'] >= temp_border and data['temp'][ 'left_front'] >= temp_border: victims['type'] = 'heat' victims['direction'] = 'left' victims['specs'] = None elif data['temp']['right_front'] >= temp_border and data['temp'][ 'right_back'] >= temp_border: victims['type'] = 'heat' victims['direction'] = 'right' victims['specs'] = None else: victims['type'] = None victims['direction'] = None victims['specs'] = None return victims elif which_type == 'environment': grayscale_border = 75 tilt_border = 10 environment = {} if data['grayscale']['grayscale'] >= grayscale_border: environment['floor'] = 'black' else: environment['floor'] = 'white' if data['gyro']['tilt'] >= tilt_border: environment['tilt'] = 'ramp_up' elif data['gyro']['tilt'] <= (tilt_border * -1): environment['tilt'] = 'ramp_down' else: environment['tilt'] = 'straight' environment['rotation'] = data['gyro']['rotation'] return environment elif which_type == 'motors': return data['encoder']