The software is where most of the work for this project went. It inludes all of the functions necessary for operation with additional saftey features. This is mainly the ability to take in data from the sensor and alter it until it is a useable PWM signal for each of the motors.
- PID Controllers
- Motor Control Algorithm
- Battery Health Checks
- Status LED Control
- Error Handling
- Serial Communication
PID Controllers
The main part of the controlling algorithm in CodQuaptor are the three implemented PID Controllers. The three controllers represent the height, roll, and pitch of the device. When the error is determined from these controllers the value is normalized for use with the motors.
Motor Control Algorithm
In order for the PID controller data to be used to control the motors, they were sent through an algorithm which generated the correct PWM signal for each motor. In order to generate the final result, the roll and pitch value was divided in half and then added or subtracted to the height value, depending on the position of the motor. In order to prevent any kind of positive feedback loops in the motor control the roll and pitch number was added to one side, and then subtracted from the other. This will balance the device and prevent the motors from maxing themselves out.
Battery Health Checks
To prevent damage to the device and the on-board battery, there are constant battery checks occuring inside of the main function. This uses a wire attached from the MSP430FR5994's ADC to the battery to determine it's current voltage. There are three states of battery health: Optimal, Low, and Critical. When the device is in an optimal battery state, it functions normally. When the low battery state is entered, the device will decrease the power sent to the motors which will hopefully lead to a successfull landing. As soon as the device enters a critical battery state, the motors and LEDs are all disables, and the MSP430 enters a low power mode until the device is reset.
- Optimal > 3.0 V
- Low 2.9 V - 2.7 V
- Critical < 2.7 V
Error Handeling
To prevent any I2C errors from crippling the function of the device, whenever a NACK is received from the slave device, the master will resend a start condition to reestablish the I2C Communication.
Status LED Control
In order to indicate the status of the battery to the user, there is an LED placed on each of the arms of Codquaptor which display the battery health. In an optimal voltage state, the lights remain in a constant on state. When a low-power state is entered, the lights will begin to flash with a 50% duty cycle. Once the critical battery plane is entered the lights will shut off along with the motors.
Serial Communications
I2C and UART are both implemented into the software to allow for simple communication with all of the ICs on board. I2C is used between the MSP430, the proximity sensor, and the accelerometer. UART is used to talk to the MSP430 chip from a computer. Below is an example data read from the accelerometer showing how the data will be displayed to the processor. First, the master enters write mode and sends the address it wants to read from. The next 6 received bytes are the X, Y, Z values with the most significant byte sent first.