Crazyflie Log Data and Z Ranger

Post here to get support
Post Reply
firzen91
Beginner
Posts: 5
Joined: Sun Oct 08, 2017 9:42 am

Crazyflie Log Data and Z Ranger

Post by firzen91 »

Hi Everybody;

I bought 2 Crazyflies. They are too cool and I will use them in my Thesis. I can send a command to CF, But I have some problems with them.

1- How can I read Log data without using object ? (on the otherhand use basic python code.)

2- How can I read Z ranger deck ?

Code: Select all

import logging
import time
import logging
import time
from threading import Thread

import cflib
from cflib.crazyflie import Crazyflie
from cflib.crazyflie.log import LogConfig

logging.basicConfig(level=logging.ERROR)

values = [0,0,0]

cflib.crtp.init_drivers(enable_debug_driver=False)
cf = Crazyflie()

available = cflib.crtp.scan_interfaces()
print(available)
a = cf.open_link(available[0][0])
cf.commander.send_setpoint(0, 0, 0, 0)
print('Bağlandı!')


def position_callback(timestamp, data, logconf):
    Roll = data['Roll']
    Pitch = data['Pitch']
    Yaw = data['Yaw']
    print('Rot: ({}, {}, {})'.format(Roll, Pitch, Yaw))

log_conf = LogConfig(name='Read:', period_in_ms=100)
log_conf.add_variable('Roll', 'float')
log_conf.add_variable('Pitch', 'float')
log_conf.add_variable('Yaw', 'float')
a.cf.log.add_config(log_conf)
a.data_received_cb.add_callback(position_callback)
a.start()

while True:
	Output_Value = [Roll,Pitch,Yaw]
	print(Output_Value)	
	cf.commander.send_setpoint(0, 0, 0, 12000)
	time.sleep(0.01)
cf.close_link()
print('Bağlantı Koptu')
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Crazyflie Log Data and Z Ranger

Post by tobias »

Hi and welcome to the forum.

1. I'm note totally sure what you mean by Log data without using object? Have you checked the example in cflib?

2. You can use the log variable range.zrange to read the z-ranger distance.
firzen91
Beginner
Posts: 5
Joined: Sun Oct 08, 2017 9:42 am

Re: Crazyflie Log Data and Z Ranger

Post by firzen91 »

Hi Tobias;

I read this post. But really confused my brain. Because 1st link about that deafult example of Crazyflie. But I need to modify sample code which is basiclog. Secondly, z-ranger link which is sent by you is about that firmware. But I don't know how I can read data from Crazyflie. I have just example code and I only try to modify. Actually, crazyflie documentation has not good information for developer user.
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Crazyflie Log Data and Z Ranger

Post by arnaud »

Hi,
The Crazyflie software and lib have been designed to ease development and communication between the firmware and python scripts on the ground. The two main pieces of the architecture to achieve this are log and param: https://wiki.bitcraze.io/doc:crazyflie: ... am#logging. Almost everything in the Crazyflie is accessible using the log and param framework.

Using the log example you should be able to replace (or add, depending of what you need) the example "self._lg_stab.add_variable('stabilizer.roll', 'float')" by "self._lg_stab.add_variable('ranges.zrange', 'uint16_t')" in order to get the z-ranger readings.

To find out the name of the log variables, there is two approach: either you look in the firmware source code like Tobias showed you or you can loo in the Crazyflie client, you will find there a list of all log variables and you can make log block and plot them of see what the data looks like.
firzen91
Beginner
Posts: 5
Joined: Sun Oct 08, 2017 9:42 am

Re: Crazyflie Log Data and Z Ranger

Post by firzen91 »

Hi Arnaud;

I understand what you say. But I have tackle with OOP system. I don't want to use OOP (class and self command). So I am searching how I can solve this problem.

Any idea for this problem?

Thanks.
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Crazyflie Log Data and Z Ranger

Post by arnaud »

Hi,

Out of curiosity, is there any reason why you do not want to write object oriented code in Python?

The synchronous log example is written as a program without using class: https://github.com/bitcraze/crazyflie-l ... logSync.py. This could be a good example to start with.

There is no need to write an object to use the cflib, it just happens that it is how most of the example where written. You could do everything that is done in the examples without writing objects. The sync examples have been written that way so maybe you can look at them.
firzen91
Beginner
Posts: 5
Joined: Sun Oct 08, 2017 9:42 am

Re: Crazyflie Log Data and Z Ranger

Post by firzen91 »

Thanks Arnaud this source is so helpful :)

But I have 1 more question :(
I tried to combine "Send command" and "Read Command". It's not Work.

Do you have any idea for this tackle?
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Crazyflie Log Data and Z Ranger

Post by arnaud »

Hi,

I am not sure to understand, do you mean that you want to receive log blocks and send setpoints in the same program?
firzen91
Beginner
Posts: 5
Joined: Sun Oct 08, 2017 9:42 am

Re: Crazyflie Log Data and Z Ranger

Post by firzen91 »

Yeap, You understood me! :)
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Crazyflie Log Data and Z Ranger

Post by arnaud »

If you have a loop that gets the log reading, from within this loop you can call the setpoint function (like so: https://github.com/bitcraze/crazyflie-l ... ync.py#L58).

By the way, the autonomous sequence exemple is an exemple that setups a log, to verify that the kalman filter has merged, and that sends setpoints to the Crazyflie without defining any objects: https://github.com/bitcraze/crazyflie-l ... equence.py
Post Reply