Firmware > Height Control
IR Sensor Activation and Data Collection:
As mentioned before, the project specified for the blimp to use IR sensor readings (instead of e-field readings) for proximity readings. The given blimp module contained five infrared lights controlled by a decoder peripheral as well as one infrared light reader connected directly to the blimp microprocessor. Because of this, time-division multiple-access (TDMA) sampling was used to collect data. To initiate a IR sampling, the respective IR light was triggered by setting the decoder pins and then toggling the decoder’s enable bit. However, because of the nature of IR light, the data was not sampled immediately after initiation but rather through a timer interrupt routine (TimerA2). There, the ADC10 on the microprocessor was initiated to obtain the IR reader data. This was repeated multiple times (about 64 times) and, after all data was collected, the samples were averaged to obtain the overall IR sensor data result for a particular sensor.
Height Control:
For height control, a proportional/integral/derivative controller (PID controller) was implemented to handle the vertical IR sensor data. In particular, this method of using PID control allowed for a continuous feedback loop that automatically adjusted the speed and direction of the vertical fan with regards to the current sensor sample value and the target height value.
Height Lookup:

Before the PID control algorithm was used, the height values were first determined by manually recording the sensor values at respective heights. This was necessary for adequate PID usage because, as explained in the lab specifications, sensor readings using IR sensors are by default non-linear, making it extremely difficult for the blimp to distinguish sensor readings for heights very near or very far away from the ground. To accomplish this linearization of sensor values, a look-up table (LUT) was used alongside bi-linear interpolation to determine the blimp’s respective height. Generation of these LUT points was done by first taking the sensor value readings from the maximum height and the ground (which were 900 and 3000 respectively). Then, samples at consistent intervals between the ground and the maximum height were taken and recorded. After that was done, these points were inputted into a graphing program and were used to generate intermediate points along an inverse graph .
PID error control:

Kp: Proportional gain, a tuning parameter Ki: Integral gain, a tuning parameter Kd: Derivative gain, a tuning parameter e: Error = Set-point - currentpoint t: Time or instantaneous time (the present) MV: Adjustment as feedback to modify the current fan speed.
The altitude height control was always completed after one batch of sensor sampling data was sent back to the computer. The fan adjustment was implemented by adding up the three different parts of the PID control: the proportional error correction (which depended on the current error calculation), the integral error adjustment (which depended on the total errors made within a certain time period), and the derivative control (which adjusted the speed of vertical fan depending on the current error rate). As a result, the blimp was able to accurately model its height and correct the differences between its current height and its target height more efficiently. In addition, a low pass filter was implemented to reduce the effect of any noise. Ultimately, the the different PID components and the low-pass filter was tuned in the end using the GUI in order to get the best results.
