Tortuga II Software
The software is like the brain of the vehicle. It takes inputs from all the sensors and determines what commands to send to the vehicle. The software for the vehicle is written in C, C++ and Python programming languages. It runs on the Gentoo GNU/Linux operating system. It is capable of running both the actual vehicle and a simulation of the vehicle.
Figure 9. Overall software structure.
Drivers
The drivers are software libraries which provide a basic interface to the vehicle's hardware. They allow the high level software to send commands to and receive data from the hardware. Drivers for the IMU, sensor board, and motor controllers where written in the C programming language. The drivers are used by the controller and other software components to send commands to thrusters, read orientation data from the IMU, and check voltage and current levels.
Controller
The controller commands the vehicle in order to match the software's desired vehicle state with the actual vehicle state. The controllers uses the IMU driver to determine the orientation of the vehicle and computes the difference between that orientation and vehicle desired orientation. Using a non-linear adaptive controller it determines the proper thruster forces to move vehicle toward the desired orientation in a stable manner. The same is done for the vehicle's depth. The controllers is implemented in C++ to guarantee its runtime to provide precise update rates needed by the controller.
Vision
The vision system processes images from the on board cameras to derive information about the outside world. The goal of the vision system is determine the vehicle's location relative to competition objectives. Images are captured from the forward and downward firewire cameras and are filtered based on the color of the competition objectives. Then depending on the current objective various imaging processing algorithms such as canny edge detection (highlights the edges in an image), hough transform (finds the straight lines in an image), and blob detection (detects continuous sections of color) are used. The vision system is implemented with the OpenCV imaging processing library using C++ for the best possible performance.
Motion
The motion system moves the vehicle in predetermined patterns. These patterns can be to change depth or heading at a specific rate, search patterns, or objective seeking motions. They are implemented on top of the controller using inputs from the vehicle's other sensors and exist to simplify the development of missions and the artificial intelligence (AI). They let the AI determine that it just wants to run a search pattern or change depth, and it doesn't have to worry about how it gets done.
AI
The artificial intelligence of the vehicle determines what the vehicle should do based on the currently available information. It is implemented in Python using a finite state machine. A finite state machine represents a process, like completing the competition, as a discrete groups of steps with actions providing the transitions between them. These actions are generated from the vehicle's sensor systems. They can be things like finding the red light, one of the competition objectives, or finishing a dive. The AI determines when to turn on and off the vision system, and when an objective is found it then activates on the motion which completes it. As you can see in figure 10 below these states can be chained together to create an entire mission. In this example when the dive is finished the AI turns on the vision system. When the light is found it creates the motion which propels the vehicle toward the light, then surfaces after completing the objective.
Figure 10. Example state machine for completing the red light objective.


