Magic PlankUniversity of Central Florida College of Computer Science and EngineeringSenior Design II Group IISpring/Summer 2012 |
|
Menu Home Project Overview Project Files Photo Gallery Team Members Contacts |
Software Files, Behind The Software of Magic PlankThe software design for the Magic Plank is really the main part of the project. It is implemented using the Arduino programming language, which is syntax compatible with C++. Taking advantage of this object oriented code base, the code is designed as a collection of modules which each perform their functions independently. The hierarchy takes a bottom up approach by first addressing bare hardware interfacing and handling the hardware functions to make it easier to handle from the higher level modules. The Sabertooth, IMU, and Bluetooth modules handle hardware interfacing while the Filter class manages the IMU and handles angle processing for the Balancer class, which manages all the classes in the hierarchy and incorporates them into a main control loop. Balancer ClassThe balancer class is the main master class of the system. Balancer, as seen in the code hierarchy, instantiates and manages the Bluetooth, Sabertooth, and Filter classes. The balancer contains the Proportional Integral Derivative (PID) control algorithm that calculates a speed for the motors. The main control loop operates by first updating the Bluetooth class, which will either result in a new steering value from the Bluetooth module or result in a failure. In the event of a failure, the loop will send a signal to terminate movement of the motors, which creates the effect of a software dead man switch. More on this functionality is described in detail in the section regarding the Bluetooth class. In the event of a success, the loop then continues to a loop timing control, which regulates the loop time of the algorithm. Currently, the algorithm executes a loop time of 50 ms, or 200 loops per second. After the loop regulation time, the PID control function is executed. The PID control function operates by first updating the Filter class, which implicitly updates the IMU class, therefore sampling new data from the current data from the IMU3000. Once this update is complete, a new angle is returned for use in the PID calculation. Balancer Class [14 KB] Bluetooth ClassThe Bluetooth class is the driver that handles all input from the Bluetooth RN-42 Bluetooth module. The first function is the update function, which reads in and parses a new two byte signed integer value from the Bluetooth module. This value is then cross-referenced against a pre-defined kill command. If the kill command is received, a killSwitch flag is marked. If the connection times out and does not receive any data, the update function returns false. If the killSwitch flag is marked or the update returns false, the Balancer takes appropriate action and terminates movement of the motors. Upon termination of the motors, the Balance r then calls the next function, which is the DeadLoop. In the loop, the Bluetooth module continues to be sampled until it receives a pre-defined revive command. Upon receiving this command, the loop exits and the Balancer is free to resume the balancing loop. In addition to handling the kill switch, the secondary function of the Bluetooth class is to interpret incoming steering commands, which, if valid, are passed up to the Balancer class for integration into the control loop. Bluetooth Class [4 KB] Filter ClassThe Filter class handles processing the raw data passed up from the IMU class and passes the data through what is known as a Complementary Filter. Filter Class [5 KB] IMU ClassThe IMU class is the hardware driver for the IMU3000. The IMU works by utilizing the hardware supported I2C interface and the Arduino I2C software library. Initializing the IMU causes it to enter into the calibration function, which calibrates the IMU, assuming that the current orientation is level. This initialization is actually critical to the startup of the Magic Plank and determines the level at which the platform will attempt to balance. Updating the IMU causes the class to sample from the IMU3000s registers, sampling the most recent raw data from the gyroscope and its auxiliary accelerometer. It then subtracts the calibration offsets determined upon initialization and also converts the raw data into usable data: degrees per second for the gyroscope and force of gravity in Gs. These values are then passed up for the Filter class to use. IMU Class [7 KB] Sabertooth ClassThe IMU class is the hardware driver for the IMU3000. The IMU works by utilizing the hardware supported I2C interface and the Arduino I2C software library. Initializing the IMU causes it to enter into the calibration function, which calibrates the IMU, assuming that the current orientation is level. This initialization is actually critical to the startup of the Magic Plank and determines the level at which the platform will attempt to balance. Updating the IMU causes the class to sample from the IMU3000s registers, sampling the most recent raw data from the gyroscope and its auxiliary accelerometer. It then subtracts the calibration offsets determined upon initialization and also converts the raw data into usable data: degrees per second for the gyroscope and force of gravity in Gs. These values are then passed up for the Filter class to use. Sabertooth Packetized Class [3 KB] Sabertooth Packetized2 Class [4 KB] Sabertooth Simplified Class [3 KB] Back to Project Files |
Questions or coments, please vists our Contacts Page. |