Skip to content

Commit

Permalink
Add example script that uses the ParamFileHelper.
Browse files Browse the repository at this point in the history
The script will write all supplied parameters to the crazyflie and store them
  • Loading branch information
ToveRumar committed Jun 5, 2024
1 parent 7af6558 commit c7be40d
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions cflib/utils/param_file_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@


class ParamFileHelper:
'''ParamFileHelper is a helper to synchonously write multiple paramteters from a file and store them in persistent memory'''
def __init__(self, crazyflie):
if isinstance(crazyflie, Crazyflie):
self._cf = crazyflie
Expand Down
62 changes: 62 additions & 0 deletions examples/parameters/persistent_params_from_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# -*- coding: utf-8 -*-
#
# ,---------, ____ _ __
# | ,-^-, | / __ )(_) /_______________ _____ ___
# | ( O ) | / __ / / __/ ___/ ___/ __ `/_ / / _ \
# | / ,--' | / /_/ / / /_/ /__/ / / /_/ / / /_/ __/
# +------` /_____/_/\__/\___/_/ \__,_/ /___/\___/
#
# Copyright (C) 2021 Bitcraze AB
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, in version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
Example to show how to write several persistent parameters from a yaml file.
The params in the file should be formatted like this;
params:
activeMarker.back:
default_value: 3
is_stored: true
stored_value: 30
type: persistent_param_state
version: '1'
"""
import argparse
import logging
import cflib.crtp
from cflib.crazyflie import Crazyflie
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
from cflib.utils import uri_helper
from cflib.utils.param_file_helper import ParamFileHelper


# uri = uri_helper.uri_from_env(default='usb://0')
uri = uri_helper.uri_from_env(default='radio://0/37/2M/E7E7E7E7E7')

# Only output errors from the logging framework
logging.basicConfig(level=logging.ERROR)


if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-f', '--file', type=str, help='The yaml file containing the arguments. ')
args = parser.parse_args()

cflib.crtp.init_drivers()

cf = Crazyflie(rw_cache='./cache')
with SyncCrazyflie(uri, cf=cf) as scf:
writer = ParamFileHelper(scf.cf)
writer.store_params_from_file(args.file)


0 comments on commit c7be40d

Please sign in to comment.