Exemplo n.º 1
0
def log_output(stream):
    for line in stream:
        ansible.send_message('UPDATE_CONSOLE',
                             {'console_output': {
                                 'value': line
                             }})
        time.sleep(0.05)  # don't want to flood ansible
Exemplo n.º 2
0
def log_output(stream):
    #TODO: figure out a way to limit speed of sending messages, so
    # ansible is not overflowed by printing too fast
    for line in stream:
        ansible.send_message('UPDATE_CONSOLE',
                             {'console_output': {
                                 'value': line
                             }})
Exemplo n.º 3
0
def log_output(stream):
    for line in stream:
        ansible.send_message('UPDATE_CONSOLE', {
            'console_output': {
                'value': line
            }
        })
        time.sleep(0.05) # don't want to flood ansible
Exemplo n.º 4
0
def log_output(stream):
    #TODO: figure out a way to limit speed of sending messages, so
    # ansible is not overflowed by printing too fast
    for line in stream:
        ansible.send_message('UPDATE_CONSOLE', {
            'console_output': {
                'value': line
            }
        })
Exemplo n.º 5
0
def log_output(stream):
    #TODO: figure out a way to limit speed of sending messages, so
    # ansible is not overflowed by printing too fast
    for line in stream:
        if robot_status == 0:
            return
        time.sleep(0.005)
        ansible.send_message('UPDATE_CONSOLE',
                             {'console_output': {
                                 'value': line
                             }})
Exemplo n.º 6
0
def log_output(stream):
    #TODO: figure out a way to limit speed of sending messages, so
    # ansible is not overflowed by printing too fast
    for line in stream:
        if robot_status == 0:
            return
        time.sleep(0.005)
        ansible.send_message('UPDATE_CONSOLE', {
            'console_output': {
                'value': line
            }
        })
Exemplo n.º 7
0
def send_motor_data(data):
    global motor_data_last_sent
    if time.time() < motor_data_last_sent + 1:
        return
    motor_data_last_sent = time.time()

    for name, value in data.items():
        ansible.send_message('UPDATE_PERIPHERAL', {
            'peripheral': {
                'name': device_id_get_name(name),
                'peripheralType':'MOTOR_SCALAR',
                'value': value,
                'id': name
            }
        })
Exemplo n.º 8
0
def send_motor_data(data):
    global motor_data_last_sent
    if time.time() < motor_data_last_sent + 1:
        return
    motor_data_last_sent = time.time()

    for name, value in data.items():
        ansible.send_message(
            'UPDATE_PERIPHERAL', {
                'peripheral': {
                    'name': device_id_get_name(name),
                    'peripheralType': 'MOTOR_SCALAR',
                    'value': value,
                    'id': name
                }
            })
Exemplo n.º 9
0
def send_peripheral_data(data):
    global peripheral_data_last_sent
    # TODO: This is a hack. Should put this into a separate process
    if time.time() < peripheral_data_last_sent + 1:
        return
    peripheral_data_last_sent = time.time()

    # Send sensor data
    for device_id, value in data.items():
        ansible.send_message('UPDATE_PERIPHERAL', {
            'peripheral': {
                'name': device_id_get_name(device_id),
                'peripheralType':h.getDeviceName(uid_to_type[device_id_to_uid(device_id)]),
                'value': value,
                'id': device_id
                }
            })
Exemplo n.º 10
0
def send_peripheral_data(data):
    global peripheral_data_last_sent
    # TODO: This is a hack. Should put this into a separate process
    if time.time() < peripheral_data_last_sent + 1:
        return
    peripheral_data_last_sent = time.time()

    # Send sensor data
    for device_id, value in data.items():
        ansible.send_message('UPDATE_PERIPHERAL', {
            'peripheral': {
                'name': 'sensor_{}'.format(device_id),
                'peripheralType':'SENSOR_BOOLEAN',
                'value': value,
                'id': device_id
                }
            })
Exemplo n.º 11
0
def send_peripheral_data(data):
    global peripheral_data_last_sent
    # TODO: This is a hack. Should put this into a separate process
    if time.time() < peripheral_data_last_sent + 1:
        return
    peripheral_data_last_sent = time.time()

    # Send sensor data
    for device_id, value in data.items():
        ansible.send_message(
            'UPDATE_PERIPHERAL', {
                'peripheral': {
                    'name': 'sensor_{}'.format(device_id),
                    'peripheralType': 'SENSOR_SCALAR',
                    'value': value,
                    'id': device_id
                }
            })
Exemplo n.º 12
0
def send_peripheral_data(data):
    global peripheral_data_last_sent
    # TODO: This is a hack. Should put this into a separate process
    if time.time() < peripheral_data_last_sent + 1:
        return
    peripheral_data_last_sent = time.time()

    # Send sensor data
    for device_id, value in data.items():
        ansible.send_message(
            'UPDATE_PERIPHERAL', {
                'peripheral': {
                    'name':
                    device_id_get_name(device_id),
                    'peripheralType':
                    h.getDeviceName(uid_to_type[device_id_to_uid(device_id)]),
                    'value':
                    value,
                    'id':
                    device_id
                }
            })
Exemplo n.º 13
0
def test_battery():
    global battery_UID
    if battery_UID is None or battery_UID not in [
            x[0] for x in connectedDevices
    ]:
        ansible.send_message(
            'ADD_ALERT', {
                'payload': {
                    'heading':
                    "Battery Error",
                    'message':
                    "Battery buzzer not connected. Please connect and restart the robot"
                }
            })
        ansible.send_message('UPDATE_BATTERY', {'battery': {'value': 0}})
        return False

    try:
        (safe, connected, c0, c1, c2,
         voltage), timestamp = h.getData(battery_UID, "dataUpdate")
    except:
        safe, voltage = False, 0.0

    ansible.send_message('UPDATE_BATTERY', {'battery': {'value': voltage}})

    if not safe:
        ansible.send_message(
            'ADD_ALERT', {
                'payload': {
                    'heading':
                    "Battery Error",
                    'message':
                    "Battery level critical. Reconnect a safe battery and restart the robot"
                }
            })
        return False
    else:
        return True
Exemplo n.º 14
0
def test_battery():
    global battery_UID
    if battery_UID is None or battery_UID not in [x[0] for x in connectedDevices]:
        ansible.send_message('ADD_ALERT', {
        'payload': {
            'heading': "Battery Error",
            'message': "Battery buzzer not connected. Please connect and restart the robot"
            }
        })
        ansible.send_message('UPDATE_BATTERY', {
            'battery': {
                'value': 0
                }
        })
        return False

    try:
        (safe, connected, c0, c1, c2, voltage), timestamp = h.getData(battery_UID,"dataUpdate")
    except:
        safe, voltage = False, 0.0

    ansible.send_message('UPDATE_BATTERY', {
       'battery': {
            'value': voltage
            }
    })

    if not safe:
        ansible.send_message('ADD_ALERT', {
        'payload': {
            'heading': "Battery Error",
            'message': "Battery level critical. Reconnect a safe battery and restart the robot"
            }
        })
        return False
    else:
        return True
Exemplo n.º 15
0
         console_proc = multiprocessing.Process(target=log_output, args=(lines_iter,))
         console_proc.start()
         robotStatus = 1
         print 'Running student code'
     elif msg_type == 'stop' and robotStatus:
         student_proc.terminate()
         console_proc.terminate()
         robotStatus = 0
         print 'Stopping student code'
     elif msg_type == 'custom_names':
         sensor_id = msg['content']['id']
         id_to_name[sensor_id] = msg['content']['name']
 ansible.send_message('UPDATE_PERIPHERAL', {
     'peripheral': {
         'name': id_to_name['1236'],
         'peripheralType': 'SENSOR_SCALAR',
         'value': random.randint(0, 100),
         'id': '1236'
     }
 })
 ansible.send_message('UPDATE_BATTERY', {
     'battery': {
         'value': batteryLevel
     }
 })
 ansible.send_message('UPDATE_STATUS', {
     'status': {
         'value': robotStatus
     }
 })
 ansible.send_message('UPDATE_PERIPHERAL', {
     'peripheral': {
Exemplo n.º 16
0
                'name': 'sensor_{}'.format(device_id),
                'peripheralType':'SENSOR_BOOLEAN',
                'value': value,
                'id': device_id
                }
            })

while True:
    msg = ansible.recv()
    # Handle any incoming commands from the UI
    if msg:
        msg_handling(msg)

    # Send whether or not robot is executing code
    ansible.send_message('UPDATE_STATUS', {
        'status': {'value': robot_status}
    })

    # Send battery level
    ansible.send_message('UPDATE_BATTERY', {
        'battery': {
            'value': 100 # TODO: Make this not a lie
        }
    })

    ansible.send_message('UPDATE_PERIPHERAL', {
                'peripheral': {
                    'name': name,
                    'peripheralType':'MOTOR_SCALAR',
                    'value': name_to_value[name],
                    'id': name_to_ids[name]
Exemplo n.º 17
0
            print 'Uploading student code'
        elif msg_type == 'stop' and robotStatus:
            student_proc.terminate()
            console_proc.terminate()
            robotStatus = 0
            print 'Stopping student code'
        elif msg_type == 'custom_names':
            sensor_id = msg['content']['id']
            id_to_name[sensor_id] = msg['content']['name']
        elif msg_type == 'update':
            print msg['content']['update_path']
            print msg['content']['signature_path']

    ansible.send_message('UPDATE_BATTERY', {
        'battery': {
            'value': batteryLevel
        }
    })
    ansible.send_message('UPDATE_STATUS', {
        'status': {
            'value': robotStatus
        }
    })

    if temporary_send > 0:
        ansible.send_message('UPDATE_PERIPHERAL', {
            'peripheral': {
                'name':id_to_name['1240'],
                'peripheralType': 'MOTOR_SCALAR',
                'value': random.uniform(-100, 100),
                'id': '1240'
Exemplo n.º 18
0
            robotStatus = 0
            print 'Uploading student code'
        elif msg_type == 'stop' and robotStatus:
            student_proc.terminate()
            console_proc.terminate()
            robotStatus = 0
            print 'Stopping student code'
        elif msg_type == 'custom_names':
            sensor_id = msg['content']['id']
            id_to_name[sensor_id] = msg['content']['name']
        elif msg_type == 'update':
            print msg['content']['update_path']
            print msg['content']['signature_path']

    ansible.send_message('UPDATE_BATTERY',
                         {'battery': {
                             'value': batteryLevel
                         }})
    ansible.send_message('UPDATE_STATUS', {'status': {'value': robotStatus}})

    if temporary_send > 0:
        ansible.send_message(
            'UPDATE_PERIPHERAL', {
                'peripheral': {
                    'name': id_to_name['1240'],
                    'peripheralType': 'MOTOR_SCALAR',
                    'value': random.uniform(-100, 100),
                    'id': '1240'
                }
            })
        ansible.send_message(
            'UPDATE_PERIPHERAL', {
Exemplo n.º 19
0
read_naming_map()
enumerate_hibike()
enumerate_motors()
mc.set('competition', {'competition': False})

while True:
    if battery_UID:  #TODO Only tests battery safety if battery buzzer is connected
        battery_safe = test_battery()
    if not battery_safe and battery_UID:  #TODO Disables sending alert if battery buzzer is not connected
        if robot_status:
            student_proc.terminate()
            stop_motors()
            robot_status = 0
        for _ in range(10):
            ansible.send_message('UPDATE_STATUS', {'status': {'value': False}})
            time.sleep(0.1)
        continue

    msg = ansible.recv()
    # Handle any incoming  commands from the UI
    if msg:
        msg_handling(msg)

    # Send whether or not robot is executing code
    ansible.send_message('UPDATE_STATUS', {'status': {'value': robot_status}})

    # Update sensor values, and send to UI
    update_hibike()
    all_sensor_data = get_all_data(connectedDevices)
    send_peripheral_data(all_sensor_data)
Exemplo n.º 20
0
                    'name': 'sensor_{}'.format(device_id),
                    'peripheralType': 'SENSOR_SCALAR',
                    'value': value,
                    'id': device_id
                }
            })


while True:
    msg = ansible.recv()
    # Handle any incoming commands from the UI
    if msg:
        msg_handling(msg)

    # Send whether or not robot is executing code
    ansible.send_message('UPDATE_STATUS', {'status': {'value': robot_status}})

    # Send battery level
    ansible.send_message(
        'UPDATE_BATTERY',
        {
            'battery': {
                'value': 100  # TODO: Make this not a lie
            }
        })

    # Update sensor values, and send to UI
    all_sensor_data = get_all_data(connectedDevices)
    send_peripheral_data(all_sensor_data)
    mc.set('sensor_values', all_sensor_data)
Exemplo n.º 21
0
         console_proc.start()
         robotStatus = 1
         print 'Running student code'
     elif msg_type == 'stop' and robotStatus:
         student_proc.terminate()
         console_proc.terminate()
         robotStatus = 0
         print 'Stopping student code'
     elif msg_type == 'custom_names':
         sensor_id = msg['content']['id']
         id_to_name[sensor_id] = msg['content']['name']
 ansible.send_message(
     'UPDATE_PERIPHERAL', {
         'peripheral': {
             'name': id_to_name['1236'],
             'peripheralType': 'SENSOR_SCALAR',
             'value': random.randint(0, 100),
             'id': '1236'
         }
     })
 ansible.send_message('UPDATE_BATTERY',
                      {'battery': {
                          'value': random.randint(0, 100)
                      }})
 ansible.send_message('UPDATE_STATUS', {'status': {'value': robotStatus}})
 ansible.send_message(
     'UPDATE_PERIPHERAL', {
         'peripheral': {
             'name': id_to_name['1234'],
             'peripheralType': 'MOTOR_SCALAR',
             'value': random.randint(0, 100),
Exemplo n.º 22
0
read_naming_map()
enumerate_hibike()
enumerate_motors()
mc.set('competition', {'competition': False})

while True:
    if battery_UID: #TODO Only tests battery safety if battery buzzer is connected
        battery_safe = test_battery()
    if not battery_safe and battery_UID: #TODO Disables sending alert if battery buzzer is not connected
        if robot_status:
            student_proc.terminate()
            stop_motors()
            robot_status = 0
        for _ in range(10):
            ansible.send_message('UPDATE_STATUS', {
                'status': {'value': False}
            })
            time.sleep(0.1)
        continue

    msg = ansible.recv()
    # Handle any incoming  commands from the UI
    if msg:
        msg_handling(msg)

    # Send whether or not robot is executing code
    ansible.send_message('UPDATE_STATUS', {
        'status': {'value': robot_status}
    })

    # Update sensor values, and send to UI