LOCO定位系统入门教程-使用python脚本读取和设置参数
说明:
- 介绍如何使用python脚本,读取和设置参数
步骤:
- 将Crazyflie连接到cfclient,点击客户端的菜单栏上
View
->Tabs
->Parameters
,来查看参数
新建一个python脚本connect_log_param.py
代码如下
import logging
import time
import cflib.crtp
from cflib.crazyflie import Crazyflie
from cflib.crazyflie.log import LogConfig
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
from cflib.crazyflie.syncLogger import SyncLogger
# URI to the Crazyflie to connect to
uri = 'radio://0/80/2M/E7E7E7E7E7'
# Only output errors from the logging framework
logging.basicConfig(level=logging.ERROR)
def param_stab_est_callback(name, value):
print('The crazyflie has parameter ' + name + ' set at number: ' + value)
def simple_param_async(scf, groupstr, namestr):
cf = scf.cf
full_name = groupstr + '.' + namestr
cf.param.add_update_callback(group=groupstr, name=namestr,
cb=param_stab_est_callback)
time.sleep(1)
cf.param.set_value(full_name, 2)
time.sleep(1)
cf.param.set_value(full_name, 1)
time.sleep(1)
def log_stab_callback(timestamp, data, logconf):
...
def simple_log_async(scf, logconf):
...
def simple_log(scf, logconf):
...
def simple_connect():
...
if __name__ == '__main__':
# Initialize the low-level drivers
cflib.crtp.init_drivers()
lg_stab = LogConfig(name='Stabilizer', period_in_ms=10)
lg_stab.add_variable('stabilizer.roll', 'float')
lg_stab.add_variable('stabilizer.pitch', 'float')
lg_stab.add_variable('stabilizer.yaw', 'float')
group = 'stabilizer'
name = 'estimator'
with SyncCrazyflie(uri, cf=Crazyflie(rw_cache='./cache')) as scf:
simple_param_async(scf, group, name)
- 运行脚本
python3 connect_log_param.py
- 结果如下
The crazyflie has parameter stabilizer.estimator set at number: 1
The crazyflie has parameter stabilizer.estimator set at number: 2
The crazyflie has parameter stabilizer.estimator set at number: 1
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号