Page 1 of 1

Crazyflie Log Data and Z Ranger

Posted: Sun Oct 08, 2017 9:47 am
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')

Re: Crazyflie Log Data and Z Ranger

Posted: Mon Oct 09, 2017 1:09 pm
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.

Re: Crazyflie Log Data and Z Ranger

Posted: Mon Oct 09, 2017 3:39 pm
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.

Re: Crazyflie Log Data and Z Ranger

Posted: Tue Oct 10, 2017 7:20 am
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.

Re: Crazyflie Log Data and Z Ranger

Posted: Wed Oct 11, 2017 4:03 pm
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.

Re: Crazyflie Log Data and Z Ranger

Posted: Thu Oct 12, 2017 9:14 am
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.

Re: Crazyflie Log Data and Z Ranger

Posted: Fri Oct 13, 2017 2:16 pm
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?

Re: Crazyflie Log Data and Z Ranger

Posted: Mon Oct 16, 2017 12:33 pm
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?

Re: Crazyflie Log Data and Z Ranger

Posted: Mon Oct 16, 2017 1:07 pm
by firzen91
Yeap, You understood me! :)

Re: Crazyflie Log Data and Z Ranger

Posted: Tue Oct 17, 2017 9:20 am
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