[Beginner] Help with Python Client

Post here to get support
VeryConfused
Beginner
Posts: 9
Joined: Mon Mar 05, 2018 5:43 am

[Beginner] Help with Python Client

Post by VeryConfused »

Hello,

For a class that I am taking, a team and I are responsible for demonstrating basic autonomy for a quadcopter system (following a predetermined flight path for example, but that is much further down the line than where we are right now). We have chosen the Crazyflie as our platform on which to do this, as it seems like it provides lots of opportunities for user development. However, at the moment, we cannot figure out how to even send flight commands to the drone. I read the 'Getting Started with Development' page on the Bitcraze website, but all it seemed to teach was how to change the firmware in order to make an LED flash a different color. Because I want to actually send flight commands, it looks like I will need to use the 'Python client.' However, even though I have been seeing references to this almost everywhere I go to look for help, I am not too sure what it refers to. Is the Python client an IDE which can send code directly to the Crazyflie? If so, how do I access it? I do have the Bitcraze VM downloaded, which (supposedly?) should be all I need.

Basically, my question is this: Say that I want to tell the Crazyflie to execute a basic pre-written flight sequence, such as flowsequenceSync.py (I do have the flow deck and Crazyradio). Starting from the VM desktop, how do I get to the position where I am able to do that?

I would very much appreciate any kind of step-by-step instructions that anyone could give me, and don't worry about sounding condescending because I truly am rather clueless.

Thank you all for your time, and sorry for being such a beginner!
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: [Beginner] Help with Python Client

Post by arnaud »

Hi and welcome!

If you have the flow deck you can follow the getting started with STEM bundle: https://www.bitcraze.io/getting-started ... ne-bundle/

It should guide you to do exactly what you want to do: writing a small sequence that the Crazyflie will follow.

The VM contains everything needed to control the Crazyflie. Though, if all you want is to write python code to control the Crazyflie from the computer, it will be simpler to work directly on your machine as explain by the getting started guide.
VeryConfused
Beginner
Posts: 9
Joined: Mon Mar 05, 2018 5:43 am

Re: [Beginner] Help with Python Client

Post by VeryConfused »

I'd prefer to use the VM if possible, to allow more options for expanded development in the future. When following the instructions for the STEM bundle, I am unable to download the package "python3-usb". Isn't this the package which allows for communication with the radio dongle? Is there a way I can fix this?
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: [Beginner] Help with Python Client

Post by arnaud »

If you are using the VM, everything should be setup already. You should just be able to write the script and execute it.
VeryConfused
Beginner
Posts: 9
Joined: Mon Mar 05, 2018 5:43 am

Re: [Beginner] Help with Python Client

Post by VeryConfused »

I appreciate that you are trying to help, but I don't think I'm properly expressing what my struggle is. You are saying that I can simply 'execute the script' but it has not been that easy. Let me tell you where I am at right now.

I am on the desktop of the Virtual Machine. I have clicked the icon to update all projects. I have the Crazyradio plugged into my USB port. I have the CrazyFlie turned on. I can open a code in the Python IDE (IDLE3). I can run the code. However, after running the code, the output shown on the shell is quite long and the gist of it is that the program cannot find the Crazyradio dongle.

Is this an issue with the code? I know the line with "URI = 'radio://0/80/250K'" must be changed to reflect the identity of my personal Crazyradio. Where do I go to find my personal URI? I have tried opening up the CrazyFlie Client, but it shows no indication that I have a Crazyradio connected, and therefore no indication of how I can connect to the Crazyflie.

I hate to be a pest, but could you please just give me a step-by-step instruction of how to go from having downloaded the virtual machine and plugged in the Crazyradio, to being able to run a Python code that will be sent to the drone? I would very much appreciate your help. Thank you.
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: [Beginner] Help with Python Client

Post by arnaud »

Well I can only help if I know your state, thanks for updating your current state. Since you have idle3 running in the VM I would say that you have managed quite well so far :-).

If would be useful to know the exact error you are getting when running the script. If it is complaining about the Crazyradio being not detected it seems that you have not setup the Crazyradio to be passed in the virtual machine usign VirtualBox.

Do you have the Crazyflie flying manually from the virtual machine using the crazyflie client?

We have tried to work had at making getting started and they are step-by-step instruction so I think what you need to follow is:

1. Getting started with the Crazyflie 2.0. This will allow you to make sure everything is working and that the radio can connect your Crazyflie from within the VM.
2. Getting started with the STEM drone bundle. Once you have the VM able to connect to the Crazytflie, the script should work. I do not think IDLE was installed by default in the VM but you managed to get it in.

If any step fails, please give us some details about how the step had failed and we will work it out.
VeryConfused
Beginner
Posts: 9
Joined: Mon Mar 05, 2018 5:43 am

Re: [Beginner] Help with Python Client

Post by VeryConfused »

Okay, I've gotten through most of the "Getting Started with Crazyflie 2.0" instruction successfully this time. However, I run into problems when I try to actually click the "Connect" button within the Crazyflie Client on the VM. I have attached a screenshot of what the window looks like. As you can see, it says "Connecting to radio://0/2/2M ...", which would seem to indicate that it is in the process of connecting, however it never goes any further than this. Also, there appears to be an input for 'Link Quality', which is almost at full, but none of the other telemetry fields seem to be coming through. Is there something I can do to fix this? I have also attached a screenshot of the 'About Crazyflie Client' window to help diagnose any issues.

For the "Getting Started with the STEM Drone Bundle" instruction, I tried to run the line of code "sudo apt-get install python3 python3-pip python3-usb idle3" within the terminal on the VM. The output told me that it was "Unable to locate package python3-usb". So, I tried typing the same command except without the "python3-usb" part, and that seemed to work. Is this "python3-usb" an important package? If so, how can I install it if this did not work?

sudo groupadd plugdev
sudo usermod -a -G plugdev $USER
echo 'SUBSYSTEM=="usb", ATTRS{idVendor}=="1915", ATTRS{idProduct}=="7777", MODE="0664", GROUP="plugdev"' | sudo tee /etc/udev/rules.d/99-crazyradio.rules
I then proceeded to run these lines verbatim, which did not produce any error messages so I hope that means that it worked.

I then opened up idle3, and opened up the example 'flowsequenceSync.py', and changed the URI to equal what I believe is my personal radio address (radio://0/2/2M). The output of this code was just "Connecting to radio://0/2/2M", and it never went further than this.

This is all that I have tried so far, and all the errors I have encountered along the way. If you could give me any help with this, I'd greatly appreciate it. Thanks!
Attachments
aboutcfclient.PNG
cfclient.PNG
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: [Beginner] Help with Python Client

Post by arnaud »

Hi,

To answer the VM installation: python3-usb is already installed in the VM, it is needed to run the client and the examples. The VM uses an old version of Ubuntu where the package did not exist or had another name (I can't remember exactly), but the point is: except for idle3 everything should be already up and ready in the VM to control Crazyflie from a Python script. From your description everything is installed fine you just need to be able to connect your Crazyflie.

Both your attempt, with the client and with your script, are consistent. The connection process does not seem to go though.

Is the Crazyflie starting correctly? The M4 LED should blink GREEN multiple times at startup. One reason I see for the connection to not success is that the radio chip of the Crazyflie is starting but not the main CPU. In that case the behavior would be exactly as you described: the connection will never succeed but radio communication works.

What firmware are you running, have you updated your Crazyflie to the latest firmware when following the getting started instructions?
VeryConfused
Beginner
Posts: 9
Joined: Mon Mar 05, 2018 5:43 am

Re: [Beginner] Help with Python Client

Post by VeryConfused »

I am running the latest release of the Crazyflie firmware, which I downloaded from the Bitcraze GitHub as "crazyflie-2018.01". I then used the Crazyflie Client to update the firmware on the drone itself, as detailed in the "Update firmware in the Crazyflie" section of the Getting Started page (I attached a screenshot of the steps that I am referring to).

I think you are onto something with the LED's. According to the Getting Started page, plugging in a uUSB should initiate a self-test which will ideally result in the M4 LED blinking GREEN five times, as you said. As of right now, however, when I turn on the Crazyflie (either by using the power button or plugging in a uUSB), the only LED that turns on is M2 (the back right one), which is a solid BLUE color. The "Understanding LEDs" section (which I attached) does not provide any insight into this issue, as there is no listed condition which results in the back right LED being fully lit in blue. I tried redoing the firmware update process in case I messed it up the first time, but that did not fix the problem. While updating, however, the back two LEDs on the drone blinked blue and the front left LED flickered GREEN (it actually looked like yellow, but I could easily be wrong), which I believe is what should happen. But immediately upon finishing the update and exiting bootloader mode, the drone went straight back to only having one BLUE LED lit on the back right.

I also tried connecting the drone to my phone via the Crazyflie app, which is also the first thing I did after assembling it a few weeks ago. When I tried it then, it worked, and I was able to make the drone fly. However, when I tried the same thing a few minutes ago, I could not. The app said that it established a connection with the drone, but moving the joysticks to send motion commands did not produce any response. So, it is clear that something has happened to the drone between assembly and now which has hindered its ability to operate, but I do not know what that would have been, as I have only been following the instructions given.

Any insights?
Attachments
LED color guide
LED color guide
Steps followed to update firmware within the Crazyflie
Steps followed to update firmware within the Crazyflie
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: [Beginner] Help with Python Client

Post by arnaud »

Hi,

It looks like the flashing procedure is not working, you get a corrupted firmware in the drone. There is two things that can help
- Installing the winUSB driver instead of libUSB for the Crazyradio using Zadig and updating the Crazyflie again from within the VM.
- Installing the client on Windows, reverting to libUSB, and updating from the native client.

I have observed that sometimes updating from the VM failed, though it is normally intermittent.
Post Reply