Hi!
Sadly, I have to reopen the issue. I've tried to follow the instructions from this thread and the Wiki, but no luck. Here's what's going on:
1. I added the following to crazyflie-firmware/modules/src/stabilizer.c:
Code: Select all
LOG_GROUP_START(acc)
LOG_ADD(LOG_FLOAT, x, &acc.x)
LOG_ADD(LOG_FLOAT, y, &acc.y)
LOG_ADD(LOG_FLOAT, z, &acc.z)
LOG_GROUP_STOP(acc)
After compiling and flashing the firmware, I can see the variables acc.x, acc.y and acc.z as floats in the Log TOC in the CF client.
2. I tried to get the accelerometer values to log with a Python script, but it didn't work. I think that part of the problem is that the example for adding loggable variables in the Wiki might base on an older API in the PC client, but I'm not sure. Here's what I've got:
Code: Select all
import cflib.crtp
from cfclient.utils.logconfigreader import LogConfig
from cfclient.utils.logconfigreader import LogVariable
from cflib.crazyflie import Crazyflie
class Main:
def __init__(self):
self.crazyflie = Crazyflie()
cflib.crtp.init_drivers()
# Set accelerometer logging config
accel_log_conf = LogConfig("Accel", 10)
accel_log_conf.addVariable(LogVariable("acc.x", "float"))
accel_log_conf.addVariable(LogVariable("acc.y", "float"))
accel_log_conf.addVariable(LogVariable("acc.z", "float"))
self.crazyflie.open_link("radio://0/10/250K")
# Now that the connection is established, start logging
self.accel_log = self.crazyflie.log.create_log_packet(accel_log_conf)
if self.accel_log is not None:
self.accel_log.dataReceived.addCallback(log_accel_data)
self.accel_log.start()
else:
print("acc.x/y/z not found in log TOC")
self.crazyflie.connectSetupFinished.add_callback(
self.connectSetupFinished)
def connectSetupFinished(self, linkURI):
Thread(target=self.log_accel_data).start()
def log_accel_data(self, data):
logging.info("Accelerometer: x=%.2f, y=%.2f, z=%.2f" %
(data["acc.x"], data["acc.y"], data["acc.z"]))
time.sleep(0.01)
self.log_accel_data(data)
Main()
That code's not pretty, I know, I just wanted to test the principle of whether I could get the data. Here are my two questions concerning this step:
* When I run it, "acc.x/y/z not found in log TOC" is printed. But I can see the variables in the log TOC in the GUI! What's going on?
* I pretty much took the function log_accel_data() from the Wiki 1:1. I don't understand how the example in the wiki would work, though. The function "gyroData" in the Wiki is added as a callback. I assume the function is called as a Callable at some point in the code. But the function requires "data" to run. Where is it called?
Am I on the completely wrong path here?
Thanks a bunch!
Daniel