def is_color(ch, color, index=1): if not isinstance(index, (int, float)): return False if not isinstance(color, (str, )): return False id_list = neurons_get_block_index("m_dual_rgb_sensor") if index > len(id_list): return False ch = _get_channel(ch) if ch == None: return False #assert obj_color = _get_color_id(color) if obj_color == None: return False value = get_all_data(index) if ch == __SENSOR_CHANNEL_1: actual_color = value[5] elif ch == __SENSOR_CHANNEL_2: actual_color = value[6] else: return False if obj_color == actual_color: return True else: return False
def release_angle(index="all"): if index == "all": id_list = neurons_get_block_index("m_smartservo") for index in range(len(id_list)): neurons_request("m_smartservo", "lock_unlock", 0x01, index + 1) else: if (not isinstance(index, (int, ))) or (index <= 0): return neurons_request("m_smartservo", "lock_unlock", 0x01, index)
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)
def reset(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_zero", [], index + 1) else: if (not isinstance(index, (int))) or (index <= 0): return neurons_request("m_smartservo", "set_zero", [], index) # reserve 3 seconds, avoid frequent calling of this function. # because this api will operate the flash time.sleep(3)
def stop_all(): id_list = neurons_get_block_index("m_dc_motor") for index in range(len(id_list)): neurons_request("m_dc_motor", "set_power", 0, index + 1)