Nothing Special   »   [go: up one dir, main page]

Parrot Ref

Download as pdf or txt
Download as pdf or txt
You are on page 1of 92

Simulink® Support Package for Parrot®

Minidrones
Reference

R2022b
How to Contact MathWorks

Latest news: www.mathworks.com

Sales and services: www.mathworks.com/sales_and_services

User community: www.mathworks.com/matlabcentral

Technical support: www.mathworks.com/support/contact_us

Phone: 508-647-7000

The MathWorks, Inc.


1 Apple Hill Drive
Natick, MA 01760-2098
Simulink® Support Package for Parrot® Minidrones Reference
© COPYRIGHT 2017–2022 by The MathWorks, Inc.
The software described in this document is furnished under a license agreement. The software may be used or copied
only under the terms of the license agreement. No part of this manual may be photocopied or reproduced in any form
without prior written consent from The MathWorks, Inc.
FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation by, for, or through
the federal government of the United States. By accepting delivery of the Program or Documentation, the government
hereby agrees that this software or documentation qualifies as commercial computer software or commercial computer
software documentation as such terms are used or defined in FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014.
Accordingly, the terms and conditions of this Agreement and only those rights specified in this Agreement, shall pertain
to and govern the use, modification, reproduction, release, performance, display, and disclosure of the Program and
Documentation by the federal government (or other entity acquiring for or through the federal government) and shall
supersede any conflicting contractual terms or conditions. If this License fails to meet the government's needs or is
inconsistent in any respect with federal procurement law, the government agrees to return the Program and
Documentation, unused, to The MathWorks, Inc.
Trademarks
MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See
www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand names may be
trademarks or registered trademarks of their respective holders.
Patents
MathWorks products are protected by one or more U.S. patents. Please see www.mathworks.com/patents for
more information.
Revision History
July 2017 Online only New for Version 17.1.0 (R2017a)
September 2017 Online only Revised for Version 17.2.0 (R2017b)
January 2018 Online only Revised for Version 17.2.2 (R2017b)
March 2018 Online only Revised for Version 18.1.0 (R2018a)
September 2018 Online only Revised for Version 18.2.0 (R2018b)
November 2018 Online only Revised for Version 18.2.1 (R2018b)
March 2019 Online only Revised for Version 19.1.0 (R2019a)
April 2019 Online only Revised for Version 19.1.1 (R2019a)
September 2019 Online only Revised for Version 19.2.0 (R2019b)
March 2020 Online only Revised for Version 20.1.0 (R2020a)
April 2020 Online only Revised for Version 20.1.1 (R2020a)
September 2020 Online only Revised for Version 20.2.0 (R2020b)
March 2021 Online only Revised for Version 21.1.0 (R2021a)
September 2021 Online only Revised for Version 21.2.0 (R2021b)
March 2022 Online only Revised for Version 22.1.0 (R2022a)
September 2022 Online only Revised for Version 22.2.0 (R2022b)
Contents

Coder Target Context Sensitive Help


1
Model Configuration Parameters for Parrot Minidrone . . . . . . . . . . . . . . . 1-2
Hardware Implementation Pane Overview . . . . . . . . . . . . . . . . . . . . . . . . 1-2
Build Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3
Clocking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3
External Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4

Build options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5


Build action . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5
Launch Parrot Flight Control Interface automatically after build . . . . . . . . 1-5
Enable profiling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5
Enable Take-off of drone if the surface is tilted . . . . . . . . . . . . . . . . . . . . . 1-6
Abort flight at high accelerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-6
Maximum acceleration of drone before safety abort . . . . . . . . . . . . . . . . . 1-6
Disable parallel build . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-6

Clocking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-8
CPU Clock (MHz) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-8

External Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9


Communication interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9
IP address . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9
Port . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9
Verbose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9

Blocks
2
Spin the Motors of a Parrot Minidrone without Flying the Drone . . . . . 2-19

Controlling Motor Speed of a Parrot Minidrone During Runtime Using


External Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-28

Communicating with a Parrot Minidrone Using TCP/IP and UDP . . . . . . 2-32

Getting Started with Image Processing Algorithms for Parrot Minidrones


......................................................... 2-38

Getting Started with Keyboard Control of Parrot Minidrones . . . . . . . . . 2-42

Fly a Parrot Minidrone and Detect Objects . . . . . . . . . . . . . . . . . . . . . . . . 2-48

iii
Follow Set of Waypoints or Follow Orbit Using Parrot Minidrone . . . . . . 2-53

Getting Started with Cannon Block for Parrot Minidrone . . . . . . . . . . . . 2-65

Getting Started with Grabber Block for Parrot Minidrone . . . . . . . . . . . 2-68

Path Planning Using Keyboard Control for Parrot Minidrone . . . . . . . . . 2-71

iv Contents
1

Coder Target Context Sensitive Help


1 Coder Target Context Sensitive Help

Model Configuration Parameters for Parrot Minidrone

In this section...
“Hardware Implementation Pane Overview” on page 1-2
“Build Options” on page 1-3
“Clocking” on page 1-3
“External Mode” on page 1-4

Hardware Implementation Pane Overview

Default Hardware Implementation Pane

Configure Parrot minidrone to run Simulink models.

1-2
Model Configuration Parameters for Parrot Minidrone

1 In the Simulink Editor, select Simulation > Model Configuration Parameters.


2 In the Configuration Parameter dialog box, click Hardware Implementation.
3 Set the Hardware board parameter to Parrot Rolling Spider or Parrot Mambo.
4 The parameter values under Hardware board settings are automatically populated to their
default values.

You can optionally adjust these parameters for your particular use case.
5 To apply the changes, click Apply.

For more information on selecting a hardware support package and general configuration settings,
see “Hardware Implementation Pane”.

Build Options
Parameter Description Default Value
“Build action” on page 1-5 Option to specify whether you Build, load, and run
want only the build, or the build,
load, and run actions during
code generation
“Launch Parrot Flight Control Determines whether the Flight on
Interface automatically after Control UI is automatically
build” on page 1-5 launched or not
“Enable profiling” on page 1- Determines whether profiling is off
5 enabled on the generated code
“Enable Take-off of drone if the Determines whether the drone on
surface is tilted” on page 1-6 can perform the take-off when
kept on a tilted surface
“Abort flight at high Determines whether the flight of off
accelerations” on page 1-6 the drone needs to be aborted at
high accelerations
“Maximum acceleration of Sets the maximum acceleration 60
drone before safety abort” on of the drone beyond which the
page 1-6 flight is aborted
“Disable parallel build” on page Option to compile the generated off
1-6 code on multiple cores of the
processor on the host computer

Clocking
Parameter Description Default Value
“CPU Clock (MHz)” on page 1- The CPU clock frequency in 416
8 MHz.

1-3
1 Coder Target Context Sensitive Help

External Mode
Parameter Description Default Value
“Communication interface” on Transport layer used to TCP/IP
page 1-9 exchange data between host
and hardware.
“IP address” on page 1-9 Sets the IP address of the drone For Parrot Rolling Spider –
to establish the connection. 192.168.3.5

For Parrot Mambo –


192.168.3.1
“Port” on page 1-9 Sets the port for transfer of data 17725
over TCP/IP for External mode
“Verbose” on page 1-9 View External mode execution on
progress and updates

1-4
Build options

Build options
Defines how Simulink Coder software responds when you press Ctrl+B to build your model.

Build action

Default: Build, load, and run

Build, load, and run


With this option, pressing Ctrl+B or clicking Build Model:

1 Generates code from the model.


2 Compiles and links the code into a shared object called librsedu.so.
3 Detects if a Parrot minidrone is connected over Bluetooth.
4 Loads the librsedu.so into the connected Parrot minidrone.
5 Runs the librsedu.so in the Parrot minidrone.

Build
With this option, pressing Ctrl+B or clicking Build Model:

1 Generates code from the model.


2 Compiles and links the code into a shared object called librsedu.so.

This option does not load and run the librsedu.so on the Parrot minidrone.

Launch Parrot Flight Control Interface automatically after build

This parameter is used to enable the automatic launch of the Parrot Flight Control Interface after the
build is successful. The Parrot Flight Control Interface can be used to:

• Change the power gain of motors on the drone


• Change the flight time
• Start and stop the motors
• Obtain the flight log and the MAT file

Settings

Default: on

Enable profiling

This parameter is used to enable profiling of the generated code after you run the Simulink model on
the target Parrot minidrone. Profiling helps you to evaluate the performance and also helps in
analyzing the function run-time in the code deployed on Parrot minidrone.

1-5
1 Coder Target Context Sensitive Help

Settings

Default: off

Enable Take-off of drone if the surface is tilted

This parameter is used to enable the take-off of the Parrot minidrone even if the drone is kept on a
tilted surface. Before initiating take-off of the drone on a tilted surface, ensure that you adhere to the
necessary safety precautions.

Settings

Default: on

Abort flight at high accelerations

This parameter is used to abort the flight of Parrot minidrone if high acceleration of the drone is
detected. Selecting this parameter helps to prevent unexpected behaviour of the drone during its
flight.

Settings

Default: off

Maximum acceleration of drone before safety abort

This parameter is used to set the maximum acceleration (in ㎨) that is allowed beyond which the
flight is aborted. This parameter is visible only if you select the option Abort flight at high
accelerations.

Settings

Default: 60 (maximum)

Disable parallel build

By default, the build process makes use of multiple cores on the processor of the host computer. This
reduces the compilation time.

In case of any build failures, the error messages may not be in order and hard to debug. In such
scenarios, you can disable this option using Hardware Implementation > Target Hardware
Resources > Build options > Disable parallel build.

• off - When you clear the selection, the support package compiles the generated code parallely.
Parallel execution reduces the time taken to build the model.
• on - When you select this option, the support package compiles the generated code in a sequential
order.

1-6
Build options

See Also
“Model Configuration Parameters for Parrot Minidrone” on page 1-2

1-7
1 Coder Target Context Sensitive Help

Clocking

CPU Clock (MHz)

This option is for the CPU clock frequency of the processor on the target hardware.

Note This parameter setting is disabled.

Settings

Default: 416

See Also
“Model Configuration Parameters for Parrot Minidrone” on page 1-2

1-8
External Mode

External Mode
External mode enables Simulink on the host computer to communicate with the deployed model on
the Parrot minidrone during runtime. This feature helps you to tune the parameters and perform real-
time monitoring of the model running on the drone.

Note Do not change any of the default settings for the External mode parameters.

Communication interface

Select the transport layer that the External mode uses to exchange data between the host computer
and the Parrot minidrone.

Settings

Default:TCP/IP

IP address

Set the IP address of the Parrot minidrone.

Settings

Default: For Parrot Rolling Spider – 192.168.3.5

Default: For Parrot Mambo – 192.168.3.1

Port

Set the value of the TCP/IP port number. External mode uses this port for communication between
the Parrot minidrone and host computer.

Settings

Default: 17725

Verbose
Select this check box to view the External mode execution progress and updates in the Diagnostic
Viewer or in the MATLAB® Command Window.

See Also
“Model Configuration Parameters for Parrot Minidrone” on page 1-2

1-9
2

Blocks
2 Blocks

TCP/IP Receive
Receive data over TCP/IP network from remote host
Library: Simulink Support Package for Parrot Minidrones

Description
The TCP/IP Receive block receives data from a remote host over a Bluetooth® network. When you set
Connection mode to Server, you must provide the Local IP port. The Local IP port acts as the
listening port of the TCP/IP server. When you set Connection mode to Client, you must provide the
Remote IP port of the server from which to receive the data.

The block has two output ports, Data and Status. At each sample time, the Data port outputs data as
a vector of the size specified in the Data size (N) parameter. The Status port contains 0 or 1 to
indicate whether the new data at the specified time step is received. The Status port value 1
indicates that the data from Data port is valid.

Parrot minidrone is a little-endian device. The TCP/IP Receive block expects the byte order of the
received TCP/IP data to be big-endian, and it converts the data to little-endian.

Note In some cases, the antivirus or firewall software might block the TCP traffic. If so, configure the
antivirus or firewall software to allow the traffic for a specific IP port number.

Input/Output Ports
Output

Data — Output data


[Nx1] array

At each time step, the port outputs data as a vector of the size specified in the Data size (N)
parameter.
Data Types: int8 | uint8 | int16 | uint16 | int32 | uint32 | single | double | Boolean

Status — Status of the data received


1|0

At each time step, when the length of data received is greater than or equal to the length specified in
the Data size (N) parameter, the port outputs 1. Otherwise, it outputs 0, indicating that no new data
is received.
Data Types: uint16

2-2
TCP/IP Receive

Parameters
Main Tab

Connection mode — Set block as server or client


Server (default) | Client

Set the block as TCP/IP server or client.

When you set this parameter to Server, you must provide a Local IP port. The local port acts as the
listening port of the TCP/IP server.

When you set this parameter to Client, you must provide the Remote IP port of the TCP/IP server
from which you want to receive the data.

Local IP port — IP port of receiving host from which data is received


25000 (default) | [1, 65535]

This local port number acts as a listening port of the receiving host. Match the local port number with
the remote port number of the sending host.

Remote IP address — Remote IP address of server from which data is received


192.168.3.2 (default)

The IP address of the server from which the data is received. The Remote IP address is set at
192.168.3.2; do not change this IP address.
Dependencies

This parameter appears only when you set the Connection mode parameter to Client.

Remote IP port — Remote IP port of server from which data is received


25000 (default) | [1, 65535]

Specify port number of the server from which data is received.

Note Do not use ports 24099 and 26061 for TCP/IP communication with Parrot minidrone as these
ports are reserved.

Dependencies

This parameter appears only when you set the Connection mode parameter to Client.

Data type — Data type of received data


uint8 (default) | double | single | int8 | int16 | uint16 | int32 | uint32 | boolean

Specify the type of data the block receives from the sending host. The size of each element depends
on its data type.

Data size (N) — Number of bytes in received data


1 (default) | any positive integer

The number of bytes to receive at each time step.

2-3
2 Blocks

Sample time — Interval at which block reads data from sending host
0.005 (default) | any non-negative value that is a multiple of 0.005 (5 ms) | -1

Enter the time interval at which to receive data.

When you set this parameter to -1, Simulink determines the best sample time for the block based on
the block context within the model.

Advanced Tab

Manually specify local IP port — Manually specify the number of the local IP port
off (default) | logical

Allow manual specification of local IP port at which to receive data. This parameter appears only
when you set the Connection mode to Client.

Local IP port — Local port at which to receive data


25000 (default) | scalar

Enter the local port of the client to receive data. This parameter appears only when you set the
Connection mode to Client and select the check box Manually specify local IP port.

Receive TCP Data

This section explains the values at the output ports in non-blocking mode, with the following block
parameters specified as:

Block Parameter Value


Data type uint8
Data size (N) 4

The values at the output ports vary depending on whether the length of data received is less than,
greater than, or equal to the length of requested data.

• Length of data received = Data size (N): The Data port outputs data as a vector of the size
specified in the Data size (N) parameter. The Status port outputs 1, indicating that the
requested data is received.

Suppose that the length of the data received is 4. In this case, the Data port outputs a data vector
of size 4 filled with the received data bytes. The Status port outputs 1.
• Length of data received < Data size (N): In non-blocking mode, the block does not wait for the
requested data to be available. The Data port outputs data as a vector of the size specified in the
Data size (N) parameter filled with zeros. The Status port outputs 0, indicating that no new data
is received.
• Length of data received > Data size (N): The Data port outputs a data vector of the size specified
in the Data size (N) parameter. The vector contains only the first N bytes from the data. The
remaining bytes are emitted along with the data bytes in the next time step. The Status port
outputs 1, indicating that the requested data is received.

Suppose that the length of data received is 5 bytes. In this case, the Data port outputs a data
vector of size 4. The vector contains only the first 4 bytes from the received data. The fifth byte is
emitted along with the data bytes in the next time step. The Status port outputs 1.

2-4
TCP/IP Receive

Data Mode of Read Output Port


Length Operation Data Status
Length of Non-blocking 1
data
received
= Data
size (N)
Length of Non-blocking 0
data
received
< Data
size (N)
Length of Non-blocking 1
data
received
> Data
size (N)

Version History
Introduced in R2018a

See Also
TCP/IP Send

2-5
2 Blocks

TCP/IP Send
Send data over TCP/IP network to remote host
Library: Simulink Support Package for Parrot Minidrones

Description
The TCP/IP Send block sends data to a remote host over a Bluetooth network. You can set the
Connection mode of the block to Server or Client. When you set Connection mode to Client,
you must provide the Remote IP port of the server to which you want to send data. When you set
Connection mode to Server, you must provide the Local IP port. This Local IP port acts as a
listening port of the TCP/IP server.

Input/Output Ports
Input

Port1 — Input port to accept data


[Nx1] array

The block accepts data specified as an N-by-1 array. The block sends this data over a TCP/IP network
to the receiving host.
Data Types: int8 | uint8 | int16 | uint16 | int32 | uint32 | single | double | Boolean

Parameters
Main Tab

Connection mode — Set block as server or client


Server (default) | Client

Set the block as a TCP/IP server or client.

When you set this parameter to Server, you must provide a Local IP port. The local port acts as the
listening port of the TCP/IP server.

When you set this parameter to Client, you must provide the Remote IP port of the TCP/IP server
to which you want to send the data.

Local IP port — Local port acting as the listening port of the server
25000 (default) | [1, 65535]

Enter the local port number which acts as the listening port of the TCP/IP server.
Dependencies

This parameter appears only when you set the Connection mode parameter to Server.

2-6
TCP/IP Send

Remote IP Address — Remote IP address of server to which to send data


192.168.3.2 (default)

The remote IP address of the server to which the data is sent. The Remote IP address is set at
192.168.3.2; do not change this IP address.
Dependencies

This parameter appears only when you set the Connection mode parameter to Client.

Remote IP port — Remote IP port of server to which data is sent


25000 (default) | [1, 65535]

Specify the port number of the server to which data is sent.

Note Do not use ports 24099 and 26061 for TCP/IP communication with Parrot minidrone as these
ports are reserved.

Dependencies

This parameter appears only when you set the Connection mode parameter to Client.

Advanced Tab

Manually specify local IP port — Manually specify the number of the local IP port
off (default) | logical

Allow manual specification of local IP port from which to send data. This parameter appears only
when you set the Connection mode to Client.

Local IP port — Local port from which to send the data


25000 (default) | scalar

Enter the local port of the client to send data. This parameter appears only when you set the
Connection mode to Client and select the check box Manually specify local IP port.

Version History
Introduced in R2018a

See Also
TCP/IP Receive

2-7
2 Blocks

UDP Receive
Receive UDP message from UDP host
Library: Simulink Support Package for Parrot Minidrones

Description
The UDP Receive block receives UDP message from a UDP host.

The block output, Data, emits UDP packet data as a one-dimensional vector of a specified data type.
The block output, Size, emits the size of the data in the UDP buffer. With each sample, the block
outputs the bytes of a UDP message as a data vector of the size specified by the Data size (N)
parameter.

The data type of the block output, Data, depends on the Data type parameter. The data type of the
block output, Size, is uint16. Size represents the total bytes. For example, if the Data Type is
double and the number of elements (mentioned using the Data size (N) parameter) is 5, then the
value of Size is 40, that is, 8*5 bytes.

The block receives the message on the port number specified in the Local IP port parameter. Match
the port number specified in the Local IP port parameter with the remote port number of the
sending host.

Parrot minidrone is a little-endian device. The UDP Receive block expects the byte order of the
received UDP data to be little-endian.

Note If you are having trouble using UDP to communicate with a computer, the antivirus or firewall
software might be blocking UDP traffic. If so, configure the software to allow the traffic for a specific
IP port number.

Input/Output Ports
Output

Data — Output UDP message received from sending UDP host


[Nx1] array

At each sample time, the port outputs the data bytes of a message received as a data vector of the
size specified by the Data size (N) parameter.
Data Types: int8 | uint8 | int16 | uint16 | int32 | uint32 | single | double | Boolean

Size — Number of data bytes in UDP message received


scalar

At each sample time, the port outputs the number of data bytes in the received message.

2-8
UDP Receive

Data Types: uint16

Parameters
Local IP port — IP port on the receiving UDP host
25000 (default) | [1, 65535]

Specify the port number of the application on which you want to receive messages. Match the local
port number with the remote port number of the sending host.

Note Do not use ports 24099 and 26061 for UDP communication with Parrot minidrone as these
ports are reserved.

Data type — Data type of the data bytes in UDP message


uint8 (default) | double | single | int8 | int16 | uint16 | int32 | uint32 | boolean

Select the data type of the bytes to be received from the sending host.

Data size (N) — Number of data bytes in each UDP message


4 (default)

Specify the number of data bytes that you want to receive in each message.

Sample time — Interval to read messages from sending UDP host


0.005 (default) | any non-negative value that is a multiple of 0.005 (5 ms) | -1

Enter the time interval at which to receive data.

When you set this parameter to -1, Simulink determines the best sample time for the block based on
the block context within the model.

Version History
Introduced in R2018a

See Also
UDP Send

2-9
2 Blocks

UDP Send
Send UDP message to UDP host
Library: Simulink Support Package for Parrot Minidrones

Description
The UDP Send block sends an input vector as UDP message over an IP network port to a UDP host.

Specify the IP address and the port number of the receiving host in the Remote IP address and
Remote IP Port parameter.

Input/Output Ports
Input

Port1 — Send UDP messages to another UDP host


vector

The port accepts an array and sends it as UDP messages over an IP network port to the receiving
host.
Data Types: int8 | uint8 | int16 | uint16 | int32 | uint32 | single | double | Boolean

Parameters
Remote IP address — IP address of receiving UDP host
192.168.3.2 (default)

Specify the IP address or the host name to which the block sends the UDP messages. The Remote IP
address is set at 192.168.3.2; do not change this IP address.

Remote IP Port — IP port on the receiving UDP host


25000 (default) | [1, 65535]

Specify the port number of the application on the receiving host to which you want to send the
messages. Match the remote port number with the local port number of the receiving host.

Note Do not use ports 24099 and 26061 for UDP communication with Parrot minidrone as these
ports are reserved.

Local IP Port — IP port on the sending UDP host


2048 (default) | [1, 65535]

2-10
UDP Send

This parameter appears if you select the Specify via dialog option for Local IP port source.
Specify the port number of the application from which you want to send the messages.

Version History
Introduced in R2018a

See Also
UDP Receive

2-11
2 Blocks

PARROT Image Conversion


Convert the encoded Y1UY2V image format to YUV or RGB format
Library: Simulink Support Package for Parrot Minidrones

Description
The PARROT Image Conversion block converts an image that is encoded in Y1UY2V format, as
obtained from the Parrot minidrone's downward-facing camera, to either YUV or RGB format. The
block separates the color components and provides them as the output.

Input/Output Ports
Input

Port_1 — Image in Y1UY2V format


4x9600 array

The input image is obtained from the downward-facing camera of Parrot minidrone, and it is
represented as a 4-by-9600 array. This input is encoded in the Y1UY2V format.
Data Types: uint8

Output

Y — Luminance of image when converted to YUV format


120x160 array
Data Types: uint8

U — U chrominance of image when converted to YUV format


120x160 array
Data Types: uint8

V — V chrominance of image when converted to YUV format


120x160 array
Data Types: uint8

R — Red color in image when converted to RGB format


120x160 array
Data Types: uint8

G — Green color in image when converted to RGB format


120x160 array
Data Types: uint8

2-12
PARROT Image Conversion

B — Blue color in image when converted to RGB format


120x160 array
Data Types: uint8

Parameters
Output color space — Select color space for conversion
YUV (default) | RGB

Select the color space, either YUV or RGB, for converting the image from the encoded Y1UY2V
format.

When you set this parameter to YUV, the Y, U, and V components are available as separate output
ports.

When you set this parameter to RGB, the R, G, and B components are available as separate output
ports.

Version History
Introduced in R2018b

See Also
“Code Generation Simulink Template for Image Processing for Parrot Minidrone”

2-13
2 Blocks

Keyboard Read
Receive key presses from keyboard of host computer and output ASCII code
Library: Simulink Support Package for Parrot Minidrones

Description
The Keyboard Read block receives the key presses for any basic character on the keyboard of the
host computer, and outputs the corresponding ASCII code of the character.

This block can be used in a Simulink model created using Simulink Support Package for Parrot
Minidrones, to perform real-time flight control of Parrot minidrone using the keyboard keys.

Note Only one Keyboard Read block is allowed in the entire Simulink model. Any number of
connections can be derived from the output signal of this block.

In the Simulink model, you can connect multiple Compare to Constant blocks to the output of the
Keyboard Read block to map the different ASCII codes.

After the Simulink model has started running on the drone, you can use the Keyboard Control
Panel on the Flight Control Interface to type the basic characters that you have mapped to the
control logic.

Input/Output Ports
Output

Port_1 — ASCII code of the basic character pressed on the keyboard


ASCII

The supported basic characters include all printable characters – letters, numbers, punctuation
marks, and common symbols present on the keyboard.
Data Types: uint8

Parameters
Sample time — Interval at which block reads data
0.005 (default) | any non-negative value that is a multiple of 0.005 (5 ms) | -1

Enter the time interval at which to receive data.

When you set this parameter to -1, Simulink determines the best sample time for the block based on
the block context within the model.

2-14
Keyboard Read

Version History
Introduced in R2019a

See Also
“Code Generation Simulink Template for Image Processing for Parrot Minidrone”

2-15
2 Blocks

Grabber
Control the Grabber module connected to a Parrot Mambo minidrone
Library: Simulink Support Package for Parrot Minidrones

Description
The Grabber block controls the Grabber module that is connected to a Parrot Mambo minidrone.

Input/Output Ports
Input

Port_1 — Input signal to control the Grabber module


1|0

The grabber closes (to grab the object) if the input is 1, and it opens (to place the object in position) if
the input is 0.

Note The change of value of the input signal (0 to 1 or 1 to 0 results in an immediate action by the
Grabber. For example, the grabber closes immediately if the input signal becomes 1 even though an
opening action is in progress due to a previous input signal of value 0.

Data Types: Boolean

Output

Port_1 — Current state of the grabber module


0 | 1 | -1

The block outputs one of these three values that correspond to the current state of the Grabber
module:

• 1 – Grabber is closed
• 0 – Grabber is opened
• -1 – Grabber is not connected to the drone or it is not working

Data Types: uint8

Version History
Introduced in R2019b

2-16
Grabber

See Also

2-17
2 Blocks

Cannon
Control the Cannon module connected to a Parrot Mambo minidrone
Library: Simulink Support Package for Parrot Minidrones

Description
The Cannon block controls the Cannon module that is connected to a Parrot Mambo minidrone.

Input/Output Ports
Input

Port_1 — Input signal to control the Cannon module


1|0

The Cannon module fires one ball whenever the input changes from 0 to 1.

If there are multiple input commands to the Cannon block (to fire the balls in succession), the
commands are queued and they are executed one after the other.

Tip You can also use multiple Cannon blocks in the same Simulink model (instead of queuing the
commands in one Cannon block) to fire the balls in succession.

Data Types: Boolean

Output

Port_1 — Number of firing commands pending in the queue


scalar integer | -1

The number of firing commands that are pending in the queue while the Cannon module is busy.

An output value of -1 indicates that the Cannon module is not connected to the drone, or the Cannon
module is not working.
Data Types: uint8

Version History
Introduced in R2019b

See Also

2-18
Spin the Motors of a Parrot Minidrone without Flying the Drone

Spin the Motors of a Parrot Minidrone without Flying the Drone

This example shows you how to use Simulink Support Package for Parrot® Minidrones to run a
Simulink® model that spins the propellers connected to motors of a Parrot minidrone, without flying
the drone.

Introduction

Simulink Support Package for Parrot Minidrones enables you to create and run Simulink models on
Parrot Rolling Spider and Parrot Mambo minidrones. The support package lets you design and
simulate estimation and control algorithms for a minidrone in MATLAB and Simulink, and auto-
generates embedded c-code that you can use to actually fly the minidrone. After the flight, recorded
data can be visualized and analyzed.

In this example, you will learn how to configure a simple Simulink model to generate code for a
Parrot Rolling Spider and Parrot Mambo minidrone and run the generated code on the board. Using
this example, you will spin the propellers connected to motors 1 and 3 for 2 seconds, and then spin
the motors connected to motors 2 and 4 for 2 seconds, and so on till 20 seconds.

Prerequisites

• If you are new to Simulink, we recommend completing the Interactive Simulink Tutorial.

Required Hardware

To run this example you will need the following hardware:

• Parrot Rolling Spider Or Parrot Mambo minidrone with fully charged battery and propellers.
• Micro USB type-B cable
• Bluetooth Low Energy (BLE) 4.0 support

Task 1 - Connect a Parrot minidrone to host machine

In this task, you will connect a Parrot Rolling Spider/Parrot Mambo minidrone to host machine.

1. Check if the Parrot minidrone is connected via Bluetooth to the host machine by pinging the drone.
To check whether Parrot Rolling Spider is connected or not, use the below command for ping.

ping 192.168.3.5

To check whether Parrot Mambo is connected or not, use the below command for ping.

ping 192.168.3.1

If the ping is successful, continue to Task 2.

2. On the MATLAB Home tab, click Add-Ons -> Manage Add-Ons.

3. Click the gear button as shown in the below figure.

2-19
2 Blocks

4. Follow the instructions on the screen that appears, and ensure that the Rolling Spider/Mambo
minidrone is connected via Bluetooth with the host machine. You can refer to the Setup and
Configuration document if you face any issues while connecting the drone to the host machine.

Task 2 - Model the algorithm to spin the propellers

This task shows how to use the input and output ports to model an algorithm to spin the motors.

1. Open the Getting started with Parrot minidrone model.

open_system('parrot_gettingstarted');

2-20
Spin the Motors of a Parrot Minidrone without Flying the Drone

2. Notice the following points in the model:

• There are 2 input ports in the model. The AC cmd input port gives a bus signal which mainly
consists of 'position reference' and 'orientation reference' values along with other signals.

• The Sensors input port contains data from sensors like accelerometer, gyroscope, ultrasonic,
pressure, and optical flow data.

• There are two output ports in the model. The Motors output port expects a vector of 4 single
values.

• The Flag output port expects a uint8 scalar value. Model an error condition and feed the value to
the Flag output port. A non-zero value for this port indicates an error condition, and stops the
drone flight. The non-zero value fed to the Flag outport is captured in the flight log generated
after the flight.

2-21
2 Blocks

3. The Flight Control System subsystem models the logic of spinning of motors. Double click
and open the Flight Control System subsystem.

4. The logic used to spin alternate motors for 2 seconds each is mentioned below:

2-22
Spin the Motors of a Parrot Minidrone without Flying the Drone

• Two Pulse Generator source blocks with phase shift are used to spin alternate motors for 2
seconds each.

• The input port values are not used in this model and hence are terminated by connecting the input
port signals to the Terminator sink block.

Task 3 - Run the generated code on the Parrot minidrone using the Flight Control Interface

This task shows how to spin the motors of the Parrot minidrone using the above model.

1. In your parrot_gettingstarted model, click Build Model on the toolbar. The model is loaded to
the drone. After the build goes through successfully, a shared object is running on the drone, waiting
for a connection from the PC.

2. If you have selected the Launch Parrot Flight Control Interface automatically after build
option in the Configuration Parameters dialog box (Hardware Implementation pane > Target
Hardware Resources > Build Options), the Parrot Flight Control UI opens automatically after the
build goes through successfully. It can also be launched by clicking at the link displayed in the
Diagnostic Viewer after model build is successful.

You can also launch the interface by executing Parrot_FlightInterface(Parrot_FlightInterface)


at the MATLAB command window.

2-23
2 Blocks

To know more about Parrot Flight Interface go to this section.

3. Set the power gain of the motors with the help of the slider. The power gain of the motors can be
set to a percentage value from 0 to 100. It is recommended to set the power gain to a lower value
first to test. The default powergain is 10%.

4. You can use the Simulation Stop Time for your model as the duration of flight for your minidrone. If
you wish to specify your own flight time, clear the checkbox and then set the flight time.

5. Click START . It might take a few minutes after which the motors start spinning. Observe that the
two clockwise motors spin for 2s, and then the two counter-clockwise motors spin for 2s, and so on.

2-24
Spin the Motors of a Parrot Minidrone without Flying the Drone

You can also observe that the Parrot Flight Control Interface is changed after you click START, and it
displays STOP button.

The STOP button can be used for emergency shutdown of the drone's motors, if required.

7. When the flight time (as defined in Step 4 above) is over or the motors have stopped spinning, the
Parrot Flight Control Interface changes the display back to show the START button. Click Flight Log
to obtain the flight log. A text file titled droneFlight.txt is downloaded to your current MATLAB
directory.

8. You can change the power gain and flight time and start the drone flight again for the updated
values by clicking START.

2-25
2 Blocks

9. If you have Simulink Coder License, you can also download the MAT-File for the signals logged in
the model. Enable MAT-File logging for your model and click Build Model to download the generated
code on the minidrone. Click START to spin the motors. After the flight time is over, click MAT File
to download the MAT-File on your current MATLAB directory.

Task 4 - Use Simulink templates for Parrot Minidrone

In this Task, you will learn how to use the Simulink templates for Parrot Minidrones. Two templates
are provided for the Simulink Support Package for Parrot Minidrones, namely, Code
Generation template and Flight Simulation template.

1. Open the Simulink Start page.

2. From the Simulink Support Package for Parrot Minidrones templates, create a new Simulink
model using Code Generation template.

The template is categorized into three main regions, namely, input, algorithm and output section.

3. Use the input ports Sensors and AC cmd, output ports Motors and Flag as mentioned in Task 2
above.

4. Open the 'Flight Control System' subsystem in your new model, and model your own controller
logic by using the sensor values from the 'SensorBus' and output a vector of single values to the
Motors output port.

2-26
Spin the Motors of a Parrot Minidrone without Flying the Drone

5. From the Simulink Support Package for Parrot Minidrones templates, create a new Simulink
project using Flight Simulation template.

6. Use the new project to design your own controller in the 'Flight Control System' subsystem,
simulate the 'slQuadcopter' to see your controller in action. To build and load the controller that you
have designed on to the drone, click the Generate Flight Code shortcut in the Project Shortcuts tab.

Other Things to try with Simulink Support Package for Parrot Minidrones

For Example:

1. Create and run a model that spins the motors 1 and 2, when the drone is tilted in forward
direction, and spins the motors 3 and 4, when the drone is tilted in backward direction. Hint: Use the
accelerometer data from the input port Sensors to determine the tilt angle.

2. Create and run a model that has the following characteristics.

• Spin all the 4 motors

• Model the logic in such a way that the model stops executing after 10 seconds. Hint: Use the
'live_time_ticks' signal from the AC cmd to keep track of time.

• Stop running the model if the drone is tilted by more than in any direction. Hint: Use the
accelerometer data from the input port Sensors to determine the tilt angle.

3. Fly the drone using the Simulink template as mentioned in this section.

4. Create a new project using the Flight Simulation Template from the Parrot template library,
which is on similar lines as of the above demo. Create your own controller in the framework provided
in the newly created project, simulate and fly the drone.

2-27
2 Blocks

Controlling Motor Speed of a Parrot Minidrone During Runtime


Using External Mode

This example shows you how to use the External mode feature in Simulink® for speed control of
motors on a Parrot® minidrone during runtime.

Introduction

Simulink's External mode feature enables parameter tuning while the model is running on target
hardware, without stopping the model. When you change parameter values from within Simulink, the
modified parameter values are communicated to the target hardware. The effects of the parameters
tuning activity can be monitored by viewing the signals on Scopes or Displays in Simulink.

In this example, you will learn how to configure a Simulink model to run a simulation in External
mode on Parrot minidrone, and control the speed of motors during runtime.

Prerequisites

Complete “Spin the Motors of a Parrot Minidrone without Flying the Drone” on page 2-19.

Required Hardware

To run this example, you will need the following hardware:

• Parrot Rolling Spider Or Parrot Mambo minidrone with fully charged battery and propellers
• Micro USB type-B cable
• Bluetooth Low energy (BLE) 4.0 support

Task 1 - View the Model and Set Up the External Mode

In this task, you will open the Simulink model and set up the External mode feature.

1. Connect the Parrot Minidrone to your computer as mentioned in “Spin the Motors of a Parrot
Minidrone without Flying the Drone” on page 2-19. You can refer to the Setup and Configuration
document if you face any issues while connecting the minidrone over Bluetooth to the host machine.

2. Open the External mode model.

open_system('parrot_external_mode');

2-28
Controlling Motor Speed of a Parrot Minidrone During Runtime Using External Mode

This model has already been configured for the Parrot Rolling Spider target. To learn how to setup
a model for Parrot Minidrone, refer to “Spin the Motors of a Parrot Minidrone without Flying the
Drone” on page 2-19.

3. Go to Hardware tab and select Monitor & Tune to start the External mode.

After the model build goes through successfully, the model waits for the start command from MATLAB
to start executing the code on the drone. It can be seen that the time in the Simulink model is frozen
at 0s as shown in the below figure.

2-29
2 Blocks

Task 2 - Start the Drone and Control the Speed of Motors

In this task, you can start the Parrot minidrone motors in External mode, change the parameter
values in the Simulink, and view the change in speed of the motors in real-time.

1. Open the Parrot Flight Control Interface:

• If you have selected the Launch Parrot Flight Control Interface automatically after build
option in the Configuration Parameters dialog box (Hardware Implementation pane > Target
Hardware Resources > Build Options), the Parrot Flight Control UI opens automatically after
the build goes through successfully.

• You can also open the Parrot Flight Control Interface from the command line

>> Parrot_FlightInterface

To know more about Parrot Flight Interface go to this section.

2. In the Parrot Flight Control Interface, set the Power Gain and Flight Time as required.

3. Click START.

Once the Start command is received, the motors start spinning, and the Simulink model starts
running in External mode. It can be seen that the time starts running on the Simulink model.

4. Open the Flight Control System subsystem.

5. The Accel2Motor subsystem takes the accelerometer values and spins a particular combination
of motors based on the orientation of the drone. For example, all the four motors spin when the drone
is kept on a flat surface.

Try tilting the drone vertically to its right by . You can observe that only the 1st motor spins in this
case.

6. While the model is running in External mode, view the accelerometer signals by opening the
Scope.

7. Vary the motor speed using the slider and notice the change in speed of the motors.

8. Click STOP in Flight Control Interface in order to stop the External mode simulation.

2-30
Controlling Motor Speed of a Parrot Minidrone During Runtime Using External Mode

Stopping the External mode simulation terminates the code running on the Parrot Minidrone. Before
you can start another External mode simulation, you need to run the generated code again by clicking
the Run icon on the toolbar of the Simulink window.

2-31
2 Blocks

Communicating with a Parrot Minidrone Using TCP/IP and UDP

This example shows how to use the TCP/IP and UDP communication blocks in the Simulink® Support
Package for Parrot® Minidrones. The blocks are used to control the motor speed of the drone and
visualize the accelerometer sensor data from the drone.

Introduction

The Simulink Support Package for Parrot Minidrones provides a library with TCP/IP and UDP
communication blocks, which enable you to establish TCP/IP and UDP connections between the
Parrot minidrone and the host computer.

To view the TCP/IP and UDP communication blocks:

1. Enter slLibraryBrowser at the MATLAB® prompt.

2. In the Simulink Library Browser, navigate to Simulink Support Package for Parrot
Minidrones. You can see the TCP/IP Send and Receive blocks and the UDP Send and Receive blocks.

open_system('parrotlib');

In this example, you will learn how to use the TCP/IP and UDP blocks to:

• Control the speed of propellers connected to the motors on the Parrot minidrone using TCP/IP
connection

2-32
Communicating with a Parrot Minidrone Using TCP/IP and UDP

• Send accelerometer sensor data from the drone to the host computer using UDP connection
• Use the Scope in the host model to visualize the variation of acceleration.

The Simulink models used in this example are:

• Target Communication Model(parrot_communication) - This model is run on the Parrot Minidrone.


• Host Communication Model(parrot_communication_host) - This model is run on the host computer.

Prerequisites

• If you are new to Simulink, complete the Interactive Simulink Tutorial.

• 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” on page 2-19.

Required Hardware

To run this example, you will need 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

Task 1 - Configure and Deploy the Simulink Model on Parrot Minidrone

This task shows how to configure the input and output ports of TCP/IP and UDP blocks in a Simulink
model and then deploy the model on the Parrot minidrone.

1. Open the Target Communication Model(parrot_communication) from the MATLAB command


prompt.

open_system('parrot_communication');

2-33
2 Blocks

2. Open the "Flight_Control_System" subsystem. The output port Data of the TCP/IP Receive block is
connected to input ports 1 and 3 of the Concatenate block. The Concatenate input ports correspond
to the RPM values assigned to the motors.

3. Double click on the TCP/IP Receive block. The Local IP port value is set to 25000, which
matches the remote port on the TCP Send block in the Host Communication
Model(parrot_communication_host). The Data type is set to double and Data size is set to 1.
Ensure that the Data type and Data size parameters in the host model are set to the same values as
the parameters in the target model.

The Connection mode of TCP/IP Receive block can be Server or Client. For this model, the
Connection mode is set to Server. This is because, in the host Simulink model, we are using a TCP
Send block to serve as a client. Click OK to save and close the block.

4. Double-click on the UDP Send block. The Remote IP address is the IP address of the Bluetooth
interface on the host computer. Use the default address, 192.168.3.2. The Remote IP port
parameter is set to 29000 to match the local port in the UDP Receive block in the host Simulink
model. Click OK to save and close the block.

5. On the toolbar of the Simulink model window, click the Deploy to Hardware icon.

6. If you have selected the Launch Parrot Flight Control Interface automatically after build
option in the Configuration Parameters dialog box (Hardware Implementation pane > Target
Hardware Resources > Build Options), the Parrot Flight Control UI opens automatically after the
build goes through successfully.

2-34
Communicating with a Parrot Minidrone Using TCP/IP and UDP

You can also open the Parrot Flight Control Interface from the command line

>> Parrot_FlightInterface

To know more about Parrot Flight Interface, go to this section.

Task 2 - Run Communication Model on the Host Computer

In this task, you will configure and run a Simulink model on the host computer to communicate with
the target model deployed on the drone.

The host Simulink model performs the following functions:

• Starts motors 1 and 3 on the drone


• Sends varying motor speed inputs using a Knob block to the target model running on the drone
• Receives the sensor data sent by the target model

Note: The host Simulink model uses TCP/IP blocks and UDP blocks from the Instrument Control
Toolbox in the Simulink Library Browser. The model uses TCP/IP to send the commands that starts
the motors and changes the speed of motors, and uses UDP to receive the data from the
accelerometer sensor on the drone.

1. Open the Host Communication Model(parrot_communication_host) from the MATLAB command


prompt.

open_system('parrot_communication_host');

2-35
2 Blocks

2. Double-click on the UDP Receive block. This block is configured to receive UDP packets sent by
the model running on the Parrot minidrone. The Local port is set to 29000, and the output Data
type is set to single to match the sensor value type. Click OK to save and close the block.

3. Double-click on the TCP/IP Send block. This block is configured to transmit the packets on port
25000 to 192.168.3.5, which is the IP address of the Parrot Rolling Spider minidrone. If you are
using a Parrot Mambo minidrone, change the address to 192.168.3.1. Click OK to save and close
the block.

4. On the Flight Control Interface (launched in Task 2), click START. The deployed target model on
the drone starts sending UDP packets to port 29000 of the host computer. The drone is also prepared
to receive TCP/IP data at port 25000.

You can relaunch the interface by executing Parrot_FlightInterface at the MATLAB command
window.

5. On the toolbar of the host model Simulink window, click the Run icon to simulate the model. You
will observe propellers connected to motors 1 and 3 begin to spin.

6. Change the knob position in the host model to control the speed of the motors. Notice the change
in speed of the propellers after some delay.

NOTE :

2-36
Communicating with a Parrot Minidrone Using TCP/IP and UDP

The Simulink model on the host does not run in real time. Hence, we might notice some delay in the
speed change of the propellers. You can use Set Pace block from Aerospace Blockset/Animation
Support Utilities or real-time block from this MATLAB File Exchange page.

7. Double-click on the Scope block in the host model to see the variation in acceleration sensed by
the Parrot Minidrone in the Z direction (the Z value is positive in the downward direction). Change
the position of the drone from the ground level (raise or lower the drone). Double-click on the Scope
block to observe the change in the sensor value.

Other Things to Try with TCP/IP and UDP Blocks in Simulink Support Package for Parrot
Minidrones

Create and run a model that increases the motor speed when the drone is tilted forward, and reduces
the motor speed when the drone is tilted backward. Tip: Use the accelerometer data from the input
port Sensors to determine the tilt angle.

2-37
2 Blocks

Getting Started with Image Processing Algorithms for Parrot


Minidrones

This example shows you how to create a Simulink® model that uses the images from a Parrot
minidrone's downward-facing camera to develop a simple image-processing algorithm to be deployed
on Parrot minidrone.

Introduction

The Parrot minidrones are equipped with a downward-facing camera that provides images measuring
120-by-160 pixels. The image is internally used by the drone to calculate the optical flow of the drone.
The image data is also available to the user to develop vision-based algorithms.

The Simulink Support Package for Parrot Minidrones provides a Simulink template that contains an
inport that obtains the images captured by the drone's camera. You can use this template to develop
image-processing algorithms. The output of the image-processing algorithm can be used as an
additional input to control the flight of the drone.

The image data obtained from the downward-facing camera is a 4-by-9600 array of type uint8, in
Y1UY2V format. This is an encoded format of the standard YUV color space. The template also
contains the Parrot Image Conversion block, which converts the image from Y1UY2V format to YUV
or RGB format.

The block can also be found in the Simulink library. To access the Parrot Image Conversion block from
the Simulink Library Browser:

1. Enter slLibraryBrowser at the MATLAB prompt.

2. In the Simulink Library Browser, navigate to Simulink Support Package for Parrot
Minidrones.

2-38
Getting Started with Image Processing Algorithms for Parrot Minidrones

In this example, you will learn how to use the Code Generation Template For Image Processing
and Control to:

• Obtain an image from the downward-facing camera and convert it using the Parrot Image
Conversion block
• Perform analysis of converted image to detect any red object in the image
• Run one of the motors of the drone if a red object is detected

Prerequisites

• If you are new to Simulink, complete the Interactive Simulink Tutorial.


• To setup and run a Simulink model on a Parrot minidrone, follow the example described in Getting
Started with Simulink Support Package for Parrot Minidrones.
• Download and install the Computer Vision Toolbox. This requires a separate license.

Required Hardware

To run this example, you will need the following hardware:

• Parrot Rolling Spider or Parrot Mambo with a fully charged battery and propellers connected to
the motors.
• Bluetooth Low Energy (BLE) 4.0 support on the host computer

2-39
2 Blocks

Task 1 - Develop the Image Processing Algorithm to Detect a Red Colored Object

This task shows how to develop an image processing algorithm to detect a red colored object using
the image from the downward-facing camera of Parrot minidrone. This task uses blocks from
Computer Vision System Toolbox.

1. On the Simulink Start page, navigate to Simulink Support Package for Parrot Minidrones and
select Code Generation Template For Image Processing and Control.

2. Double-click and open the Image Processing System subsystem. You can find the Image Data inport
which obtains the image from the camera. This inport is connected as input to the Parrot Image
Conversion block. The outputs from the block are Y, U, and V, by default.

3. Open the Parrot Image Conversion block mask and change Output color space from YUV to RGB,
and select all the three channels for output (R, G, and B).

4. Add logic to binarize the image using a threshold. This logic should check the pixels in the image
and find the pixels that have red as the dominant color.

To do this, check if the red component is greater than half-the-value of green and blue by at least 100,
that is, Output = R - (G/2) - (B/2), which should be more than 100. If it is, then output a value of 1, for
the particular pixel input. Otherwise, output zero.

You also need to add all the output 1's and compare it with a constant to ensure that more pixels are
considered.

This logic could be implemented in Simulink like this:

a) Add a Product block to divide the green and blue outputs from the Parrot Image Conversion block,
by half (divide by 2).

b) Use a Sum block at the output of the Product block to calculate the dominance of red color
component among the three components, and then compare the output value with a threshold value
of 100 (using a GreaterThan block).

c) Use another Sum block and a Compare to Constant block (with 50 as the Constant value) to
consider more number of pixels (binarized images).

5. Use the output from the Compare to Constant block as the input to a Switch block. The Switch
block can be used to pass a Motor Run value of 200 when the output of Compare to Constant block
is more than 50, or a Motor stop value of 0 if it is less.

6. Connect the Switch block to the Vision-based Data outport.

Task 2 - Use the Vision-based Data to Control the Speed of a Motor

In this task, use the output from the Image Processing System in the Flight Control System
subsystem as input data. Use the data to control a motor on the drone.

1. The Flight Control System subsystem contains a Motors outport, which expects four input values
that correspond to the speed of the four motors. A mux block (Vector Concatenate block) is already
connected to this output port in the template. Connect the Vision-based Data inport as the second
input of the mux block, and connect a Constant block with value 200 as the first input. Connect two
Constant blocks with value 0 to the other two inputs of the mux block.

2. On the toolbar of the Simulink model window, click the Deploy to Hardware icon.

2-40
Getting Started with Image Processing Algorithms for Parrot Minidrones

If you have selected the Launch Parrot Flight Control Interface automatically after build
option in the Configuration Parameters dialog box (Hardware Implementation pane > Target
Hardware Resources > Build Options), the Parrot Flight Control Interface opens automatically
after the build goes through successfully.

3. On the Parrot Flight Control Interface, click Start. The deployed model is now ready to analyze
images obtained from the downward-facing camera of the drone, and the first motor starts running.

4. Hold the Parrot minidrone over a red object in such a way that the downward-facing camera of the
drone faces the object. Check if the second motor runs.

A ready to run model(parrot_vision) with an image-processing algorithm is provided for your


reference. This model contains the blocks and connections as explained in Task 1 and Task 2.

Other Things to Try with a Parrot Image Processing Algorithm

The red color detection from the image (as described in this example) is dependent on the lighting
conditions and the threshold chosen. You may need to tune your model to adapt to the chosen
environment. The External mode can be used to tune the image-processing algorithm or to check the
intermediate outputs:

1. In the Simulink model, change the Simulation mode to External.

2. Open the Image Processing System subsystem and add a Video Viewer block from the Computer
Vision System Toolbox. Connect the outputs of the Parrot Image Conversion block to the Video Viewer
block.

The Video Viewer block has a single input by default. To use separate channels, double-click on the
block, go to File, and select Separate Color Signals. Connect the R, G, and B outputs of Parrot
Image Conversion block to the Video Viewer block.

3. Click the Run icon on the Simulink toolbar to start the External mode.

4. When the Parrot Flight Control Interface appears, click Start.

The images that are being captured by the drone can be seen on the Video Viewer block. The update
rate is slow because the images are being sent over BLE.

To check the binarized image in the model, disconnect the Video Viewer block and connect it to the
output of the logic used for binarization, and run the model in External mode.

A ready to run model(parrot_vision_ext_mode) with a Video Viewer block and the External mode
enabled is provided for your reference.

2-41
2 Blocks

Getting Started with Keyboard Control of Parrot Minidrones

This example shows you how to create a Simulink® model that uses the keyboard of the host
computer to control the motors of a Parrot minidrone.

Introduction

The Simulink Support Package for Parrot Minidrones provides a Keyboard Read block that reads the
keys pressed on the keyboard of the host computer, when the Simulink model is running on the
drone. The output of this Keyboard Read block is the corresponding ASCII code of the character
pressed, which you can use to trigger any control logic.

The Keyboard Read block can be found in the Simulink library. To access the block from Simulink
Library Browser:

1. Enter slLibraryBrowser at the MATLAB prompt.

2. In the Simulink Library Browser, navigate to Simulink Support Package for Parrot
Minidrones.

open_system('parrotlib');

In this example, you will learn how to use the Keyboard Read block in the Code Generation
Template to set the speed of one of the motors on Parrot minidrone, using two different keys on the
keyboard.

2-42
Getting Started with Keyboard Control of Parrot Minidrones

Prerequisites

• If you are new to Simulink, complete the Interactive Simulink Tutorial.


• 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” on page 2-19.

Required Hardware

To run this example, you will need the following hardware:

• Parrot Rolling Spider or Parrot Mambo with a fully charged battery, and propellers connected to
the motors.
• Bluetooth Low Energy (BLE) 4.0 support on the host computer

Task 1 - Add a Keyboard Read block and model the logic to detect the received characters

1. On the Simulink Start page, navigate to Simulink Support Package for Parrot Minidrones and
select Code Generation Template.

2. In the Simulink model, navigate into the Flight Control System, and insert the Keyboard Read
block from the library.

3. Add two Compare to Constant blocks in the model, and connect the output of Keyboard Read
block to the inputs of the two Compare to Constant blocks.

In this example, we assume that the character 'a' on the keyboard will be used to start a motor, and
the character 's' will be used to stop the motor. You can use one of the Compare to Constant blocks to
compare the received character with the ASCII code of 'a' (which is 97), and use the other block to
compare the received character with the ASCII code of 's' (which is 115).

4. Double-click the Compare to Constant blocks, set the Operator value to ==, and Constant value
to 97 and 115 respectively.

Task 2 - Add additional logic for controlling the motor

In this task, you will perform the following:

• Use the output from the Compare to Constant block mapped to 'a' to run Motor 1 of Parrot
minidrone
• Use the output from the Compare to Constant block mapped to 's' to stop Motor 1 of Parrot
minidrone.

1. Insert an Add block, and combine the two outputs (from the two Compare to Constant blocks)
using the Add block.

2. Insert a Switch block, and connect the output of the Add block to Input 2 of the Switch block.

3. Add a Gain block with value 400, and connect it to the output of Compare to Constant block
configured for character 'a'. Connect the output of the Gain block to Input 1 of the Switch block.

4. For the Input 3 of the Switch block, we will a delay feedback that is derived from the output of the
Switch block. Insert a delay block and connect it to Input 3.

5. Connect the output of Switch block to Motor 1.

2-43
2 Blocks

6. Add a Constant block with value 200 and connect it to other motors.

The completed logic will look like this:

A pre-configured model(parrot_keyboard_control) is also included for your convenience. Double-click


the Flight Control System subsystem in this model to view the control logic.

open_system('parrot_keyboard_control');

2-44
Getting Started with Keyboard Control of Parrot Minidrones

Task 3 - Deploy the model and use the keyboard to control the drone

In this task, you will deploy the Simulink model to Parrot minidrone, start the model, and use the
keyboard of the host computer to control the speed of Motor 1.

1. On the Simulink toolbar, click the Deploy to hardware button. The model is deployed to the
Parrot Minidrone.

If you have selected the Launch PARROT Flight Control Interface automatically after build
option in the Configuration Parameters dialog box (Hardware Implementation pane > Target
Hardware Resources > Build Options), the Parrot Flight Control Interface opens automatically
after the build goes through successfully.

You can also launch the interface by executing the command Parrot_FlightInterface at the
MATLAB command prompt.

2. On the Parrot Flight Control Interface, click Start. The deployed model is now ready to accept
keyboard key actions.

3. On the Parrot Flight Control Interface, click Show Keyboard Control Panel.

4. Click Enable Keyboard Control

5. Place the cursor in the field below the Enable Keyboard Control button, and type the character a
on the keyboard of the host computer.

2-45
2 Blocks

The Motor 1 starts running.

6. Type the character s on the keyboard of the host computer. The Motor 1 stops running.

7 Click STOP on the Flight Control Interface to stop the model running on the drone.

For more details, see “Keyboard Control of Parrot Minidrones”.

Use MATLAB script to control the drone

The above behavior can be reproduced using a MATLAB script. For more details, refer to the topic
“Using MATLAB Scripts for Keyboard Control”.

A sample script is provided below, which switches on the motor for 3 seconds and then switches it off
for 3 seconds, for 10 cycles.

You need to first deploy the Simulink model to the drone, start the model using the Flight Control
Interface, and then run the below script at the MATLAB command prompt.

try
tcpHandle = tcpclient('192.168.3.1',26061);

for i = 1:10
write(tcpHandle, uint8('a'));
pause(3);
write(tcpHandle, uint8('s'));
pause(3);
end
catch ex
if(isequal(ex.identifier,'MATLAB:networklib:tcpclient:cannotCreateObject'))
error('Simulink model that includes a Keyboard Read block must be running in drone to enab
else
error('Failed to transfer keyboard character to drone. Check if Simulink model is running
end
end

2-46
Getting Started with Keyboard Control of Parrot Minidrones

Click STOP on the Flight Control Interface to stop the model running on the drone.

2-47
2 Blocks

Fly a Parrot Minidrone and Detect Objects

This example shows how to create a Simulink® model that starts the flight of a Parrot® minidrone
and detects a blue-colored object on the ground using the drone's downward-facing camera.

Introduction

The Parrot minidrones are equipped with a downward-facing camera that provides images of the
surface below it. These images can be processed to detect objects.

In this example, you will learn how to use the model to:

• Obtain an image from the downward-facing camera while the drone is airborne
• Perform analysis of the image to detect any blue colored objects
• Hover the drone over the detected blue object

Prerequisites

• 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” on page 2-19.

• See the “Getting Started with Image Processing Algorithms for Parrot Minidrones” on page 2-38
example.

Required Hardware

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

Model

The support package includes an example project that starts the flight of the Parrot minidrone. This
example project takes the drone off the ground and moves the drone to the right until it sees a blue
color on the ground. When the drone sees blue color, it hovers over it.

You can launch the example project by running the following command at the MATLAB command
prompt: parrotMinidroneCompetitionStart

Task 1: Simulate the Drone in 3D Simulator Window

1. Open the example project by executing this command at the MATLAB command prompt.

parrotMinidroneCompetitionStart

2-48
Fly a Parrot Minidrone and Detect Objects

2-49
2 Blocks

2. Once the Simulink project is open, click the Project Shortcuts tab 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, click the Run button on the Simulink model toolbar. 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 to the right direction until the camera on the drone detects a blue color object. On detecting a
blue color object, the drone stops moving and hovers above the blue object.

Note: The command parrotMinidroneCompetitionStart starts 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.

2-50
Fly a Parrot Minidrone and Detect Objects

Task 2: Set Environment to Fly Drone

1. Place a blue colored object on the ground.

2. Place the drone to the left of the blue colored object in such a way that the object is on the y-axis of
the drone.

3. Connect the Parrot Minidrone to your computer using Bluetooth as described in Setup and
Configuration.

Task 3: Deploy the Model on Parrot Minidrone

1. In the model, right-click the Flight Control System and select Open As Top Model. The
flightControlSystem model opens in a separate window.

2. In the model toolbar, click the Deploy to Hardware button. The lower-left corner of the model
window displays status while Simulink prepares, downloads, and runs the model on the hardware.

After succesfully deploying the model, the Parrot minidrone takes off from the ground and starts
moving to the right direction until the drone detects the blue colored object. On detecting the object,
the drone stops moving and starts hovering over the object.

Task 4: Modify the Track in 3D Simulator Window using Competition Track Builder

You can use the Competition Track Builder app to create new tracks and to modify existing tracks.
This app also allows you to test line-following algorithms and other similar algorithms in the Simulink
3D environment. For more information on using Competition Track Builder app, see “Competition
Track Builder”.

1. In the Simulink project, click the Project Shortcuts tab and then click Open Track Builder.

2. In the Competition Track Builder app, make the changes as required. For example, create a custom
track by clicking on the white area and update the changes to 3D Simulator window. A sample GIF
image is shown below.

2-51
2 Blocks

See Also

“Competition Track Builder”

2-52
Follow Set of Waypoints or Follow Orbit Using Parrot Minidrone

Follow Set of Waypoints or Follow Orbit Using Parrot Minidrone

This example shows how to fly a Parrot® minidrone using Simulink Support Package for Parrot
Minidrones by configuring the path planning algorithm to:

• Follow a set of waypoints


• Follow an orbit path

Note: This example requires you to additionally install the UAV Toolbox® from MathWorks.

Prerequisites

• 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” on page 2-19.

Required Hardware

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

Required Products

• Simulink Support Package for Parrot Minidrones


• UAV Toolbox
• Aerospace Blockset
• Aerospace Toolbox
• Control System Toolbox
• Signal Processing Toolbox
• Simulink 3-D Animation

Model

The support package includes two example projects that start the flight of Parrot minidrone and
follows either a pre-configured set of waypoints or an orbit follower, for the flight's path.

To open the example project that uses a set of waypoints, execute this command at the MATLAB
command prompt:

parrotMinidroneWaypointFollowerStart

2-53
2 Blocks

2-54
Follow Set of Waypoints or Follow Orbit Using Parrot Minidrone

To open the example project that uses an orbit follower, execute this command at the MATLAB
command prompt:

parrotMinidroneOrbitFollowerStart

2-55
2 Blocks

2-56
Follow Set of Waypoints or Follow Orbit Using Parrot Minidrone

Task 1: Simulate the Drone in 3D Simulator Window

1. Open the example project.

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.

2-57
2 Blocks

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 parrotMinidroneWaypointFollowerStart and


parrotMinidroneOrbitFollowerStart 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.

Task 2: Configure Waypoint Follower and Landing Logic in Path Planning Subsystem

In the parrotMinidroneWaypoint Simulink model, the waypoints and landing logic are modeled inside
Flight Control System > Path Planning subsystem. Double-click the Path Planning subsystem to
view the logic.

2-58
Follow Set of Waypoints or Follow Orbit Using Parrot Minidrone

There are two subsystems inside the Path Planning subsystem:

Waypoint Follower

The Waypoint Follower subsystem contains the Waypoint Follower block (from UAV Toolbox).

2-59
2 Blocks

This subsystem is used in the parrotMinidroneWaypointFollower project for the following:

• Define the set of waypoints for Parrot minidrone to follow, using [x y z] coordinates. In this project,
we use nine waypoints (with the first point defining the drone's initial position among the
waypoints, and the remaining points defining the complete square path that the drone navigates
twice). The waypoints are defined using a Constant block connected to the Waypoints input of
Waypoint Follower block, by entering the Constant value as follows:

[0 0 -1; 1.5 0 -1; 1.5 1.5 -1; 0 1.5 -1; 0 0 -1; 1.5 0 -1; 1.5 1.5 -1; 0 1.5
-1; 0 0 -1]

Here the z axis value -1 represents the height (1 meter) at which the drone navigates along the
square path.

2-60
Follow Set of Waypoints or Follow Orbit Using Parrot Minidrone

In the Waypoint Follower block, we also set the value of the Transition radius parameter as 0.3.
When the drone is approaching a waypoint, this value is used as the radius around the waypoint
within which the drone starts moving towards the next point. For example, if the Transition radius is
set as 0.3m, and the drone is 0.3m away from the waypoint, the drone starts moving towards the next
waypoint. The accuracy of reaching a specified waypoint increases with a decrease in the value of
Transition radius.

• Define the lookahead distance of the Parrot minidrone while it is navigating along the path. In this
project, we use 0.25 meters as the lookahead distance. This value is proportional to the speed at
which the drone is going to fly (if you increase the value of lookahead distance, the drone moves
fast along the waypoints).

• Update the status once the navigation of the drone along the square path is completed. In this
project, the navigation complete status (obtained from the Status port of the Waypoint Follower
block) is communicated to the Landing Logic subsystem to land the drone.

Task 3: Deploy the Waypoint Follower Model on Parrot Minidrone

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 and starts moving along the x-axis for 1.5 meters. The drone completes the square path

2-61
2 Blocks

twice (as defined using waypoints), finally initiates the landing logic, and then shuts down the motors
when it reaches a height of 0.3 meters from the ground.

Task 4: Configure Orbit Follower and Landing Logic in Path Planning Subsystem

In the parrotMinidroneOrbitFollower Simulink model, the orbit follower and landing logic are
modeled inside Flight Control System > Path Planning subsystem. Double-click the Path
Planning subsystem to view the logic.

There are two subsystems inside the Path Planning subsystem:

Orbit Follower

The Orbit Follower subsystem contains the Orbit Follower block (from the UAV Toolbox).

2-62
Follow Set of Waypoints or Follow Orbit Using Parrot Minidrone

This subsystem is used in the parrotMinidroneOrbitFollower project for the following:

• Define the orbit for Parrot minidrone to follow, by defining the center of orbit (using [x y z]
coordinates) and the radius. In this project, we use [0.5, 0.5, -1] as the centre of rotation and 0.5
as the radius. These are defined using two Constant blocks connected to the Center and Radius
inputs of Orbit Follower block.

Here the z axis value -1 represents the height (1 meter) at which the drone navigates along the orbit.

In the UAV Orbit Follower block, we also set the value of the Turn Direction input as 1. This defines
a clockwise movement of the drone along the orbit.

• Define the lookahead distance of the Parrot minidrone while it is navigating along the orbit. In this
project, we use 0.4 meters as the lookahead distance. This value is proportional to the speed at
which the drone is going to fly (if you increase the value of lookahead distance, the drone moves
fast along the orbit).

• Update the status once the drone completes four circles. In this project, the NumTurns output of
the UAV Orbit Follower block is latched when it reaches a value of 4, and this value is passed to
the Landing Logic subsystem to land the drone.

Task 5: Deploy the Orbit Follower Model on Parrot Minidrone

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.

2-63
2 Blocks

After the model is successfully deployed, the Parrot minidrone takes off from the ground to a height
of 1 meter and starts moving along an orbit of radius 0.5 meters. The drone completes the orbit four
times, finally initiates the landing logic, and then shuts down the motors when it reaches a height of
0.3 meters from the ground.

Other things to try

In the Waypoint Follower subsystem, perform the following and observe the changes in the flight of
the drone:

• Change the set of waypoints that define the path followed by the drone

• Change the Look ahead distance

In the Orbit Follower subsystem, perform the following and observe the changes in the flight of the
drone:

• Change the orbit radius

• Change the Look ahead distance

2-64
Getting Started with Cannon Block for Parrot Minidrone

Getting Started with Cannon Block for Parrot Minidrone

This example shows how to use the Cannon block in Simulink Support Package for Parrot Minidrones
to control a Cannon module attached to a Parrot Mambo minidrone.

Introduction

The Simulink Support Package for Parrot Minidrones provides a Cannon block that you can use to
control the Cannon module attached to a Parrot Mambo minidrone.

The Cannon block can be found in the Simulink library. To access the block from Simulink Library
Browser:

1. Enter slLibraryBrowser at the MATLAB prompt.

2. In the Simulink Library Browser, navigate to Simulink Support Package for Parrot
Minidrones.

open_system('parrotlib');

In this example, you will learn how to use the Cannon block in the Code Generation Template to
fire the balls from the Cannon module attached to the Parrot minidrone.

Prerequisites

• If you are new to Simulink, complete the Interactive Simulink Tutorial.

2-65
2 Blocks

• 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” on page 2-19.

Required Hardware

To run this example, you will need the following hardware:

• Parrot Mambo minidrone with a fully charged battery


• Cannon module attached to the drone
• Bluetooth Low Energy (BLE) 4.0 support on the host computer

Task 1 - Add a Cannon Block and Configure the Input and Output Ports

1. On the Simulink Start page, navigate to Simulink Support Package for Parrot Minidrones and
select Code Generation Template.

2. In the Simulink model, navigate into the Flight Control System, and insert the Cannon block from
the library.

3. Add two Constant blocks and a Manual Switch block in the model, and connect the output of the
Constant blocks to the inputs of the Manual Switch block.

4. Double-click the Constant blocks and set the Constant value as 1 and 0 respectively.

5. Connect the output of the Manual Switch block to the input of the Cannon block.

6. Connect the output port of the Cannon block to a Scope block. The output port provides the
number of firing commands that are pending in the queue while the Cannon module is busy.

The completed Simulink model looks like this:

2-66
Getting Started with Cannon Block for Parrot Minidrone

Task 2 - Perform Monitor and Tune to Fire Balls from Cannon

In this task, you will use the Monitor and Tune feature in Simulink to run the model on Parrot
minidrone, and change the values of the Manual Switch block to start firing the balls from the
Cannon module attached to the drone.

Before proceeding with this task, ensure that the Cannon module is properly attached to the Parrot
Mambo minidrone and the balls are loaded in the Cannon module.

1. Go to the Hardware tab of the Simulink toolstrip, and click Monitor & Tune. The Simulink model
starts running on the Parrot minidrone.

2. In the Simulink model, double click the Manual Switch block to change the input value to 1. The
Cannon module starts firing the first ball after a few seconds.

Observe the value in the Scope block connected to the output of Cannon block in the model. The
displayed value, which was initially 1 when you first clicked the Manual Switch block, changes to 0
after the ball is fired.

3. Double click the Manual Switch block twice to return to the input value of 1. The Cannon module
starts firing the second ball.

Note: The Scope block displays the pending inputs that are queued up before the actual firing action
of the Cannon module occurs.

The support package also provides a pre-configured model(parrot_cannon_getting_started) that you


can use to work with the Cannon module of Parrot Mambo minidrone.

Other things to try

You can use the Keyboard Read block available with Simulink Support Package for Parrot Minidrones
to control the input to the Cannon block. You can configure any key on the keyboard of the host
computer to trigger the firing of balls from the Cannon module. For reference, look at this pre-
configured model(parrot_cannon_keyboard_control).

2-67
2 Blocks

Getting Started with Grabber Block for Parrot Minidrone

This example shows how to use the Grabber block in Simulink Support Package for Parrot Minidrones
to control a Grabber module attached to a Parrot Mambo minidrone.

Introduction

The Simulink Support Package for Parrot Minidrones provides a Grabber block that you can use to
control the Grabber module attached to a Parrot Mambo minidrone.

The Grabber block can be found in the Simulink library. To access the block from Simulink Library
Browser:

1. Enter slLibraryBrowser at the MATLAB prompt.

2. In the Simulink Library Browser, navigate to Simulink Support Package for Parrot
Minidrones.

open_system('parrotlib');

In this example, you will learn how to use the Grabber block in the Code Generation Template to
close and open the Grabber module attached to the Parrot minidrone.

Prerequisites

• If you are new to Simulink, complete the Interactive Simulink Tutorial.

2-68
Getting Started with Grabber Block for Parrot Minidrone

• 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” on page 2-19.

Required Hardware

To run this example, you will need the following hardware:

• Parrot Mambo minidrone with a fully charged battery


• Grabber module attached to the drone
• Bluetooth Low Energy (BLE) 4.0 support on the host computer

Task 1 - Add a Cannon Block and Configure the Input and Output Ports

1. On the Simulink Start page, navigate to Simulink Support Package for Parrot Minidrones and
select Code Generation Template.

2. In the Simulink model, navigate into the Flight Control System, and insert the Grabber block from
the library.

3. Add two Constant blocks and a Manual Switch block in the model, and connect the output of the
Constant blocks to the inputs of the Manual Switch block.

4. Double-click the Constant blocks and set the Constant value as 1 and 0 respectively.

5. Connect the output of the Manual Switch block to the input of the Grabber block.

6. Connect the output port of the Grabber block to a Scope block. The output port provides a boolean
value that represents the current state of the Grabber module (open or closed).

The completed Simulink model looks like this:

2-69
2 Blocks

Task 2 - Perform Monitor and Tune to Close and Open the Grabber Module

In this task, you will use the Monitor and Tune feature in Simulink to run the model on Parrot
minidrone, and change the values of the Manual Switch block to close and open the Grabber module
attached to the drone.

Before proceeding with this task, ensure that the Grabber module is properly attached to the Parrot
Mambo minidrone.

1. Go to the Hardware tab of the Simulink toolstrip, and click Monitor & Tune. The Simulink model
starts running on the Parrot minidrone.

2. In the Simulink model, double click the Manual Switch block to change the input value to 1. The
Grabber module closes.

Observe the value in the Scope block connected to the output of Cannon block in the model, after the
Grabber closes. The displayed value is 1.

3. Double click the Manual Switch block again to change input value to 0. The Grabber module
opens.

The support package also provides a pre-configured model(parrot_grabber_getting_started) that you


can use to work with the Grabber module of Parrot Mambo minidrone.

Other things to try

You can use the Keyboard Read block available with Simulink Support Package for Parrot Minidrones
to control the input to the Grabber block. You can configure any key on the keyboard of the host
computer to trigger the closing or opening of the Grabber module. For reference, look at this pre-
configured model(parrot_grabber_keyboard_control).

2-70
Path Planning Using Keyboard Control for Parrot Minidrone

Path Planning Using Keyboard Control for Parrot Minidrone

This example shows how to use the keyboard of the host computer to control the position of Parrot®
minidrone using Simulink Support Package for Parrot Minidrones.

Prerequisites

• 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” on page 2-19.

Required Hardware

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

Required Products

• Simulink Support Package for Parrot Minidrones

Model

The support package includes an example project that starts the flight of the Parrot minidrone. The
position of the drone is controlled using the keyboard.

You can launch the example project by running the following command at the MATLAB command
prompt: parrotMinidroneKeyboardControlStart

Task 1: Simulate the Drone in 3D Simulator Window

1. Open the example project by executing this command at the MATLAB command prompt.

parrotMinidroneKeyboardControlStart

2-71
2 Blocks

2-72
Path Planning Using Keyboard Control for Parrot Minidrone

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.

2-73
2 Blocks

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.

Task 2: Configure Keyboard and Landing Logic in Path Planning Subsystem

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.

2-74
Path Planning Using Keyboard Control for Parrot Minidrone

There are three subsystems inside the Path Planning subsystem:

Keyboard Control Logic

The Keyboard Control Logic subsystem is used in the parrotMinidroneKeyboardControl project for
the following:

• Define the set of keys on the keyboard 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:

Here the 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 X axis.

Here the 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 Y axis.

2-75
2 Blocks

Here the 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.

Here the Yaw value represents the yaw of the drone and the value is determined by 'g' and 'h' keys on
the keyboard. Press the key 'g' to change yaw of the drone by 0.1 radians in clockwise direction or
press the key 'h' to change yaw of the drone by 0.1 radians in anticlockwise direction.

Note: The value 0.1 for the keys can be changed by modifying the Gain values in the Keyboard
Control Logic subsystem.

Task 3: Deploy the Model on Parrot Minidrone

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.

2-76
Path Planning Using Keyboard Control for Parrot Minidrone

3. In the Hardware tab of 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. Use the configured keys to control the drone's position.

2-77

You might also like