def get_learn_data(self): """ 返回学习后的,红外编码数据。该函数须在 ``learn`` 函数后使用。 :return: 返回编码后的红外脉冲数据buff """ i2c.writeto(16, b'\x07') return i2c.readfrom(16, 118)
def get_hsv(self): """ 获取hsv值,通过反射方式获取物体颜色时,须开启亮暗平衡调整功能。 :return: tuple hsv颜色值元组(h,s,v) """ i2c.writeto(17, b'\x05', False) hsv = ustruct.unpack('Iff', i2c.readfrom(17, 12)) return hsv
def get_rgb(self): """ 获取RGB值,通过反射方式获取物体颜色时,须开启亮暗平衡调整功能。 :return: tuple RGB颜色值元组(r,g,b) """ i2c.writeto(17, b'\x04', False) rgb = ustruct.unpack('BBB', i2c.readfrom(17, 3)) return rgb
def get_raw(self): """ 获取裸数据 :return: tuple 裸数据元组(r,g,b,c) """ i2c.writeto(17, b'\x03', False) raw = ustruct.unpack('HHHH', i2c.readfrom(17, 8)) return raw
def get_battery_level(): """ 获取拓展板的电压值。 :return: 返回电量,单位mV。 """ i2c.writeto(16, b'\x03') tmp = i2c.readfrom(16, 2) return struct.unpack('H', tmp)[0]
def humidity(self): """ 获取湿度 :return: 湿度,单位% """ self.i2c.writeto(0x40, b'\xf5') sleep_ms(25) t = i2c.readfrom(0x40, 2) return -6 + 125 * (t[0] * 256 + t[1]) / 65535
def temperature(self): """ 获取温度 :return: 温度,单位摄氏度 """ self.i2c.writeto(0x40, b'\xf3') sleep_ms(70) t = i2c.readfrom(0x40, 2) return -46.86 + 175.72 * (t[0] * 256 + t[1]) / 65535
def get_lux(self): """ 获取亮度值 :return: int 亮度值,单位lux """ self.set_led(False) i2c.writeto(17, b'\x08', False) lux = ustruct.unpack('H', i2c.readfrom(17, 2))[0] return lux
def get_temp(self): """ 获取色温值 :return: int 色温值 """ self.set_led(False) i2c.writeto(17, b'\x06', False) color_temp = ustruct.unpack('H', i2c.readfrom(17, 2))[0] return color_temp
def get_sensor_val(self): """ 获取防跌落传感器AD采样值 :return: tuple 四个防跌落传感器AD采样值 """ if self.drop_detct_ir_on == False: self.drop_detct_ir_on = True i2c.writeto(17, b'\x8E') #打开防跌红外发射管 i2c.writeto(17, b'\x01', False) #发出读ADC数据指令 tmp = ustruct.unpack('HHHHHHHH', i2c.readfrom(17, 16)) drop_detect_data = tmp[4:8] return drop_detect_data
def get_val(self): """ 获取循迹AD采样值 :return: 四个循迹传感器AD采样值 """ if not self.tracking_led_on: self.tracking_led_on = True self.set_led(1) i2c.writeto(17, b'\x01', False) # 获取AD值 tmp = ustruct.unpack('HHHHHHHH', i2c.readfrom(17, 16)) tracking_data = tmp[0:4] return tracking_data
def get_params(self): """ 获取机器人所有配置参数 :return: 示例:(85, 0.002, 0.005, 1.0, 1.0, 1.0, 8, 11, 10, 30, 254, 3411, 3157, 259, 3444, 3185, 254, 3498, 3244, 252, 3305, 3053, 2000, 2000, 2000, 2000) | 85: 标记 | 0.002: 行走补偿 | 0.005: 旋转补偿 | 1.0, 1.0, 1.0: 亮平衡RGB比例值 | 8, 11, 10, 30: 暗平衡rgbc值 | 254, 3411, 3157, 259: 循迹传感器1白平衡亮、值、差值 有4组 """ i2c.writeto(17, b'\x71', False) sys_params = ustruct.unpack('I5f20H', i2c.readfrom(17, 56)) return sys_params
def get_battery_level(): i2c.writeto(16, b'\x03') tmp = i2c.readfrom(16, 2) return struct.unpack('H', tmp)[0]
def get_learn_status(self): i2c.writeto(16, b'\x08') return i2c.readfrom(16, 1)[0]
def get_learn_data(self): i2c.writeto(16, b'\x07') return i2c.readfrom(16, 118)