The Final Run Part I

Our final leg of the competition involved a lot of hard work and critical decisions that were made by the team and cannot be summarised into a single blog post. So I shall split it up into parts to document the process we had so others will not fall into the same trap as we did!

The High level Software and Low level Embedded Architecture

Our system has a slew of sensors: 3 axis gyroscopes, 3 axis magnetometer, 3 axis accelerometers to give orientation and heading, a pressure sensor for depth ranging and two web cams for vision. It previously had two sonars (for depth ranging and obstacle avoidance)  and a flow rate meter for velocity control but we took that out due to the simplicity of the mission parameters we realised later on. The Arduino is in charge of the sensing, actuation(i.e. propulsion of the thrusters) and lastly control systems which help realise our autonomous behaviour. The Raspberry Pi is in charge of high level algorithm control. It performs the more computational and memory intensive work. You can think of it as he’s the big boss of the Arduino who is the supervisor of everybody else except the webcam which is connected to the Pi. Autonomous platforms usually consist of the three above mentioned: sensing, controls and A.I., actuation. The diagrams below shows our software and hardware architecture prior to the final few days leading up to the competition.

Software Architecture

Embedded Hardware Architecture


The Turning Point

The final lead up to the competition was a crazy week for all of us. Just a week before the competition, it seemed impossible for us to even be able to compete in the competition given that we had not even managed to properly waterproof our hull and were also faced with a major crack in the flange of our hull. Our mechanical design proved to be difficult to waterproof. At that point in time with waterproofing incomplete we could not test our AUV right down to basic control systems because we simply could not risk getting our electronics (mostly bare boards) anywhere near water!  And so that fateful Friday as I recalled it with time and money both against us, I put forth the idea of a withdrawal from the competition rather than going for the competition with a leaky hull and incomplete software which all needed way more than the few days we had left to test and tune. So we sat down together and discussed the cards we had left to play on the table: To withdraw now from the competition and announce the complications we faced as the reason or to continue attempting to waterproof the original hull we had been working on for months on ends and lastly, the boldest and riskiest move of which, to come up with a completely new hull in 3 days on minimum budget as we had used up almost all of our cash reserves. Tune and test our control systems and  A.I. in the remaining 3-4 days we had available.  After much discussion and deliberation, we decided on the third option, which was to start from scratch again and rebuild a new hull on extremely cheap materials. So we we went to IMM to shop for waterproof containers for our Hull and found this at Giant: Lock N’ Lock Tupperware containers.

Conceptual model of CoconutPi Rev2

Conceptual model of CoconutPi Rev2

The bottles represent vertical thrusters. The scrunched up plastic bags are propulsion thrusters. Cylindrical Lock&Lock box is for the camera and the Big one is for the main electronics. It was all to be held together with three lengths of square aluminium profiles. Macgyver style hackish contraptions FTW!

The Countdown

What ensued next was a full day of drilling and hacking to assemble our mechanical body within a single day with sensors integrated. Loads of marine sealant, epoxy putty, sugru and plastic steel epoxy were applied to patch the hull up. The next day we did a lot of waterproofing testing and reapplication of sealants and patching up of the mechanical hull. By the third day it was deemed to be waterproof and we headed down to Eng Wei’s condominium to test out the mechanical aspects such as buoyancy and the righting moment of the ship.


Testing the waterproof-ness of the ship at my Condominium

This was a bad day for us as it started raining heavily in the afternoon just when we had completely waterproofed the AUV. In addition to that the power supply to the area was turned off. So we decided to abandon the swimming pool tests and just focus on water tank tests at the Acoustics Research Lab. We had lost our 2nd last card on our hands. At that point we were only left with 72 hours to get our Control Systems working and  depth sensors (which were not yet completed) fully working. On top of that we had to integrate the higher level Mission Planning  and Computer Vision into the system which needed time for testing and debugging. The next few days we rushed and survived on very little sleep, loads of coffee and Al Ameen food because we worked late into the night. We faced tonnes of problems surfacing of which we solved issue after issue and mistake after mistake, from accidental short circuiting of the ArduPilotMega, from nearly killing it (on the day of qualifiers) to actually killing it (2 hours before finals!) and managing to replace it with the older version of the ArduPilot just in time.


Our set up working into the night. Continuously we were programming and testing and debugging the autonomous underwater robot at the Acoustics Research Laboratory at NUS.

The Qualifiers

By the morning of the qualifying rounds we had only just managed to finish the control systems and had not started on the Computer vision aspect. The fortunate thing for us was that the qualifying rounds only required the AUV to dive underwater and move forward for 10 metres. This was no tall task as we had already completed the Control Systems which were equipped with nine-axis IMUs which meant that our AUV was completely autonomous in terms of orientation and we could easily specify the direction we wanted our ship to move in. In addition to that the depth pressure sensors were working really well and could have proper depth control on it too. Another benefit we had was due to the fact that our thrusters were self assembled from various RC components and made use of Lithium Polymer batteries and could generate an immense amount of thrust. Something which we tried to reduce so as to provide a wider range of controls and less current draw on the Lipo batteries. It was difficult finding the right motor specification as we had to fit the ducted fan design too since we could not mill out our thrusters, it was better if we bought custom made EDFs. This turned out to be a slight minor advantage for us.


Close up of our Heave/Dive motors

The speed but current draw penalty we had turned into an advantage as we zoomed through the qualifers which only required us to complete 10m in a straight line. Whilst our AUV could go straight with a yaw controller adjusting for yaw,it had problems going straight perpendicular to the swimming pool wall and would always veer off at an angle.  There was a an inaccuracy or offset in our yaw readings which did not correspond so well to the magnetometer on our smartphones(why the smartphones could even be imprecise). Right before our qualifiers we attempted to calibrate to its initial yaw angle but due to certain problems with the logic or flow of sensor initialization we were unable to fix it in due time, otherwise going straight would not have been an issue. Anyhow, it bought us the precious time we needed because, as of that moment, we had not done a SINGLE test on the higher level A.I and Computer Vision. The night before was spent entirely on Controls and a bit of Computer Vision.


Testing out the vessel for the first time round during the qualifiers. We had missed the tryouts the day before due to connectivity issues with the Pi and lack of time.

The Final Push

In some sense at that point in time, we were all pretty amazed at how we could have completed so much within such a short period of time. But we still had much work to do on the Computer Vision portion. The qualifiers had bought us time to push ahead with the software. We performed some pressure sensor calibration tests to about 1.7m to fit the competition specifications and the rest of the night was spent on getting our OpenCV right.  By then it was the fourth or fifith day we were on only few hours of sleep a day.


Testing down to a depth of 1.7m in the ARL’s deepest tank

Our line tracking algorithm was performed in the following stages:

1. Convert the image to grayscale.

2. Perform black colour thresholding on the single grayscale channel.

3. Clean up the image with a series of erosion morphological operations.

4. Compute the Hough Transform to derive lines corresponding to the edges of the black line.

5. With the array of line parameters from the Hough Transform perform Linear regression (minimisation on the Sum of Squared Error on a linear hypothesis) on the data and derive the parameters for the line of best fit.

6. With this set of x and y parameters of the line compute the angle of the line and the amount required to turn to orientate the line straight.

After tweaking the algorithm to instead applying relative yaw control from the Pi to the Arduino we were able to achieve pretty accurate results in following a straight and even curved lines.

Sadly we did not take videos of our successful runs until the dunking incident. That’s it for part I of our final I will be blogging on part II again which will talk about our finals! Stay tuned!


Going for one of the test runs


Setting up one of the tougher obstacles of the course in the tank for testing after we had our line tracking successfully done. Sadly due to various delays in the testing and also accidentally allowing water to seep into our ship caused us not to be able to get this portion of the course working.


Opening up our Tupperware Coconut Pi for inspection and fixes on the internal circuitry.


Deadbeat at three am in the morning. We had continuously only 2-3 three hours of sleep for the last week leading up to the competition and camped over night at the water tank in school


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s