Communincation between python client and Crazyflie

Firmware/software/electronics/mechanics
Post Reply
alanj853
Beginner
Posts: 3
Joined: Fri Nov 13, 2015 12:16 pm
Location: Ireland

Communincation between python client and Crazyflie

Post by alanj853 »

Hi,
I am having a bit of trouble with crazyflie 2.0 and I was hoping somebody could help me with it please. Just a quick background, I have done some C programming and have worked on 2 separate arduino projects, both of which were of a much smaller scale than the CF. I have done very little python. I do have a strong background in Java though and have done some networking through Java (with sockets, etc). So to sum up, I am pretty much a novice in this area.

Firstly, I will explain the end goal of my project. I want to write a program that will make the CF take off, hover for a number of seconds, and land again. (By hover I mean remain as stationary as possible while in mid air, so not just "altitude hold"). I am developing on the VM provided. Thanks to the ramp.py example python program provided in the VM to ramp up the motors, I have been able to partly see how the client communicates with the CF. From what I can see, the commands to the motors are sent though the "send_setpoint" python function in commander.py. From there, a CRTPacket object is created, and the thrust, roll, yaw and pitch data are structured so they can be added as data to this packet object, and then the packet is sent.

The problem is that I cannot see where the packet is "incoming" on the CF side of things.

My plan is to create a hover class in the "modules" firmware package. In this class there will be several methods to (hopefully!) make the CF hover (I have an idea to make the CF hover but I won't get into it here). I want to write a python program that uses the send_setpoint function to send a message (such as "hover") to the CF to call one of the methods in the hover class. So far I have edited the commander.py class and added the following method to send my message:

Code: Select all

def send_hover_command(self, hover_message):
        pk = CRTPPacket()
        pk.port = CRTPPort.COMMANDER
        pk.data = struct.pack('10s', hover_message)
        self._cf.send_packet(pk)
When the CF firmware receives this message, it should call the hover_init() method in my hover.c class. For now, my hover_init method will just have a some simple task in it (such as turn off the motors or print hello world to console), just so I can see that it is working properly.

So my problem is that I cannot see where the packets are coming in, and I do not know how to analyse them, and I would be very grateful if someone could even point me in the right direction.

Thanks.
chad
Expert
Posts: 555
Joined: Sun Sep 28, 2014 12:54 am
Location: New York, USA
Contact:

Re: Communincation between python client and Crazyflie

Post by chad »

This isn't going to answer your question directly because honestly, until I look a little closer, I don't know the answer but I want to ask some questions and make some statements that might take you in a different direction or change your thinking...

1) Why do you want to make a "hover" class in the firmware? To my mind, communication as to what the Crazyflie is doing and what it should be doing should be back and forth from a controller and the Crazyflie itself. The firmware handles everything the Crazyflie has to do with respect to sending feedback from its sensors and receiving commands from a controller (human or otherwise) and acting on them. Hovering can be completely implemented on the controller side without introducing changes to the "brain" of Crazyflie. Of course, if it's an excuse to learn how to hack the Crazyflie firmware, I get that too!

2) If you're not really into python, you might want to look into the ZMQ system Bitcraze has implemented. As a matter of fact, they have a ZMQ server "client" that you could run. This could allow you to create your controller in C, Java, or whatever other language ZMQ has bindings for. It's simple to send messages with JSON through ZMQ! But don't let me discourage you from using Python (or ZMQ from Python). Python is a great scripting language and well worth learning!

3) Do you have an STM32 debugger like the ST-Link/V2? Or maybe another JTAG or SWD debugger (used along with the Crazyflie debug adapter)? If not, and you're planning on fiddling with the firmware, you'll want one. You can use it to set breakpoints and print debug messages and such when working with new firmware changes. Otherwise, you'll be kind of blind to what's happening on the Crazyflie side of things.

4) There are a number of different projects around for autonomous flight. They may not coincide with your project goals but they might be worth looking into. There's the autonomous flight with a Kinect2 project. There's the sonar range finder mod. There's the (iMac) camera controlled Crazyflie hack. There's the ongoing DWM1000 local positioning system project.

So anyway, I know that's not a direct answer to your question but maybe it'll help you think about your project in a different way.

Hopefully one of the Bitcraze guys or someone else much smarter and more learned than me will pop on and directly answer your question!
Crazyflier - my CF journal...
4x Crazyflie Nano (1.0) 10-DOF + NeoPixel Ring mod.
3x Crazyflie 2.0 + Qi Charger and LED Decks.
Raspberry Pi Ground Control.
Mac OS X Dev Environment.
Walkera Devo7e, ESky ET6I, PS3 and iOS Controllers.
chad
Expert
Posts: 555
Joined: Sun Sep 28, 2014 12:54 am
Location: New York, USA
Contact:

Re: Communincation between python client and Crazyflie

Post by chad »

alanj853 wrote:So my problem is that I cannot see where the packets are coming in
For this specifically, you might want to have a look at "crazyflie-firmware/hal/src/radiolink.c."
Crazyflier - my CF journal...
4x Crazyflie Nano (1.0) 10-DOF + NeoPixel Ring mod.
3x Crazyflie 2.0 + Qi Charger and LED Decks.
Raspberry Pi Ground Control.
Mac OS X Dev Environment.
Walkera Devo7e, ESky ET6I, PS3 and iOS Controllers.
Post Reply