Example #1
0
def show(message, pos_x=None, pos_y=None, wait=True, index=1):
    if not isinstance(index, (int, float)):
        return 0

    message = str(message)
    if message == '':
        clear()
        return

    str_len = len(message)
    if pos_x != None or pos_y != None:
        if pos_x == None:
            pos_x = 0
        if pos_y == None:
            pos_y = 0

        if (not isinstance(pos_x, (int, float))) or (not isinstance(
                pos_y, (int, float))):
            return
        pos_x = int(pos_x)
        pos_y = int(pos_y)
        neurons_request("m_led_panel", "show_str_with_pos",
                        (pos_x, pos_y, message), index)
    else:
        if wait:
            neurons_request("m_led_panel", "show_str_until_done", message,
                            index)
            while neurons_blocking_read("m_led_panel", "get_status",
                                        (), index) != [1]:
                if not neurons_is_block_online("m_led_panel", index):
                    return
                time.sleep(0.1)
        else:
            neurons_request("m_led_panel", "show_str", message, index)
Example #2
0
def get_gyroscope(axis, index = 1):
    if not isinstance(index, (int, float)):
        return 0

    if axis == 'x':
        value = neurons_blocking_read("m_motion_sensor", "get_gyr_x", (INQUIRE_ID, GYRO_X_ID), index)
    elif axis == 'y':
        value = neurons_blocking_read("m_motion_sensor", "get_gyr_y", (INQUIRE_ID, GYRO_Y_ID), index)
    elif axis == 'z':
        value = neurons_blocking_read("m_motion_sensor", "get_gyr_z", (INQUIRE_ID, GYRO_Z_ID), index)
    else:
        return 0

    if value != None:
        return value[0]
    else:
        return 0 
Example #3
0
def get_rotation(axis, index = 1):
    if not isinstance(index, (int, float)):
        return 0

    if axis == 'x':
        value = neurons_blocking_read("m_motion_sensor", "get_rotate_x", (INQUIRE_ID, ROTATE_X_ID), index)
    elif axis == 'y':
        value = neurons_blocking_read("m_motion_sensor", "get_rotate_y", (INQUIRE_ID, ROTATE_Y_ID), index)
    elif axis == 'z':
        value = neurons_blocking_read("m_motion_sensor", "get_rotate_z", (INQUIRE_ID, ROTATE_Z_ID), index)
    else:
        return 0
        
    if value != None:
        return value[0]
    else:
        return 0 
Example #4
0
def get_acceleration(axis, index = 1):
    if not isinstance(index, (int, float)):
        return 0

    if axis == 'x':
        value = neurons_blocking_read("m_motion_sensor", "get_acc_x", (INQUIRE_ID, ACC_X_ID), index)
    elif axis == 'y':
        value = neurons_blocking_read("m_motion_sensor", "get_acc_y", (INQUIRE_ID, ACC_Y_ID), index)
    elif axis == 'z':
        value = neurons_blocking_read("m_motion_sensor", "get_acc_z", (INQUIRE_ID, ACC_Z_ID), index)
    else:
        return 0

    if value != None:
        return value[0] * ACC_SHIFT
    else:
        return 0
Example #5
0
def get_volume(index=1):
    if not isinstance(index, (int, float)):
        return 0

    value = neurons_blocking_read("m_speaker", "get_volume", (), index)
    if value == None:
        return 0
    else:
        return value[0]
Example #6
0
def is_playing(index=1):
    if not isinstance(index, (int, float)):
        return False

    value = neurons_blocking_read("m_speaker", "get_status", (), index)
    if value == None:
        return False
    else:
        return bool(value[0])
Example #7
0
def is_rotating_anticlockwise(index = 1):
    if not isinstance(index, (int, float)):
        return False
        
    value = neurons_blocking_read("m_angle_sensor", "get_dir", (), index)
    if value[0] == ANTICLOCKWISE_VALUE:
        return True
    else:
        return False
Example #8
0
def get_angle_speed(index = 1):
    if not isinstance(index, (int, float)):
        return 0

    value = neurons_blocking_read("m_angle_sensor", "get_angle_speed", (), index)
    if value != None:
        return value[0]
    else:
        return 0
Example #9
0
def get_load(index=1):
    if not isinstance(index, (int, float)):
        return 0

    value = neurons_blocking_read("m_servo", "get_load", (), index)
    if value != None:
        return value[0]
    else:
        return 0
Example #10
0
def get_learn_data(index=1):  #获取学习的信息
    if (not isinstance(index, (int, float))) or (index <= 0):
        return 0
    value = neurons_blocking_read("m_smart_camera", "get_learn_data", (),
                                  index)
    if value != None:
        return value
    else:
        return 0
Example #11
0
def get_barcode_count(index=1):  #获取按键的信息
    if (not isinstance(index, (int, float))) or (index <= 0):
        return 0
    value = neurons_blocking_read("m_smart_camera", "get_barcode_count", (),
                                  index)
    if value != None:
        return value[0]
    else:
        return 0
Example #12
0
def get_load(index = 1):
    if not isinstance(index, (int, float)):
        return 0

    ret = neurons_blocking_read("m_dc_motor", "get_load", (), index)
    if ret:
        return ret[0]
    else:
        return 0
Example #13
0
def get_shake_strength(index = 1):
    if not isinstance(index, (int, float)):
        return 0

    value = neurons_blocking_read("m_motion_sensor", "get_shake_strength", (INQUIRE_ID, SHAKE_ID), index)

    if value != None:
        return round(value[0], 1)
    else:
        return 0 
Example #14
0
def get_crossings_line_angle_sigle_data(index=1):  #获取交叉口线角度的单独的信息
    if (not isinstance(index, (int, float))) or (index <= 0):
        return 0
    value = neurons_blocking_read("m_smart_camera",
                                  "get_crossings_line_angle_sigle_data", (),
                                  index)
    if value != None:
        return value
    else:
        return 0
Example #15
0
def get_roll(index = 1):
    if not isinstance(index, (int, float)):
        return 0

    value = neurons_blocking_read("m_motion_sensor", "get_roll", (INQUIRE_ID, ROLL_ID), index)

    if value != None:
        return value[0]
    else:
        return 0 
Example #16
0
def get_crossings_all_data(index=1):  #获交叉口的所有信息
    if (not isinstance(index, (int, float))) or (index <= 0):
        return 0
    value = neurons_blocking_read("m_smart_camera", "get_crossings_all_data",
                                  (), index)
    if value != None:
        value[0] = round(value[0] * FRAME_REVISE_COE_LINE_X)
        value[1] = round(value[1] * FRAME_REVISE_COE_LINE_Y)
        return value
    else:
        return 0
Example #17
0
def get_barcode_all_data(barcode_id, index=1):  #获取某个条形码的所有信息
    if (not isinstance(barcode_id, (int, float))) or (not isinstance(
            index, (int, float))) or (index <= 0):
        return 0
    barcode_id = num_range_scale(barcode_id, 0, 15)
    value = neurons_blocking_read("m_smart_camera", "get_barcode_all_data",
                                  (barcode_id), index)
    if value != None:
        value[1] = round(value[1] * FRAME_REVISE_COE_LINE_X)
        value[2] = round(value[2] * FRAME_REVISE_COE_LINE_Y)
        return value
    else:
        return 0
Example #18
0
def get_pixel(pos_x, pos_y, index=1):
    if not isinstance(index, (int, float)):
        return False

    if (not isinstance(pos_x,
                       (int, float))) or (not isinstance(pos_y, (int, float))):
        return False
    pos_x = int(pos_x)
    pos_y = int(pos_y)
    if pos_x < 0 or pos_x > 15 or pos_y < 0 or pos_y > 7:
        return False
    ret = neurons_blocking_read("m_led_panel", "get_pixel", (pos_x, pos_y),
                                index)
    return bool(ret[2])
Example #19
0
def is_shaked(level = "usual", index = 1):
    if not isinstance(index, (int, float)):
        return False

    value = neurons_blocking_read("m_motion_sensor", "get_shake_strength", (INQUIRE_ID, SHAKE_ID), index)
    if level in SHAKED_THRESHOLD:
        thres = SHAKED_THRESHOLD[level]
    else:
        thres = SHAKED_THRESHOLD["usual"]

    if value != None:
        return bool(value[0] > thres)
    else:
        return False
Example #20
0
def __get_info(index=1):
    global __led_value

    if not isinstance(index, (int, float)):
        return
    value = neurons_blocking_read("m_rgb", "get_info", (), index)
    value = value if value != None else [0, 0, 0]

    if index > __RGB_NUM_MAX:
        return

    __led_value[int(index)] = value

    return value
Example #21
0
def get_line_sigle_data(type_id, index=1):  #获取线的单独的信息
    if (not isinstance(type_id, (int, float))) or (not isinstance(
            index, (int, float))) or (index <= 0):
        return 0

    if type_id == 0x00 or type_id == 0x01 or type_id == 0x02 or type_id == 0x03:
        value = neurons_blocking_read("m_smart_camera", "get_line_sigle_data",
                                      (type_id), index)
        if value != None:
            if type_id == 0x00 or type_id == 0x02:
                value[1] = round(value[1] * FRAME_REVISE_COE_LINE_X)
            else:
                value[1] = round(value[1] * FRAME_REVISE_COE_LINE_Y)
            return value
    return 0
Example #22
0
def get_fills_all_data(fills_id, index=1):  # 获取某个色块所有信息
    if (not isinstance(fills_id, (int, float))) or (not isinstance(
            index, (int, float))) or (index <= 0):
        return 0
    fills_id = num_range_scale(fills_id, 1, 7)
    fills_id -= 1
    value = neurons_blocking_read("m_smart_camera", "get_fills_all_data",
                                  (int(fills_id)), int(index))
    if value != None:
        value[1] = round(value[1] * FRAME_REVISE_COE_COLOR_BLOCK_X)
        value[2] = round(value[2] * FRAME_REVISE_COE_COLOR_BLOCK_Y)
        value[3] = round(value[3] * FRAME_REVISE_COE_COLOR_BLOCK_X)
        value[4] = round(value[4] * FRAME_REVISE_COE_COLOR_BLOCK_Y)
        return value
    else:
        return 0
Example #23
0
def get_reflected_light(ch, index=1):
    if not isinstance(index, (int, float)):
        return 0

    ch = _get_channel(ch)
    if ch == None:
        return 0

    value = neurons_blocking_read("m_dual_rgb_sensor", "get_reflect_data", (),
                                  index)
    if value == None:
        return 0
    else:
        if ch == __SENSOR_CHANNEL_1:
            return value[0]
        elif ch == __SENSOR_CHANNEL_2:
            return value[1]
Example #24
0
 def get_current(channel=None, index=1):
     if index != 0x01:
         return 0
     if channel != "ALL" and channel != "S1" and channel != "S2":
         return 0
     value = neurons_blocking_read("m_halobot", "servo_get_current",
                                   (channel_dict["ALL"]), index)
     #print(value)
     if value != None:
         if channel == "S1":
             return value[1]
         elif channel == "S2":
             return value[2]
         else:
             return value[1:]
     else:
         return 0
Example #25
0
def get_crossings_sigle_data(type_id, index=1):  #获取交叉口的单独的信息
    if (not isinstance(type_id, (int, float))) or (not isinstance(
            index, (int, float))) or (index <= 0):
        return 0

    if type_id == 0x06 or type_id == 0x07 or type_id == 0x08:
        value = neurons_blocking_read("m_smart_camera",
                                      "get_crossings_sigle_data", (type_id),
                                      index)
        if value != None:
            if type_id == 0x06:
                value[1] = round(value[1] * FRAME_REVISE_COE_LINE_X)
            elif type_id == 0x07:
                value[1] = round(value[1] * FRAME_REVISE_COE_LINE_Y)
            return value
    else:
        return 0
Example #26
0
def play_melody_until_done(music, index=1):
    if not isinstance(index, (int, float)):
        return
    if not isinstance(music, str):
        return

# only process music name which the length is 4, such as "!101"
    if len(music) != 4:
        return

    neurons_request("m_speaker", "play_melody", music, index)

    if not neurons_is_block_online("m_speaker", index):
        return
    time.sleep(0.1)
    while neurons_blocking_read("m_speaker", "get_status", (), index) != [0]:
        if not neurons_is_block_online("m_speaker", index):
            return
        time.sleep(0.1)
Example #27
0
def change_power(power, index = 1):
    if not isinstance(index, (int, float)):
        return

    if not isinstance(power, (int, float)):
        return
    # there is a bug in mbuild dc motor, the type of power is 'byte'
    # can not cover -200 ~ 200, so we use another way to implement that
    #  power = num_range_scale(power, -200, 200)
    #  neurons_request("m_dc_motor", "change_power", power, index)

    cur_power = neurons_blocking_read("m_dc_motor", "get_power", (), index)
    if cur_power:
        power_to = cur_power[0] + power
    else:
        power_to = power

    power_to = num_range_scale(power_to, -100, 100)
    neurons_request("m_dc_motor", "set_power", power_to, index)
Example #28
0
def get_barcode_sigle_data(barcode_id, type_id, index=1):  #获取条形码X的单独的信息
    if (not isinstance(barcode_id, (int, float))) or (not isinstance(
            type_id,
        (int, float))) or (not isinstance(index,
                                          (int, float))) or (index <= 0):
        return 0
    barcode_id = num_range_scale(barcode_id, 0, 15)

    if type_id == 0x0b or type_id == 0x0c:
        value = neurons_blocking_read("m_smart_camera",
                                      "get_barcode_sigle_data",
                                      (barcode_id, type_id), index)
        if value != None:
            if type_id == 0x0b:
                value[2] = round(value[2] * FRAME_REVISE_COE_LINE_X)
            else:
                value[2] = round(value[2] * FRAME_REVISE_COE_LINE_Y)
            return value
    else:
        return 0
Example #29
0
def _get_rgb_value(item, ch, index):
    if not isinstance(index, (int, float)):
        return 0

    ch = _get_channel(ch)
    if ch == None:
        return 0

    value = neurons_blocking_read("m_dual_rgb_sensor", "get_color_rgb", (),
                                  index)

    if value == None:
        return 0

    if ch == __SENSOR_CHANNEL_1:
        ret = value[item]
    elif ch == __SENSOR_CHANNEL_2:
        ret = value[item + 3]

    return ret
Example #30
0
def get_fills_sigle_data(fills_id, type_id, index=1):  # 获取某个色块的单独的信息
    if (not isinstance(fills_id, (int, float))) or (not isinstance(
            type_id,
        (int, float))) or (not isinstance(index,
                                          (int, float))) or (index <= 0):
        return 0
    fills_id = num_range_scale(fills_id, 1, 7)
    fills_id -= 1

    if type_id == 0x00 or type_id == 0x01 or type_id == 0x02 or type_id == 0x03:
        value = neurons_blocking_read("m_smart_camera", "get_fills_sigle_data",
                                      (fills_id, type_id), index)
        if value != None:
            if type_id == 0x00 or type_id == 0x02:
                value[2] = round(value[2] * FRAME_REVISE_COE_COLOR_BLOCK_X)
            else:
                value[2] = round(value[2] * FRAME_REVISE_COE_COLOR_BLOCK_Y)
            return value
    else:
        return 0