This example shows how to use the keyboard of the host computer to control the flying of a Parrot® minidrone using Simulink Support Package for Parrot Minidrones.
Note: This example requires you to additionally install the Robotics System Toolbox® from MathWorks.
If you are new to Simulink, complete the Create a Simple Model.
To setup and run Simulink model on a Parrot minidrone, follow the example described in Spin the Motors of a Parrot Minidrone without Flying the Drone.
To run this example, you must have the following hardware:
Parrot Rolling Spider Or Parrot Mambo minidrone with a fully charged battery and propellers connected to the motors
Micro USB type-B cable
Bluetooth Low energy (BLE) 4.0 support on the host computer
Simulink Support Package for Parrot Minidrones
Robotics System Toolbox
The support package includes an example project that starts the flight of the Parrot minidrone and follows a keyboard controlled path.
You can launch the example project by running the following command at the MATLAB command prompt: parrotMinidroneKeyboardControlStart
1. Open the example project by executing this command at the MATLAB command prompt.
2. Once the Simulink project is open, click the Project Shortcuts tab on the MATLAB window and click the type of drone you are using. For example, if you are using Parrot Mambo, click Set Mambo Model.
3. To simulate the model, go to the Simulation tab of the Simulink model window and click Run. The lower-left corner of the model window displays status while Simulink prepares to run the model on the host computer.
Observe that the drone in the Minidrone Flight Visualization 3D Simulator takes off and starts flying along a square path twice, and then stops.
Note: The command
parrotMinidroneKeyboardControlStart creates a new project everytime you run the command. The modifications (if any) that you made in the previous project will not appear in the new project.
In the parrotMinidroneKeyboardControlStart Simulink model, the keyboard and landing logic are modeled inside Flight Control System > Path Planning subsystem. Double-click the Path Planning subsystem to view the logic.
There are three subsystems inside the Path Planning subsystem:
Keyboard Control Logic
The Keyboard Control Logic subsystem is used in the parrotMinidroneKeyboardControlStart project for the following:
Define the set of keys on the keybaord for Parrot minidrone to follow, using [x y z Yaw] coordinates. In this project, we use eight keys to control the path of the drone. The keys are defined using a Constant block by entering the Constant value as follows:
X axis value represents the direction at which the drone navigates in
X axis and the value is determined by 'w' and 's' keys on the keyboard. Press the key 'w' to move the drone 0.1 meter forward along
X axis or press the key 's' to move the drone 0.1 meter backward along
Y axis value represents the direction at which the drone navigates in
Y axis and the value is determined by 'a' and 'd' keys on the keyboard. Press the key 'a' to move the drone 0.1 meter forward along
Y axis or press the key 'd' to move the drone 0.1 meter backwards along
Z axis value -1 represents the drone's take off height from the ground (1 meter). After the drone takes off, the value is determined by 'v' and 'b' keys on the keyboard. Press the key 'v' to move the drone 0.1 meter upwards or press the key 'b' to move the drone 0.1 meter downwards.
Yaw axis value represents the yaw motion(right or left) at which the drone navigates in
Yaw axis and the value is determined by 'g' and 'h' keys on the keyboard. Press the key 'g' to move the drone 0.1 meter towards right in yaw motion or press the key 'h' to move the drone 0.1 meter towards left in yaw motion.
The Landing Enable subsystem defines the logic required for enabling the landing. This subsystem is used in the parrotMinidroneKeyboardControlStart project for the following:
Set the landing flag by clicking the Land button on the Parrot interface.
Set the time remaining to enable landing. If the time remaining is set to less than or equal to 5 seconds, the drone starts landing.
The Landing Logic subsystem defines the logic required for landing the Parrot minidrone after it completes the navigation that was controlled using the keyboard on the host computer. This subsystem is used in the parrotMinidroneKeyboardControlStart project for the following:
Obtain the landing status from the Enable Subsystem subsystem, and initiate the landing logic
Define the landing step size that starts the descent of the drone along the
Z axis. In this example, the landing step size is 0.2 meters. If you increase the value of landing step size, the drone descents faster along the
Shutdown the drone's motors when it reaches 0.3 meters above the ground.
Flag Out signal in the Landing Logic subsystem is updated with the value
255 (errored out) when the drone shuts down.
1. In the Modeling tab of Simulink model window, click Model Settings to open the Configuration Parameters dialog box.
2. Go to the Hardware Implementation pane, and select the drone from the Hardware board list - either Parrot Mambo or Parrot Rolling Spider. Click Apply and then OK.
3. In the Hardware tab the Simulink model window, click Build, Deploy & Start. The lower-left corner of the model window displays status while Simulink prepares, downloads, and runs the model on the hardware.
After the model is successfully deployed, the Parrot minidrone takes off from the ground to a height of 1 meter. The drone shuts down the motors if it reaches a height of 0.3 meters from the ground.