I needed to build a basic system which I could test out on a lake as a small prototype. The system was able to control the motor and rudder as well as know it’s speed and direction. There should be someway of controlling the boat from my laptop but also the ability to receive data so I can see what’s happening within the system. This article will go through the creation of the initial system.
Power, that’s the first thing required when putting the components together. I did spent ages reading about different batteries but for simplicity I borrowed components from my drone. I started with a 3S (11.1v) lipo battery. But the Raspberry Pi 3B+ requires 5v, so I used a voltage converter to reduce the power. When designing the power systems it’s important to not forget the current requirements, as the Pi can provide 1.2A of power across it’s USB ports and requires a maximum of 0.75A to boot, therefore a 2.5A power supply is recommended. At the moment I’ll be connecting some of my hardware to the Pi by USB, however I have a feeling that when I eventually attach more hardware it will need more than 1.2A of power. At this point, I’ll have to power the extra hardware externally and not from the Pi. The other point to consider is to ensure that your circuits/components can handle the currents. For example, we know from previous experiments that the motor could consume up to 7A, and on the real boat we are going to have 2 motors, so parts of the circuit already need to handle 14A. If they’re not rated for 14 A they might catch on fire!
I connected my 5V power to my Pi via micro-usb and installed Raspbian, however I received several low voltage warnings. It turns out that the quality of usb cable plays a major factor to ensuring that a significant voltage drop does not occur over the cable and reduce the voltage made available to the Pi. In the end I purchased the Ultrics Short Micro USB Cable, which has stopped the warnings.
Motor and ESC
Also using the motor from my drone (a SunnySky X2212-13 980kv II), I connected this to an electronic speed controller (ESC), which is used to drive brushless motors. This can be powered directly by the 11.1v and the input of the ESC is connected to a GPIO output (PWM capable) on the Pi. Sending PWM signals to the ESC with different duty cycles controls their speed. To send a PWM signal using Python the pigpio library was used. There’s a lot more to ESCs such as calibration and arming procedure, but I won’t go in to that now.
There are different types of ESCs that can be used and they mostly have to do with the firmware which controls how an ESCs responds. They’re mostly developed for drones, so the differences in these ESCs don’t affect us. However they do have drone-esque features, so if I stop sending a signal to the ESC it eventually starts beeping, which is designed to help when a drone is lost, but when it beeps during testing it’s quite annoying! There is a method to modify the settings but it’s not very straight forward. Although at the same time it means the motor can’t go in reverse either, because drones don’t need that feature!
The rudder is operated by a servo which has an arm that changes position, and when it’s powered the arm will stay in that position. The servo is also driven by a PWM signal, but directly, rather than requiring an ESC. It also uses 5v rather than 11.1v so there’s another voltage converter used to power it.
GPS and IMU
A Ublox GPS connects to the Pi over UART. Some software called GPSD then runs in the background on the Pi, which receives data from the GPS and parses the format, so the data is easily readable. Using Python, I can connect to GPSD over a socket and receive this data.
GPS is a rich data source which provides information such as speed, heading, altitude, rate of climb and sink, longitude, latitude and number of satellites in view.
An inertial measurement unit (IMU) is made up of several components. An accelerometer, which measures acceleration in a specific direction, a gyroscope, which measures angular velocity across 3 axes and a magnetometer which measures magnetic readings. If these readings are all fused together, they can produce accurate information about it’s orientation and direction of movement. The magnetometer is also a compass, so this will be used in tandem with the GPS as the GPS will tell us the heading the boat is moving in, whereas the compass will tell us the direction the boat is facing. Which if there are strong currents, it doesn’t mean the boat is moving in the direction in which it is facing.
The traditional approach to control a boat would be to use a radio controlled system, the style that you see for drones/model boats, however as this will be a robotic project it’s mostly going to control itself, so I didn’t want to go the extra lengths to install a radio controlled system that wasn’t going to be used much. Instead I decide to opt to use wifi which was already apart of the Raspberry pi. The boat generates it’s own hotspot, I connect to it with my laptop, and then can send commands to it over a network.
The disadvantage of wifi is that it’s range is limited, but this shouldn’t matter much as it will only be used for nearby testing. To ensure safety if the boat goes out of range or the connection drops the engines will stop, to ensure it doesn’t just plough forwards.
The commands for the boat are sent from a dashboard (building using R and Shiny) on my computer, but it also receives real time data from the boat and graphs it, so we can see information such as how much battery the boat has left or what speed it’s going, or how much current the motors are taking.
There’s also a Hologram Nova on board which allows for communication over 3G, but as my testing of this was a little buggy I didn’t want to rely on it for real-time manual control of the boat.
Whilst the boat sends live data back over wifi, it is also sends intermittent stats over the internet to a database. It’s been designed this way so when the boat is in the middle of the ocean it can report back it’s location every so often, and we can see the progress it’s making.
Internally the Pi creates a log of all the decisions and commands it makes to ensure that we can diagnose faults easily and make sure that what’s been programmed is working correctly. It also records data from all the sensors every second and stores it. This is so after a journey, an in depth analysis can be performed to see how the boat performed, and so that data can be used to develop new features.
Motor and Shaft Installation
To get to this stage I’ve read for countless hours on forums and watched many videos to learn as much as possible about boats, motors, propellers, batteries, engineering and more. One of the most difficult things about model boating appears to be installing the motor and shaft. If they aren’t aligned in a straight line the propeller shaft will rub against it’s casing, and as you can imagine, make a horrible noise and be less efficient. To avoid this difficulty with alignment I 3D printed a bracket for the motor and the shaft hole. The assumption being that seeing as it’s accurately printed the mount for the motor and hole for the shaft should be precisely aligned. The issue became that I made the mount adjustable so that I could install different motors on it, and by having this movement, along with some slightly bendable plastic meant that the shaft didn’t quite align correctly. Plus the fact that my 3D printer wasn’t large enough to print the whole piece in one go. So my plan was thwarted, however it’s just the prototype so it’s not that critical at this stage.
To secure all the components mounts were 3d printed and a bracket was printed to secure the servo.
With a basic control system in place, some more testing is required, but we can soon test it on the lake!