Uart or Console
Uart or Console
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
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
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.
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
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.
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
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 :
Firmware compiles, I have uploaded it on the cf
Is that all to do CF-side ?
Client side, I added
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 ?
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);
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
This is what the code should look like in the firmware to add the variables velocity.x/y/z and position.x/y/z:
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:
You also have to add the connected callback. Either use that that is already in or add a new one:
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);
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"])
Code: Select all
self.cf.connectSetupFinished.add_callback(self.connected)
Re: Uart or Console
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 ?
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
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
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
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
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)
To sum up... i'm kinda lost :p
Re: Uart or Console
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
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
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