The PICpilot is a software package meant to control fixed-wing aircraft and numerous "copters", among other vehicles. It requires the usage of a specific type of digital signal microcontroller. This microcontroller is produced by Microchip. The microcontroller that is currently supported is the dspic33fj256gp710A. However, many other similar models can be easily adapted for support.
This software is designed to be used with two communicating microcontrollers (essential double cores). Due to the atypical nature of the software, it is recommended to view the board schematics here. The schematics are also included in another section of this document.
The two processors are allocated to two individual tasks. The chip which is responsible for attitude management is often referred to as the "main" chip. It is responsible for making corrections to the planes orientation in space, which involves pitch, roll, yaw, heading, throttle, and altitude. It also manages a few additional tasks involving relaying communication with the ground station. The second processor is often referred to as the "Path Manager". This chip controls the where the plane should fly (path), and the transitions in altitude and heading between each waypoint (specific GPS coordinates). It also controls the GPS and altitude sensors. These two chips work asynchronously from one another in order to automate the plane.
To get started, you will need three things:
A similar powerpoint presentation can be found here:https://docs.google.com/presentation/d/1HkjCdRQyY1LFaUO-24SxHGLx4cgeq_Z5OWQQNKFfidM/edit?usp=sharing
If you are not using the GUI skip this section.
- Setup a Github Account
- Select "Set up Git"
- Select "Download GitHub for
- Select "Run" and continue through the installation process
- Once the installation is complete, launch the application.
- Log in
- Find the Git Bash shell and type in the following commands:
git config global user.name "YOUR USERNAME HERE"
git config global user.email "YOUR EMAIL HERE"
These set the default name and email you use when committing to GitHub.
- At this point you will need to let one of the WARG team leads know your username, so that you can be added to the repository member's list.
- You should then be able to clone the project using the clone button, or the project URL.
You should now have the code.
You now need the libraries and compilers, as well as the optional MPLAB X IDE, in order to develop code.
- Download the compiler. You want the MPLAB XC16 Compiler V1.21 or newer. Unzip the file once it is completed.
- Accept the license agreement.
- Select "Install Compiler".
- Select "Install MPLAB XC16 C Compiler on this computer.
- Leave the activation key blank. Confirm "Yes" when the dialog prompts you about using the free version.
- Select "Run the compiler in free mode".
- Select the installation directory.
Run and finish the installation.
Note whenever you make a new project, make sure the right compiler is selected, otherwise there will be a lot of indicated syntax errors (red underlines).
IDE (The fancy word editor that lets you do some code-shenanigans)
- Download the IDE Package. You want the MPLAB X IDE V2.10 or newer. Unzip the file once it is completed.
- Proceed through the installation process (select installation directory, accept license agreement).
If you don't know how to use Git or you need a reference, GitImmersion is a great website.
- Make sure you have correctly set your default storage location in the Options menu.
Saving Files (Committing and Pushing)
- Select your Project
- Select the files that are supposed to be committed.
- Write a commit message, that gives a general overview about each change completed in this update.
- Hit "Commit".
- Once you are ready to sync the changes, hit the sync button (top of the window).
Reading Files from the Server (Pulling) * Simply click the sync button at top of the window.
General Syntax (Git Bash):
git add <Filename> or git add .stages the file for commit.
git statusdisplays all changes being made.
git commit -m "<Commit message here>"makes the change.
git pushsends the change to the server
git pullretrieves the latest change from the server.
git checkout <HASH>retrieves a SPECIFIC version from the server.
git checkout -b <Branch Name>creates a new branch.
git merge mastermerges the current branch with the latest code.
- When making small changes it is okay to commit to the master branch.
- When making large changes (that take multiple days to complete), always make a branch, so that others can work concurrently without compiling broken code.
- Always build your code before committing (To make sure it isn't broken).
- Try and get rid of warnings if possible.
C (Programming Language)
The language being used in this project is C. If you are familiar with C++, the concepts are very similar. C is a low level programming language. This means that it does not have a large amount of "built-in" functionality, therefore learning C is quite straight forward.
The compiler used for this project is listed above. It is a modified version of the GCC Compiler.
A set of well maintained tutorials can be found here: http://www.cprogramming.com/tutorial/c/lesson1.html
Topics that one should be familiar with include (in order of importance):
- If statements
- Variable types and how they work
- Structures, Unions
- Printf (There is no GUI)
- File I/O (All I/O operations are specific to the chip)
Knowledge of common data structures (binary trees, linked lists, etc.) is beneficial, but not mandatory.
Programming the Device
In order to program the device, you must have setup your account according to the Setup section. You should also refer to the Schematics and Board Design section for the ports required to complete the programming process. You will require an ICD 3 or a similar programming device.
When using the MPLAB X GUI the process to program the device is as follows:
- 1. Ensure the project you wish to program is the main project. 2. Connect a cable to the programming port. The pins that should be part of the programming port are MCLR, PGD1, and PGC1. 3. Click the "Make and Program Device" button in the top toolbar. Optionally, you can also press the debug button to use the debugging features of MPLAB X.
When using your own editor and compiling from the command line:
- 1. Have the binary file ready for programming. 2. Connect a cable to the programming port. The pins that should be part of the programming port are MCLR, PGD1, and PGC1. 3. Open the MPLAB IPE interface. 4. Select your chip model. 5. For the source option, browse to your binary file. 6. Press program and wait. Then optionally also use the verify option (recommended).
If you are using both chips of the PICpilot, ensure you correctly set the chip identifier pre-compiler in the main.h file, and ensure you program both chips.
Autopilot System Overview
The autopilot system is meant to be adaptable to any aircraft including fixed-wing and multi-rotor aircraft (still WIP). This document mostly covers the software design of the system, although there are a few hardware notes made in this section and the next.
First of all, the flowchart block diagram of the system is presented below:
From this diagram you can see how the software combined with the hardware interacts to provide the final resulting UAV behaviour.
There are three chips. The main one is most commonly referred to as the attitude manager. It is also the communication manager, and the Master chip for all interchip communication. The other chip is referred to as the path manager. The third one has the dedicated task of managing the mechanical "safety" relays which ensure that a safety pilot can always regain control of the aircraft.
There are four sensors used in the original design of the aircraft. A GPS (Global Positioning System), IMU (Inertial Measurement Unit), Altimeter, and a camera are all part of the system. Additionally, 2 wireless interfaces are included in the design. A wireless Xbee transmitter/receiver provides telemetry data, whereas an additional (Ultra-high frequency [UHF]) receiver is used to attain control from a standard RC controller.
The outputs from the system include pictures and potentially video, telemetry data, and a functioning aircraft (with moving flaps, elevators, rudder, and ailerons).
This document only covers the PICpilot, however a system overview of a previously fully assembled system will be described in this section. In the past, the PICpilot has been expanded into a larger and more sophisticated system as seen below.
Schematics and Board Design
The following schematic is V2.1 of the PicPilot. You can check out the board schematics on GrabCAD. You will require Diptrace in order to view the files. You can use the free version or use WARG's "Pro" license.
This board has 2 dspic33fj256710a chips. This is the PCB for the board. This is the labelled version:
Switching Power Supply 1
Switching Power Supply 2
External Battery Monitor
Analog sensors: airspeed and ultrasonic
UART2 Port - Unused
Path Manager Debug
Path Manager Programming Port
SPI Ports: Top- GPS, Bottom- Unused
Microcontroller 2 - Path Manager
Attitude Manager Programming Port
Microcontroller 2 - Attitude Manager
Attitude Manager Debug
Relay Controller Programmer Port
Safety Relays (Inputs 1-4)
I2C - PWM Extension
To get a full list of the different pins, look at the schematic on GrabCad. Highlighted below are the ground connections (and you are politely reminded to NEVER connect these pins to anything but ground, always check before connecting cables).
All the project files are hosted on Github. However, for convenience they are listed below (accurate at the time of writing of this document):
The coding convention form this project follows the standard coding convention for the C language.
The rule-set for the coding format is not extremely specific. However, there are a few rules of thumb to be aware of. The rules of thumb are:
- Naming convention - Use camelCase notation for variables. Use capitals and under_score_case for constants.
- Indentation Style - Use tabs/indents to show the program structure.
- Commenting - Be thorough with comments. Include a header at the beginning of every file describing the file, the author, the file name, and the date of creation. For headers, include comments describing any constants, and for each function prototype include the function name, function inputs and outputs, and a description of its functionality.
- Never hard-code values. Any constants should be defined together so that they can be easily changed through iterations of the code.