Quadcopters have been the most popular flying machine so far. Most of the people buy commercially available Ready to Fly quadcopters to train their selves to fly. As the next step they try to build their own quadcopter using frames, motors, flight controllers etc. Further, there are many tutorials, books on building your own quadcopter. Therefore, most of the electronic hobbyists know how to build a quadcopter by assembling the necessary components.
When we consider setting up an autonomous flying system for the quadcopter, usually APM, PixHawk, DJI flight controllers pop up in our mind. The main reason is that, these flight controllers provide a versatile platform with a GUI to program your quadcopter to fly automatically. We can set GPS points in google maps using these GUIs and fly our quadcopter just using one switch. But the capabilities are limited in these flight controllers. If you want to reach to the hardware level and program, these flight controllers are not the ideal option.
The most common problem with building autonomous quadcopters is the time takes to develop the stabilizing algorithm. Many people give up on their projects because of this reason. If we can tune our quadcopter to hover at one place???
Crazyflie 2.0"CrazyFlie" is an opensource quadcopter development platform. This is one of the best platforms I have used so far. With this, you can start building your own autonomous flying machines in your own way. Following video shows the capability of the CrazyFlie to hover at one place.
To begin, we need following items.
- CrazyFlie 2.0 - https://www.seeedstudio.com/Crazyflie-2.0-p-2103.html
- Crazy Radio - https://www.seeedstudio.com/Crazyradio-PA-long-range-2.4Ghz-USB-radio-dongle-with-antenna-p-2104.html
- Flow deck - https://www.seeedstudio.com/Crazyflie-2.0-Flow-Deck-p-2920.html
First, we need to assemble the CrazyFlie. Following link contains assembling instructions for CrazyFlie.
https://www.bitcraze.io/getting-started-with-the-crazyflie-2-0/
Flow DeckAfter assembling the CF, we need to connect the flow deck. Following image shows the correct way to connect the flow deck to CF.
Flow deck contains a flow sensor and a ToF sensor.
- Flow sensor is a low resolution camera which acts as a downward faced camera and process the images in order to detect movements in CF. This will help to avoid drifts and hover at one place. The performance of the flow deck depends on the light condition.
- ToF sensor is a range sensor. This measures the distance to the ground and helps to hover at a certain height.
To find more about the flow deck, check the following link. It shows how to use the flow deck in the manual flying mode. I'm not gonna explain it here as we are focusing on autonomous flying.
https://www.bitcraze.io/getting-started-with-flow-deck/
Start programmingMainly there are 2 ways to program the CF for an autonomous flying.
- Generate the navigation command on board
In this method we upload our code file to the CF memory and it generates navigation commands inside the microcontroller.
- Send commands from PC
Navigations commands are generated in PC and sent to the CF through the Crazy Radio module. The CF is capable of establish a 2 way communication to receive navigation commands and send log data to PC.
In this tutorial let's focus on the second method. I would suggest to use Ubuntu here onwards, as it's easy to configure the CF library.
CF platform comes with a Python library. In order to use that you need to install Python 3 on your PC. Run following commands on the terminal to install Python 3.
$ sudo apt-get update
$ sudo apt-get install python3.6
Then clone the following repository to your PC.
https://github.com/bitcraze/crazyflie-lib-python
The readme file contains the commands and instructions on configuring the radio module. Please follow them before proceeding to the next steps.
Let's run an example code to test the CF.
- Open the "basiclogSync.py" from crazyflie-lib-python > examples. Make sure to open the file using the IDLE.
- Plug the Radio module and Turn on the CF.
- Run the python script and wait until it connects to the CF.
- When the connecting completes, terminal will show the radio address. ( like 'radio://0/80/250K '). Copy the address.
- Open "flowsequenceSync.py" from the same directory and replace the variable URI to the address we copied at the previous step.
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
URI = 'radio://0/90/1M'
# Only output errors from the logging framework
logging.basicConfig(level=logging.ERROR)
- Keep the CF in an obstacle free area and run the script.
- CF will perform a Figure 8 flying like the following.
cf.commander.send_hover_setpoint(forward_velocity, side_velocity, yaw_rate, height)
This is the main code line which sends the control commands to the CF. Four variable values can be defined as shown in the above code. All variables can be either positive or negative except the height. If you set the forward velocity to -0.5, the CF will move backwards.
In "flowsequenceSync.py" code first for loop is used to take off the CF from the ground level.
for y in range(10):
cf.commander.send_hover_setpoint(0, 0, 0, y / 25)
time.sleep(0.1)
This code will increase the height gradually from 0 to 0.4 meters. Following loop is used to hover at a certain height, in this case at 0.4m.
for _ in range(20):
cf.commander.send_hover_setpoint(0, 0, 0, 0.4)
time.sleep(0.1)
You may change the number of iterations (currently 20) to change the time of hovering and also try to change the hovering height and see what will happen.
Following loop will do several tasks. It will command the CF to move forward while rotating the body.
for _ in range(50):
cf.commander.send_hover_setpoint(0.5, 0, 36 * 2, 0.4)
time.sleep(0.1)
As we don't need a side velocity in here it is set to 0. The very important thing is to keep the height as same as the previous command. If we set it to 0, the CF will land.
I would suggest you to try some random movements by changing these values and commands.
I will update the post with a guide on navigating the CF based on sensor inputs in near future. I hope you enjoyed this tutorial.
For further assistance you may contact Professional Electronic Designing Service Firms to support with your developments.
Cheers!
Comments