Skip to content

Commit

Permalink
(#159) forgot to style check the new script
Browse files Browse the repository at this point in the history
  • Loading branch information
knmcguire committed Jul 23, 2020
1 parent af03706 commit c404c6d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/step-by-step/connect_log_param.md
Original file line number Diff line number Diff line change
Expand Up @@ -454,4 +454,4 @@ The crazyflie has parameter stabilizer.estimator set at number: 1

# Finished and What's next?

You're done and now you know how to connect to the crazyflie and how to retrieve the parameters and logging variables through a python script. The next step is to make the crazyflie fly by giving it setpoints which is one step closer to making your own application!
You're done and now you know how to connect to the crazyflie and how to retrieve the parameters and logging variables through a python script. The next step is to make the crazyflie fly by giving it setpoints which is one step closer to making your own application!
26 changes: 14 additions & 12 deletions examples/step-by-step/connect_log_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.

import logging
import time

import cflib.crtp
from cflib.crazyflie import Crazyflie
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie

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
Expand All @@ -40,32 +38,37 @@
# 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
full_name = groupstr + '.' + namestr

cf.param.add_update_callback(group=groupstr, name=namestr,
cb=param_stab_est_callback)
cb=param_stab_est_callback)
time.sleep(1)
cf.param.set_value(full_name,2)
cf.param.set_value(full_name, 2)
time.sleep(1)
cf.param.set_value(full_name,1)
cf.param.set_value(full_name, 1)
time.sleep(1)


def log_stab_callback(timestamp, data, logconf):
print('[%d][%s]: %s' % (timestamp, logconf.name, data))


def simple_log_async(scf, logconf):
cf = scf.cf
cf.log.add_config(logconf)
logconf.data_received_cb.add_callback(log_stab_callback)
logconf.start()
time.sleep(5)
logconf.stop()



def simple_log(scf, logconf):

with SyncLogger(scf, lg_stab) as logger:
Expand All @@ -92,13 +95,13 @@ def simple_connect():
# Initialize the low-level drivers (don't list the debug drivers)
cflib.crtp.init_drivers(enable_debug_driver=False)

lg_stab = LogConfig(name="Stabilizer", period_in_ms=10)
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"
group = 'stabilizer'
name = 'estimator'

with SyncCrazyflie(uri, cf=Crazyflie(rw_cache='./cache')) as scf:

Expand All @@ -109,4 +112,3 @@ def simple_connect():
# simple_log_async(scf, lg_stab)

simple_param_async(scf, group, name)

0 comments on commit c404c6d

Please sign in to comment.