예제 #1
0
def set_report_mode(mode, timestamp, index=1):
    timestamp = num_range_scale(timestamp, 10, None)
    if mode == 0x00 or mode == 0x01 or mode == 0x02:
        neurons_request("m_ultrasonic_sensor", "set_report_mode",
                        (mode, timestamp), index)
    else:
        pass
예제 #2
0
def __set_r_g_b(col_id, value, index):
    global __led_value

    value = num_range_scale(value, 0, 255)
    __led_value[index][col_id] = value

    neurons_request("m_rgb", r_g_b_list[col_id], value, index)
예제 #3
0
def release_angle(index="all"):
    if (not isinstance(index, (int, ))) or (index <= 0):
        return
    if index == "all":
        index = 0xff

    neurons_request("m_smartservo", "lock_unlock", 0x01, index)
예제 #4
0
def send(message, index = 1):
    if not isinstance(index, (int, float)):
        return
    if not isinstance(message, (str,)):
        return

    neurons_request("m_ir_sensor", "send_str", str(message, "utf8"), index)
예제 #5
0
def set_report_mode(mode, timestamp, index=1):
    timestamp = num_range_scale(timestamp, 10, None)
    if mode == 0x00 or mode == 0x01 or mode == 0x02:
        neurons_request("m_soil_moisture", "set_report_mode",
                        (mode, timestamp), index)
    else:
        pass
예제 #6
0
def set_camera_sensitometry(level, index=1):  #设置摄像头曝光度
    if (not isinstance(level, (int, float))) or (not isinstance(
            index, (int, float))) or (index <= 0):
        return
    level = num_range_scale(level, 0, 255)
    neurons_request("m_smart_camera", "set_camera_sensitometry", (level),
                    index)
예제 #7
0
def set_default_turning_angle(angle, index=1):  #设置默认的转向角度(不开放)
    if (not isinstance(angle, (int, float))) or (not isinstance(
            index, (int, float))) or (index <= 0):
        return
    angle = num_range_scale(angle, -180, 180)
    neurons_request("m_smart_camera", "set_default_turning_angle", (angle),
                    index)
예제 #8
0
def servo_reset(servo_index=1, device_index=1):
    if not isinstance(servo_index, (int, float)):
        return
    if not isinstance(device_index, (int, float)):
        return
    neurons_request("m_standard_shield", "servo_reset", (servo_index),
                    device_index)
예제 #9
0
파일: mbot.py 프로젝트: FFtust/k210_scripts
def run(left_speed, right_speed, index=1):  #rpm
    if not isinstance(index, (int, float)):
        return
    if not isinstance(left_speed, (int, float)):
        return

    neurons_request("m_mbot", "run", (left_speed, right_speed), index)
예제 #10
0
def car_spd_mode_apiece(left_speed=__DEFAULT_SPEED,
                        right_speed=__DEFAULT_SPEED,
                        run_time=0,
                        accel_time=1,
                        decel_time=1,
                        device_index=1):
    if not isinstance(left_speed, (int, float)):
        return
    if not isinstance(right_speed, (int, float)):
        return
    if not isinstance(run_time, (int)):
        return
    if not isinstance(accel_time, (int)):
        return
    if not isinstance(decel_time, (int)):
        return
    left_speed = num_range_scale(left_speed, -__MAX_SPEED, __MAX_SPEED)
    right_speed = num_range_scale(right_speed, -__MAX_SPEED, __MAX_SPEED)
    run_time = num_range_scale(run_time, 0, __MAX_RUN_TIME)
    accel_time = num_range_scale(accel_time, 0, __MAX_ACCEL_TIME)
    decel_time = num_range_scale(decel_time, 0, __MAX_DECEL_TIME)
    neurons_request(
        "m_starter_shield", "car_spd_mode_apiece",
        (left_speed, right_speed, run_time, accel_time, decel_time),
        device_index)
    time.sleep(run_time * __MS_TO_SECOND_FACTOR)
예제 #11
0
def led_strip_set_single(strip_index,
                         led_index,
                         red_value,
                         green_value,
                         blue_value,
                         device_index=1):
    if not isinstance(strip_index, (int, float)):
        return
    if not isinstance(led_index, (int, float)):
        return
    if not isinstance(red_value, (int, float)):
        return
    if not isinstance(green_value, (int, float)):
        return
    if not isinstance(blue_value, (int, float)):
        return
    if not isinstance(device_index, (int, float)):
        return
    strip_index = num_range_scale(strip_index, 0, 127)
    led_index = num_range_scale(led_index, 0, 127)
    red_value = num_range_scale(red_value, 0, 255)
    green_value = num_range_scale(green_value, 0, 255)
    blue_value = num_range_scale(blue_value, 0, 255)
    neurons_request(
        "m_standard_shield", "led_strip_set_single",
        (strip_index, led_index, red_value, green_value, blue_value),
        device_index)
예제 #12
0
def set_both_led_bri(bri_1,
                     bri_2=0,
                     bri_3=0,
                     bri_4=0,
                     bri_5=0,
                     bri_6=0,
                     bri_7=0,
                     bri_8=0,
                     index=1):
    if not isinstance(index, (int, float)):
        return
    if isinstance(bri_1, list):
        if len(bri_1) < 8:
            bri_1.extend([0] * (8 - len(bri_1)))
        elif len(bri_1) > 8:
            bri_1 = bri_1[0:8]
        for i in range(8):
            bri_1[i] = num_range_scale(bri_1[i], 0, 100)
        neurons_request("m_led_ultrasonic_sensor", "set_led_bri", bri_1, index)
    else:
        bri_1 = num_range_scale(bri_1, 0, 100)
        bri_2 = num_range_scale(bri_2, 0, 100)
        bri_3 = num_range_scale(bri_3, 0, 100)
        bri_4 = num_range_scale(bri_4, 0, 100)
        bri_5 = num_range_scale(bri_5, 0, 100)
        bri_6 = num_range_scale(bri_6, 0, 100)
        bri_7 = num_range_scale(bri_7, 0, 100)
        bri_8 = num_range_scale(bri_8, 0, 100)
        neurons_request(
            "m_led_ultrasonic_sensor", "set_led_bri",
            (bri_1, bri_2, bri_3, bri_4, bri_5, bri_6, bri_7, bri_8), index)
예제 #13
0
def lock(index=1):
    if (not isinstance(index, (int, ))) or (index <= 0):
        return
    if index == "all":
        index = 0xff

    neurons_request("m_smartservo", "lock_unlock", 0x00, index)
예제 #14
0
def set_angle(angle, index=1):
    if not isinstance(index, (int, float)):
        return
    if not isinstance(angle, (int, float)):
        return

    angle = num_range_scale(angle, 0, 180)
    neurons_request("m_servo", "set_angle", angle, index)
예제 #15
0
def encoder_motor_reset_position(motor_index, device_index=1):
    if not isinstance(motor_index, (int, float)):
        return
    if not isinstance(device_index, (int, float)):
        return
    motor_index = num_range_scale(motor_index, 0, 127)
    neurons_request("m_starter_shield", "encoder_motor_reset_position",
                    (motor_index), device_index)
예제 #16
0
def set_power(power, index=1):
    if not isinstance(index, (int, float)):
        return
    if not isinstance(power, (int, float)):
        return

    power = num_range_scale(power, -100, 100)
    neurons_request("m_dc_motor", "set_power", power, index)
예제 #17
0
def servo_release(servo_index=1, device_index=1):
    if not isinstance(servo_index, (int, float)):
        return
    if not isinstance(device_index, (int, float)):
        return
    servo_index = num_range_scale(servo_index, 0, 127)
    neurons_request("m_standard_shield", "servo_release", (servo_index),
                    device_index)
예제 #18
0
def led_strip_off_all(strip_index, device_index=1):
    if not isinstance(strip_index, (int, float)):
        return
    if not isinstance(device_index, (int, float)):
        return
    strip_index = num_range_scale(strip_index, 0, 127)
    neurons_request("m_standard_shield", "led_strip_off_all", (strip_index),
                    device_index)
예제 #19
0
def set_position_upload_mode(mode, index=1):
    if (not isinstance(index, (int))) or (index <= 0):
        return
    if index == "all":
        index = 0xff

    if mode == 0x00 or mode == 0x01 or mode == 0x02:
        neurons_request("m_smartservo", "get_position", mode, index)
예제 #20
0
def look_right_effect(led_bri, index):
    for count in range(3):
        neurons_request("m_led_ultrasonic_sensor", "set_led_bri",
                        (0, 0, led_bri, led_bri, 0, 0, led_bri, led_bri),
                        index)
        time.sleep(0.25)
        neurons_request("m_led_ultrasonic_sensor", "set_led_bri", (0, ) * 8,
                        index)
        time.sleep(0.25)
예제 #21
0
def power_set_power_all_state_mode(mode, period, device_index=1):
    if not isinstance(device_index, (int, float)):
        return 0
    if not isinstance(mode, (int, float)):
        return 0
    if not isinstance(period, (int, float)):
        return 0
    neurons_request("m_standard_shield", "power_set_power_all_state_mode",
                    (mode, period), device_index)
예제 #22
0
def dc_motor_stop(motor_index=1, device_index=1):
    if not isinstance(motor_index, (int, float)):
        return
    if not isinstance(device_index, (int, float)):
        return
    motor_index = num_range_scale(motor_index, 0, 127)
    power = 0
    neurons_request("m_standard_shield", "dc_motor_stop", (motor_index),
                    device_index)
예제 #23
0
def happy_effect(led_bri, index):
    led_arr = [0, led_bri, led_bri, 0, 0, led_bri, led_bri, 0]
    for count in range(3):
        neurons_request("m_led_ultrasonic_sensor", "set_led_bri", led_arr,
                        index)
        time.sleep(0.25)
        neurons_request("m_led_ultrasonic_sensor", "set_led_bri", (0, ) * 8,
                        index)
        time.sleep(0.25)
예제 #24
0
def power_set_battery_voltag_mode(mode, period, device_index=1):
    if not isinstance(device_index, (int, float)):
        return 0
    if not isinstance(mode, (int, float)):
        return 0
    if not isinstance(period, (int, float)):
        return 0
    neurons_request("m_starter_shield", "power_set_battery_voltag_mode",
                    (mode, period), device_index)
예제 #25
0
def change_volume(val, index=1):
    if not isinstance(index, (int, float)):
        return

    if not isinstance(val, (int, float)):
        return
    val = num_range_scale(val, -100, 100)
    neurons_request("m_speaker", "change_volume", val, index)
    time.sleep(0.05)
예제 #26
0
def move_to_in_time(position, time, index=1):
    if (not isinstance(position, (int))) or (not isinstance(
            time, (int, ))) or (not isinstance(index, (int))) or (index <= 0):
        return
    if index == "all":
        index = 0xff

    time = num_range_scale(time, 1, 16383)
    neurons_request("m_smartservo", "move_to_in_time", [position, time], index)
예제 #27
0
def move(position, speed, index=1):
    if (not isinstance(position, (int))) or (not isinstance(
            speed, (int, ))) or (not isinstance(index, (int))) or (index <= 0):
        return
    if index == "all":
        index = 0xff

    speed = num_range_scale(speed, 1, 50)
    neurons_request("m_smartservo", "move", [position, speed], index)
예제 #28
0
def set_report_mode(mode, timestamp, index=1):
    if not isinstance(timestamp, (int, float)):
        return

    timestamp = num_range_scale(timestamp, 10, None)
    if mode == __INQUIRE_REPORT_MODE or mode == __CHANGE_REPORT_MODE or mode == __PERIOD_REPORT_MODE:
        neurons_request("m_servo", "set_report_mode", (mode, timestamp), index)
    else:
        return
예제 #29
0
def stop(index="all"):
    if index == "all":
        id_list = neurons_get_block_index("m_smartservo")
        for index in range(len(id_list)):
            neurons_request("m_smartservo", "set_pwm", 0, index + 1)
    else:
        if (not isinstance(index, (int))) or (index <= 0):
            return
        neurons_request("m_smartservo", "set_pwm", 0, index)
예제 #30
0
def back_to_zero(speed, index=1):
    if (not isinstance(speed,
                       (int, ))) or (not isinstance(index,
                                                    (int))) or (index <= 0):
        return
    if index == "all":
        index = 0xff

    speed = num_range_scale(speed, 1, 50)
    neurons_request("m_smartservo", "back_to_zero", [0x00, speed], index)