Getting sensor data with the Python API

Firmware/software/electronics/mechanics
Post Reply
Phasmicor
Beginner
Posts: 2
Joined: Tue Dec 24, 2013 4:06 pm

Getting sensor data with the Python API

Post by Phasmicor » Wed Dec 25, 2013 6:31 pm

Hi guys, I have a 10DOF model of the CF and I'm having brilliant fun with it. I've got some knowledge of python and I've managed to control the CF with my iPad. Without going in to too much detail on my setup (it's probably a bit messy), I control the pitch/roll by tilting my tablet and thrust and yaw can be set with a slider and a couple of buttons so it's all nice and simple :)

The next stage of this is to start getting some sensor data from the CF. I'm mainly after the accelerometer, gyros and altimeter/magnometer. I've trawled through almost all threads on this topic and I've tried out some sample code too but I still haven't managed to figure it out. I've pasted the results from my code tests below. All I'm after here is a stream of data for each of the sensors that I can use. This will enable me to add some cool new features (like orientating the quad in the same direction that my tablet is facing).

The code example to add accelerometer logging on the python API wiki and it come up with the following:

Code: Select all

DEBUG:cflib.crazyflie.toc:[2]: Done!
INFO:cflib.crazyflie:Param TOC finished updating
INFO:cflib.crazyflie:Callback->Connection setup finished [radio://0/10/250K]
WARNING:cflib.crazyflie.toc:Unable to find variable [acc.x]
WARNING:cflib.crazyflie.log:Log: acc.x not in TOC, this block cannot be used!
acc.x/y/z not found in log TOC
I then tried a gyro version that I found (http://forum.bitcraze.se/viewtopic.php?f=6&t=580) and that came up with the following:

Code: Select all

INFO:cflib.crazyflie:Callback->Connection setup finished [radio://0/10/250K]
WARNING:cflib.crazyflie:Exception while doing callback on port [2]

  Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cflib/crazyflie/__init__.py", line 334, in run
    cb[4](pk)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cflib/crazyflie/toc.py", line 199, in _new_packet_cb
    self._toc_fetch_finished()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cflib/crazyflie/toc.py", line 151, in _toc_fetch_finished
    self.finishedCallback()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cflib/crazyflie/__init__.py", line 136, in _param_toc_updated_cb
    self.connectSetupFinished.call(self.link_uri)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cflib/utils/callbacks.py", line 56, in call
    cb(*args)
  File "test log.py", line 48, in connected
    gyrolog = self.crazyflie.log._new_packet_cb(gyroconf)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cflib/crazyflie/log.py", line 273, in _new_packet_cb
    chan = packet.channel
AttributeError: LogConfig instance has no attribute 'channel'
Finally, I ran another bit of code I found on this thread (http://forum.bitcraze.se/viewtopic.php? ... =log#p2937). This lists all available variables for logging and most of the sensors weren't even on there??

Code: Select all

INFO:cflib.crazyflie:Param TOC finished updating
INFO:cflib.crazyflie:Callback->Connection setup finished [radio://0/10/250K]
INFO:root:printing the TOC
INFO:root:name=stabilizer.thrust, index=4, pytype=<H, ctype=uint16_t
INFO:root:name=stabilizer.yaw, index=3, pytype=<f, ctype=float
INFO:root:name=stabilizer.roll, index=1, pytype=<f, ctype=float
INFO:root:name=stabilizer.pitch, index=2, pytype=<f, ctype=float
INFO:root:name=motor.m4, index=5, pytype=<i, ctype=int32_t
INFO:root:name=motor.m1, index=6, pytype=<i, ctype=int32_t
INFO:root:name=motor.m3, index=8, pytype=<i, ctype=int32_t
INFO:root:name=motor.m2, index=7, pytype=<i, ctype=int32_t
INFO:root:name=pm.vbat, index=0, pytype=<f, ctype=float
I'm pretty confused over this. I've got the latest cflib and firmware (I think). Any help is much appreciated. Also, if anybody is interested in my iPad project, I could probably make a thread on it somewhere.



Post Reply