LOCO定位系统入门教程-使用python脚本使用灯光
说明:
介绍如何使用python脚本使用灯光
前面的两个LED M1 M4为红色/绿色(低电平使能),后面的两个LED仅为蓝色
步骤:
- 使用位掩码控制LED,高电平使能,scf.cf.param.set_value('led.bitmask', 255)
led.bitmask:| 7:ENABLE | 6:N/A | 5:BLUE_R | 4:RED_R | 3:GREEN_R | 2:RED_L | 1:GREEN_L | 0:BLUE_L |
| 4:RED_R | 3:GREEN_R |:10红色,01绿色,11红色
| 2:RED_L | 1:GREEN_L |:10红色,01绿色,11红色
1111 1111 255: M4 red, M1 red
1110 1111 239: M4 red, M1 green
1110 1011 235: M4 green, M1 green
1101 1110 222: M4 red, M1 red
1111 0101 245: M4 red, M1 red
1110 0011 227: M4 green, M1
1110 1001 233: M4 , M1 green
新建脚本light_check.py
代码如下
import time
import cflib.crtp
from cflib.crazyflie.swarm import CachedCfFactory
from cflib.crazyflie.swarm import Swarm
def activate_led_bit_mask(scf):
scf.cf.param.set_value('led.bitmask', 255)
def deactivate_led_bit_mask(scf):
scf.cf.param.set_value('led.bitmask', 0)
def light_check(scf):
activate_led_bit_mask(scf)
time.sleep(5)
deactivate_led_bit_mask(scf)
time.sleep(2)
uris = {
'radio://0/80/2M/E7E7E7E7E7',
# Add more URIs if you want more copters in the swarm
}
if __name__ == '__main__':
cflib.crtp.init_drivers()
factory = CachedCfFactory(rw_cache='./cache')
with Swarm(uris, factory=factory) as swarm:
swarm.parallel_safe(light_check)
- 执行脚本
python3 light_check.py
- crazyflie的M1 M4,同时亮红灯5秒,然后恢复正常
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号