Home > Other >Special Application Circuits > Underwater drone design based on Raspberry Pi

Underwater drone design based on Raspberry Pi

Source: InternetPublisher:toothache Keywords: drone raspberry pi Updated: 2024/03/01

This article describes the design process, development, and assembly operations of a prototype underwater drone powered by a Raspberry Pi.

I watch a lot of shows about inventors on the Discovery Channel and one time I decided to do something fun myself that would be really impressive and difficult all at once: some motors, controllers, processing, cameras. After buying a lot of useful (and not so useful) stuff, I started thinking about what kind of project I should start. In the end I came to the conclusion that there was a lot of flying and flying drones, but not about underwater drones (haha, looking back, I couldn't have been more wrong).

After surfing the web, I found several interesting projects, but most of them are either in the development stage or not cheap.

Looking to the future, I can say that I have a working prototype that can swim several meters deep, albeit with some pros and cons. I can't claim that I finally have something that's easy to control, or that can do more than quell my engineering zeal. But all the units of this stuff work, and it's very important in my opinion that my mistakes and experience can help someone create something that really matters (even if it only means something to himself).

Due to a large amount of work, this article can be divided into the following chapters:

Select components

ESC programming

Raspberry Pi server configuration

Working with electric motors using a Raspberry Pi

Gyro

Raspberry Pi flashlight control

client-server communication protocol

Android App

video streaming

Screen and joystick controls

Construction assembly and testing

in conclusion

Select components

Below you will find a list of the different things used to create your device.

motherboard

Among the many controllers, I chose the Raspberry Pi 3B. I would not recommend an Arduino-like board for this project as it will not manage such complex tasks as one needs to control at least 4 motors, diodes, gyroscopes, send video streams from the camera and simultaneously receive and process commands from the control device . The Raspberry Pi 3B comes with built-in Wi-Fi and Ethernet for RJ-45 connectors, which will definitely help you do all this.

connection channel

Transmitting data underwater is always difficult. Water is a good shield, so you can forget about any wireless data transmission. So there is no other option.

The ability to transmit data underwater.

The speed of underwater data transmission.

Versatility (it works great with Raspberry Pi 3B and transmitters).

base transmitter

The NEXX mini router has 3 main transmission options:

There are many points of contention when trying to connect a Wi-Fi antenna from water to land (in which case you should use solid wire rather than twisted pair).

Create a client-server bridge connection between the two Raspberry Pi 3Bs (this would be suitable, but more expensive and cumbersome).

Connect the mini-router to the Raspberry using twisted pair cable. This option is used as a basis because it is the most reliable, fastest and cheapest. Experience shows that this is a pretty good choice.

electric motor

N2830/2212 1000KV

After testing 3 different motors I chose this model. You may ask why? Because it is powerful enough, it has a second shaft so you can use 2 propellers at the same time. Generally speaking, all motors run normally in water until algae or sand gets inside the motor. If you choose a high-speed, less powerful motor, you will find that these types of motors are not the best for water. The cheaper motor also fell short of expectations.

Control Panel (ESC)

African ESC (30A)

This is also very simple. It can be programmed to switch forward/reverse, and 30 amps should be enough for the motor under test.

Afro ESC USB programming tool

Programming tool for ESC. Using this device you can upload the necessary firmware. But actually, that's the problem. I had to wait a month and a half.

LED pulse driver

7-30В 3А or similar

This is perfect for our purposes - it holds two of the aforementioned LEDs, and it also connects to the Raspberry and allows you to adjust the brightness of the LEDs.

Gyro

MPU-6050

A three-axis gyroscope/accelerometer that sends position data to the Raspberry. There is some data, but not very useful ☺.

camera

RPi Camera F

You can use any other native Raspberry Pi camera. The main condition is that it should be connected via FFC, not USB. Video streaming has always been a big problem (latency, encoding), or rather it's not a problem, it just takes a lot of time to get going.

joystick

iPega PG-9055 - Extra control assistant, if your hands are wet, and trust me, they will be, you can control the drone using this device.

Battery

Turnigy 2200mAh 3S 30C

Again lots of testing. 18650 batteries are not suitable because the controller has a discharge rate of 25A, which is not enough for the entire system under peak load conditions (yes, several batteries died after use). It's possible to try using 6 batteries and get 50A, but it's more difficult. Such direct current cannot be transmitted using wires (don't forget the distance of about 100 m). So I bought the Li-Po and it does the job elegantly and blends into the case perfectly.

Driving the propeller (one of the main problems)

Cable Connector

There are also cases, connectors, wires, and other stuff.

ESC programming

Unfortunately, the new Afro ESC only rotates in one direction, so you'll need to update the firmware.

It is important to connect the wires correctly now, otherwise one of the devices may malfunction.

Here you will find some brief instructions on how to connect the wires correctly:

A pair of thick red and black wires with a male connector on the end. It is a universal power supply. In this case, the power supplied will be 12V and the required amperage.

Red - Input port "+".

Black – Input port “-”.

A thick red, black and yellow wire is responsible for power to the motor. We won't connect them now, but later we will connect these wires to the wires from the motor that have similar colors.

Thin wires are responsible for controlling the circuit board.

Control signals are transmitted via the yellow wire.

The red wire outputs 5v (I haven't used it). There are several different types of them, you can learn more about them here.

The black wire should be connected to port "-".

So let's connect the thin wires to the linker: connect the black wire (minus sign) and the yellow wire (signal) together. Do not touch or connect the red wires together. Next step - provide power to the board (black and red thick inputs). I used this static power supply unit, but any other power supply with similar characteristics will do (12V, 2+A).

Open the firmware update tool and select:

Port: Select the USB port to connect to. Fortunately, there are only a few options.

Baud rate: 9600.

Controller: atmega 8 based brushless ESC (8kB flash).

Select the downloaded firmware file. Click the "Run" button and pray :)

Soon the firmware will be successfully uploaded to the ESC and everything is ready.

Working with electric motors using a Raspberry Pi

One important thing is that if you are building a serious project and not just for fun, you don't have to use the Raspberry PI for real-time work, such as motor processing. The PWM generation won't work as you expect, so use a separate board such as an Arduino for control. But for my project, using Raspberry is enough. Thanks to Fabio Balzano for explaining this in the comments below this article.

So, let's get started with the most interesting part of our job - we should write the code for the Raspberry Pi control. Find the project folder ~/drone and install the PiGpio library there:

Now I will give you some brief information about ESC control. We should transfer a certain frequency to the thin yellow wire (control) (see section "ESC Programming"). The range of afro_nfet_besc30_r1 firmware is 1100-1900, where the value 1500 is the calm state, 1100 is the maximum reverse direction, and 1900 is the maximum forward direction. Create the file engines.js and add the JS code to it:

//Calm state constant
const SERVO_ZERO = 1500;
//Connect ’pigpio’ library
const Gpio = require(’pigpio’).Gpio;
// Define 4 motors using Raspberry pins (this process will be described below)
const servo1 = new Gpio(22, {mode: Gpio.OUTPUT});
const servo2 = new Gpio(10, {mode: Gpio.OUTPUT});
const servo3 = new Gpio(9, {mode: Gpio.OUTPUT});
const servo4 = new Gpio(27, {mode: Gpio.OUTPUT});
//Set each board into the state of "calm"
servo1.servoWrite(SERVO_ZERO);
servo2.servoWrite(SERVO_ZERO);
servo3.servoWrite(SERVO_ZERO);
servo4.servoWrite(SERVO_ZERO);
//After that you should enter the value into ESC
module.exports.engines = {
leftEsc: (value) => {
servo1.servoWrite(value);
},
rightEsc: (value) => {
servo2.servoWrite(value);
},
topLeftEsc: (value) => {
servo3.servoWrite(value);
},
topRightEsc: (value) => {
servo4.servoWrite(value);
}
}

为了使用此代码,您应该在app.js中编写:

实际上这部分代码servo1.servoWrite()负责控制。1100 - 电机反向转动,1900 - 最大正向转动。

在这里您可以找到 Raspberry pin 方案:

简而言之,你应该使用橙色的 GPIO。一对由 GPIO 10 和 GPIO 22 组成,第二对是 GPIO 9 和 GPIO 27(使用 27、22 和 10 -9 会更合乎逻辑,但我在焊接时没有考虑到,所以我不得不更改它)。如果考虑序数(它们是灰色的),那么这些是 13、15 和 19、21 联系人。您应该将 ESC 的黄线连接到它们中的每一个,负号应连接到一个 GND,例如 39 触点。现在让我们连接其他的东西。

将Afro ESC的电源线(红色和黑色)连接到单独的电源单元(12v),将电机连接到黄-红-黑粗线,现在您可以尝试它是如何工作的。

陀螺仪

连接示例:

VCC到引脚 1 (3.3V PWR)

GND到任何负号

SCL到引脚 5 (GPIO 3)

SDA到引脚 3 (GPIO 2)

正确连接一切并不难,如果谈论软件——它会更简单——所有信息都可以在互联网上轻松找到。在这里你应该使用i2c-bus и i2c-mpu6050库。将它们安装到项目中:

创建文件gyroscope.js并添加:

const i2c = require(’i2c-bus’);
const MPU6050 = require(’i2c-mpu6050’);
const address = 0x68;
const i2c1 = i2c.openSync(1);
const sensor = new MPU6050(i2c1, address);
var reading = false;
var sensorData = {};
module.exports.gyroscope = {
getData : () => {
return JSON.stringify(sensorData);
},
readRotation : () => {
sensor.readRotation(function (err, rot) {
 if (err) {
  console.log(e);
  return;
 }
 console.log(rot);
});
},
readSensor : () => {
if (!reading) {
 reading = true;
}
sensor.read(function (err, data) {
 reading = false;
 if (err) {
  console.log(err);
 } else {
  sensorData = data;
 }
});
}
}

以一定的频率运行 readSensor 方法,并从 getData 获取上次调查的数据。会有很多位置分量(x,y,z,a)。我没有足够的时间来定义这些组件的含义,因为我有更重要的任务——处理。我知道调查它会更好,但结果的相关性对于当时的这个项目来说并不是很重要。

树莓派手电筒控制

So, let's go ahead and add functionality to our drone, and now I'm going to introduce you to LEDs. I have two XHP-50 LEDs and an LED pulse driver (see table above). They overheat easily, so I recommend using them with a radiator. You can find them in the same online store, the main thing is not to forget about the size. So, connect the LEDs to the heatsink, use wires to solder the negative terminal of one LED to the positive terminal of the other LED (they are labeled) and solder the - and + wires:

Controller and welding:

Power supply - 12V positive and negative, you can use the same input as the motor. The LED connector should be connected to the previously soldered connector, L- to negative and L+ to positive. In this case we don't need the analog contact (A), so don't connect it.

Now we are interested in the digital input (D) and the ground input (G). Now you should connect the digital input (D) to GPIO11 and the ground input (G) to GND (you can choose whatever you want on the Raspberry).

Now let's go back to the Raspberry Pi, create a file light.js and add the following content:

//Again the same library
const Gpio = require('pigpio').Gpio;
//Create Gpio for your pin
const light = new Gpio(11, {mode: Gpio.OUTPUT});
// You can set the value starting from 0 to 255 (I have found this info in the LED driver instructions)
const LIGHT_MIN = 0;
const LIGHT_MAX = 255;
//It will be needed for calculations
const LIGHT_DIAPASONE = LIGHT_MAX - LIGHT_MIN;
// Turn off the LED (the system starts with the LEDs turned on to maximum)
light.pwmWrite(LIGHT_MIN);
//Export work methods
module.exports.light = {
on: () => {
//Transmit the value 255 to the driver
light.pwmWrite(LIGHT_MAX) ;
},
off: () => {
// Transmit the value 0 to the driver
light.pwmWrite(LIGHT_MIN);
},
//Here will be the percent value from 0 to 100
set: (val) => {
if( val < 0 || val > 100) return;
//Calculate the value based on the percentage
val = Math.round(LIGHT_MIN + LIGHT_DIAPASONE / 100 * val);
console.log("Light:"+val);
//Transmit the value to the driver
light.pwmWrite(val);
}
}

We can run it using app.js or the engine:

client-server communication protocol

As you know from the initial configuration of the Raspberry Pi, communication will take place using socket connections. You'll also need some set of commands hardcoded in the server and client. When I was doing everything myself, I decided to use my own format since the options that existed didn't quite match the weight/readability criteria. So let's build it with the control model in mind, which in this case will be an Android smartphone.

Here you can find the model itself (the application will be described below).

The screen is divided into two parts. The left part represents the horizontal axis (front and back) and the right part represents the vertical axis. If you place your finger on a certain area, this is considered a reference point and is controlled by a pair of motors, but it is also a "calm" point.

If you slide your finger vertically upwards, the forward rotation speed of both motors will slowly increase with power from 0 to maximum (depending on the distance from the point of contact to the current point).

If you slide your finger down, the two motors will rotate in opposite directions at a speed that depends on the distance from the point of contact.

If you slide your finger to the right, the left motor will spin forward, while the right motor will spin in the opposite direction. So, actually, we need to know the angle away from the contact point (where top=90, bottom=90, right=0, left=180) and the speed ratio - the distance from the finger to the contact point (from 0 to 100). The object command should look like this:

С - (command), any command should start with this letter;

: - key-value separator;

; - delimiter of key-value pairs;

L - indicates the touch was made on the left side of the screen;

R - means the touch was made on the right side of the screen;

LIGHT——represents light:)

A——ANGLE, deviation angle;

V - value, the value of something.

So the first command sounds like: "Pair of horizontal motors, orientation - 45 degrees (left motor at maximum speed (but 35% of maximum, based on V), right motor stopped), rotating at 35% of maximum speed ".

Second command: "Vertical motor pair, direction - 0 degrees (left motor maximum speed, right motor reverse maximum speed), maximum speed".

Third command: "Turn on light at 50% brightness".

This is how it works when you send a separate command for each value change over a socket in a key-value block. Then magically turns into a command on the control board. Interpreting transformations of these data would be boring. So you can try to study it yourself and master the controller.

Android App

Finally, we've reached the point where we're trying to create the controller. Generally speaking, communication means: "click something on the screen - transfer the value to the server". I'll write a little bit about the app. Nothing unusual or particularly challenging, so I won't post all the code. If you wish, you can access the repository and find the information you need. I also want to point out that I am not using any newfangled patterns like MVVM, MVP, VIPER, etc. because I need the application to work in minimum time. The UI is as simple as possible.

First, you should create an activity with a state display view. The layout is as follows:

Video display layer (player encapsulated in a fragment).

The JoystickView layer is a custom view in which the dispatchTouchEvent method is overridden, which handles the pressing and movement of the finger on the screen. It draws the UI line from the pressed point to the current state. Multi-touch support is mandatory as controls are performed with two fingers.

A layer with a TextView of the current temperature of the Raspberry Pi (if something goes wrong and it starts to overheat, you can stop using it before it shuts down/burns). Fortunately, this didn't happen with my Raspberry.

Data layer for gyroscope display. A TextView set in a label value pair. It displays "raw data" from the gyroscope. The plan is to process this data, but I don't have enough time to do it and invent a cool display for it.

A SeekBar layer - LED control, a simple element that changes the value from 0 to 100 when dragged.

Construction assembly and testing

Now we've reached the next step - we need to find something where we can place all the things mentioned above (haha). My friend Sergey helped me a lot during the design and assembly stages. He actually found a housing and made an iron platform where we could mount the motors in different positions and then put them together:

I started by saying that a prototype with 6 motors would be more efficient, but for me it was difficult to support the prototype even with 4 motors, that's why it was decided to test the prototype with 4 motors.

First we decided to test the construction of the case, that's why instead of putting all the electronics inside the case we simply connected the motors to the platform with two pairs of twisted wires sending signals from the ESC to each of them ( The ESC remained inland during testing).

in conclusion

The main result of all this is that I gained extensive experience in building such units and systems. There are a lot of different devices used in the development process, and managing them is much easier than it looks. The four-motor prototype didn't work as well as expected - it's very difficult to control such a device. It's best to use four vertical motors and at least two horizontal motors. At the same time, it should be stabilized with a gyroscope, since it is difficult for a human to control it perfectly and requires help (the same goes for flying drones).

Furthermore, all motors on sale are clogged with sand and other stuff, all units can be damaged by corrosion (which is logical) and are not suitable for such projects. I didn't find an underwater motor (which would suggest it's waterproof, but it only works properly at a depth of 1-2 meters). After this project, any smart home won't seem that complicated anymore. Server, relaying commands, that's it. The main thing you need is the time and desire to do it. The rest will follow.

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号