Page 1 of 2
Uart or Console
Posted: Sun Jun 30, 2013 3:49 pm
by overdrivr
Hi all,
I want to recover sensor data from the crazyflie in the cfclient, and later do some processing on it, is it best to use uartPrintf or ConsolePrintf ? What's the difference between those two ?
Thanks
Re: Uart or Console
Posted: Sun Jun 30, 2013 7:30 pm
by tobias
Only have a minute so it will be a short post but you can start by looking
here.
uartPrintf is for the uart on the expansion header and the ConsolePrintf will print to the console in the cfclient. Don't print to much before the radio link is open though or the task printing will be blocked.
Re: Uart or Console
Posted: Mon Jul 01, 2013 3:42 pm
by marcus
Hi,
I would recommend using the logging framework unless you want a lot of data, then the UART in the connector would be the best. Have a look at the link that Tobias posted, there's examples on how to use the logging framework. The data that you see in the client (battery and FlightControlTab) is implemented using the logging framework.
Re: Uart or Console
Posted: Sat Jul 06, 2013 2:57 pm
by overdrivr
I decided to go with the logging framework, I added a custom function in sensFusion6.h & .c, which uses some custom global variables defined in sensFusion.c.
I added the following code right after the variable declaration to log the values :
Code: Select all
LOG_GROUP_START(custom_stuff)
LOG_ADD(LOG_FLOAT, velocity.x, &velocity.x)
LOG_ADD(LOG_FLOAT, velocity.y, &velocity.y)
LOG_ADD(LOG_FLOAT, velocity.z, &velocity.z)
LOG_ADD(LOG_FLOAT, position.x, &position.x)
LOG_ADD(LOG_FLOAT, position.y, &position.y)
LOG_ADD(LOG_FLOAT, position.z, &position.z)
LOG_GROUP_STOP(custom_stuff);
Firmware compiles, I have uploaded it on the cf
Is that all to do CF-side ?
Client side, I added
Code: Select all
lg2 = LogConfig("Custom_stuff")
lg2.addVariable(LogVariable("velocity.x","float"))
lg2.addVariable(LogVariable("velocity.y","float"))
lg2.addVariable(LogVariable("velocity.z","float"))
lg2.addVariable(LogVariable("position.x","float"))
lg2.addVariable(LogVariable("position.y","float"))
lg2.addVariable(LogVariable("position.z","float"))
in the definition of connectionDone. I have very few skills in python, am I doing it right ? I know python is interpreted, so no compilation, but do I need to do something to update the client executable ?
My problem is I thought I would be able to visualise the variables in the plotter, but the group "Custom_stuff" does not appears in the list, any ideas on what's going wrong ?
Re: Uart or Console
Posted: Mon Jul 08, 2013 2:16 pm
by marcus
This is what the code should look like in the firmware to add the variables velocity.x/y/z and position.x/y/z:
Code: Select all
LOG_GROUP_START(velocity)
LOG_ADD(LOG_FLOAT, x, &velocity.x)
LOG_ADD(LOG_FLOAT, y, &velocity.y)
LOG_ADD(LOG_FLOAT, z, &velocity.z)
LOG_GROUP_STOP(velocity);
LOG_GROUP_START(position)
LOG_ADD(LOG_FLOAT, x, &position.x)
LOG_ADD(LOG_FLOAT, y, &position.y)
LOG_ADD(LOG_FLOAT, z, &position.z)
LOG_GROUP_STOP(position);
When you connect to the Crazyflie you can go to the menu
View->Tabs->Log TOC and you should be able to see your newly added variables.
Then on the client side the support for plotting is unfortunately still pretty shaky so I would recommend printing it in the console or saving the values to a file and plotting with some other tool. Here's what the code should look like in the client if you would like to print the values every 10ms:
Code: Select all
# Callback called when the connection is established to the Crazyflie
def connected(linkURI):
custom = LogConfig("My custom logging", 10)
custom.addVariable(LogVariable("velocity.x", "float"))
custom.addVariable(LogVariable("velocity.y", "float"))
custom.addVariable(LogVariable("velocity.z", "float"))
custom.addVariable(LogVariable("position.x", "float"))
custom.addVariable(LogVariable("position.y", "float"))
custom.addVariable(LogVariable("position.z", "float"))
# crazyflie is an instance of the Crazyflie class that has been instantiated and connected
log = crazyflie.log.newLogPacket(custom)
if (log != None):
log.dataReceived.addCallback(custom_data)
log.startLogging()
else:
print "Variables not found in TOC"
def custom_data(data):
print "Velocity: x=%.2f, y=%.2f, z=%.2f" % (data["velocity.x"], data["velocity.y"], data["velocity.z"])
print "Position: x=%.2f, y=%.2f, z=%.2f" % (data["position.x"], data["position.y"], data["position.z"])
You also have to add the connected callback. Either use that that is already in or add a new one:
Code: Select all
self.cf.connectSetupFinished.add_callback(self.connected)
Re: Uart or Console
Posted: Fri Jul 12, 2013 7:12 pm
by overdrivr
Ok I see the values in the TOC. Does that they are being send over the RF link and I just have to read them client-side ? Or do I need to do some sort of querying ?
Is it possible to use Processing (
http://www.processing.org/) with the Serial lib ? Won't the pc client intercept the serial port ?
Re: Uart or Console
Posted: Mon Jul 15, 2013 8:36 am
by marcus
Once you use the Python code above the Crazyflie will "push" log data to the client and it will end up in the callback named "custom_data". At that point you can do what ever you would like with the data. If you want to process it using something else then I would dump all the values to a file and open it in another application.
Re: Uart or Console
Posted: Mon Jul 15, 2013 5:00 pm
by overdrivr
Thank you for your answer marcus, I will use an external file to view the data. In the end I would like to see the data in real time, but that'll have to wait for my python skills to improve a bit.
Edit : I cannot manage to get the code working, I've put both callbacks in the main ui class, and registered the callback "connected" with
Code: Select all
self.cf.connectSetupFinished.add_callback(self.connected)
Right after the similar line, but that does not work, I even added print "test" at the beginning of the "connected" function, but it never shows up on the console, and worse the console does not display anything at all, not even the regular log. Also tried using logger.info(test), did not work either.
To sum up... i'm kinda lost :p
Re: Uart or Console
Posted: Wed Jul 17, 2013 9:03 am
by marcus
Do you have the code published somewhere so I can try and run it? I would need both the firmware and client.
Re: Uart or Console
Posted: Fri Jul 19, 2013 4:27 pm
by overdrivr
Here are the only files I modified :
Firmware:
sensorfusion.h
sensorfusion.c
stablizer.c
Pc_Client :
(lib/cfclient/ui)
main.py
https://docs.google.com/file/d/0B33g5NZ ... sp=sharing
Let me know if you really need every files, thanks for your help marcus
