How To Guide: ArduPilot 2.0 Simulink Blockset
Fran¸cois Hugon
Robert F. Hartley
Brian DeRosa
Gulfstream Aerospace Corporation
Embry-Riddle Aeronautical University
Savannah, Georgia
Christopher Carvalho
Embry-Riddle Aeronautical University
Daytona Beach, Florida
November 2, 2012
Acknowledgements
Thank you to our wives and significant others–Sara, Laura, Bailey, and Lauren–
who patiently dealt with long nights, neglected chores, and were our biggest
supporters to be successful in this adventure.
Thanks to Brian DeRosa for allowing us to takeover his house and convert
his dining room table into a hangar.
Thanks to the world renowned RC pilot, George Hicks, for being our safety
pilot, being a great resource for tips and tricks for RC aircraft, always having
the parts we needed up to and including entire airframes, and for always being
willing to fly with almost zero notice.
Thanks to Richard Ruff from Mathworks for providing technical expertise
and guidance while developing the APM2 Blockset.
Abstract
As part of developing a new graduate level Guidance, Navigation, and Control
course at Embry-Riddle Aeronautical University, a Simulink blockset has been
developed that will allow students to work solely in Matlab/Simulink for the de-
velopment of GNC code. This code can be downloaded directly to the ArduPilot
2.0 integrated sensor and processing package allowing the students to easily de-
velop unmanned aerial vehicles. The blockset is useful in that it eliminates the
requirement to have a knowledgeable programmer, and a knowledgeable electri-
cal engineer to integrate hardware and software with the airframe. This guide is
intended to describe the functionality of the blockset, provide recommendations
for how to implement control designs, and steps on how to embed the code onto
the ArduPilot directly from Simulink. The blockset is in early development
and there is room for improvement; it is expected that future students or the
academic community as a whole will advance the capabilities going forward.
Contents
1 Introduction 7
2 Setup and Usage 8
2.1 Matlab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2 Simulink Configuration Parameters . . . . . . . . . . . . . . . . . 8
2.3 Run On Target Hardware . . . . . . . . . . . . . . . . . . . . . . 9
2.4 Arduino Target Cores Directory . . . . . . . . . . . . . . . . . . . 9
2.5 IOWrappers.cpp file . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.6 Simulink Path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.7 S-Function Build . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.8 Downloading a Model . . . . . . . . . . . . . . . . . . . . . . . . 10
3 ArduPilot Mega 2.0 Library Blocks 11
3.1 Sensor Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.1.1 Inertial Measurement Unit . . . . . . . . . . . . . . . . . 11
3.1.2 Barometric Pressure Sensor . . . . . . . . . . . . . . . . . 12
3.1.3 Magnetometer . . . . . . . . . . . . . . . . . . . . . . . . 14
3.1.4 GPS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.1.5 Pitot Probe . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.2 Receiver Input / Servo Output . . . . . . . . . . . . . . . . . . . 20
3.2.1 RC Read . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.2.2 RC Write . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.3 Timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.3.1 Clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.3.2 Real Time Monitor . . . . . . . . . . . . . . . . . . . . . . 22
3.4 Data Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.4.1 Telemetry . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.4.2 USB Output . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.4.3 Flash Memory Chip . . . . . . . . . . . . . . . . . . . . . 25
3.4.4 Downloading Data . . . . . . . . . . . . . . . . . . . . . . 26
3.5 Other Miscellaneous Blocks . . . . . . . . . . . . . . . . . . . . . 27
3.5.1 Discrete Input . . . . . . . . . . . . . . . . . . . . . . . . 27
3.5.2 Discrete Output . . . . . . . . . . . . . . . . . . . . . . . 29
3.5.3 LED Blue . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
1
3.5.4 LED Yellow . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.5.5 LED Red . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.5.6 Analog Input . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.5.7 Analog Output . . . . . . . . . . . . . . . . . . . . . . . . 30
3.5.8 Serial Read . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.5.9 Convert Float to uint8 . . . . . . . . . . . . . . . . . . . 30
4 Examples 32
4.1 Basic Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
4.2 IMU and Data Output Example . . . . . . . . . . . . . . . . . . 33
4.3 Sensors Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
4.4 Downloading a Model . . . . . . . . . . . . . . . . . . . . . . . . 35
4.5 Next Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
5 Simulink Blockset Architecture 36
5.1 APM C/C++ Code Base . . . . . . . . . . . . . . . . . . . . . . 36
5.2 Level 2 S-Function . . . . . . . . . . . . . . . . . . . . . . . . . . 39
5.3 Target Language Compiler . . . . . . . . . . . . . . . . . . . . . . 39
6 Future Work 42
6.1 Future Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
7 Support 44
2