Skip to content

1.9 Thruster Code Introduction

John-Paul Chouery edited this page Aug 24, 2024 · 3 revisions

Our power board is a crucial component that powers up all the elements on the robot. Among its functionalities, it includes a microcontroller unit (MCU) that controls the eight thrusters of the robot. In this section, we will demonstrate how to power up one thruster.

Code to Power Up a Thruster

Here's the code that controls the thruster:

#include <Servo.h>

byte servoPin = 9; // Pin connected to the thruster's ESC
Servo servo;

void setup() {
	servo.attach(servoPin); // Attach the servo (ESC) to the specified pin

	servo.writeMicroseconds(1500); // Send "stop" signal to ESC.

	delay(7000); // Delay to allow the ESC to recognize the stopped signal
}

void loop() {
	int signal = 1540; // Set signal value, which should be between 1100 and 1900

	servo.writeMicroseconds(signal); // Send signal to ESC.
}

Key Components of the Code

1. Libraries

We include the Servo.h library to simplify controlling the ESC connected to the thruster. This library provides the necessary functions to send pulse-width modulation (PWM) signals.

2. Servo Object

The Servo object is created to manage the connection to the thruster's electronic speed controller (ESC). This object allows us to control the thruster's behavior through PWM signals.

3. Setup Function

In the setup() function, we attach the ESC to the specified pin and send an initial signal of 1500 microseconds to stop the thruster. The delay allows the ESC to recognize this stop signal before we begin sending further commands.

4. Loop Function

In the loop() function, we set a signal value of 1540 microseconds, which activates the thruster. This signal can be adjusted to control the speed and direction of the thruster.

Understanding ESC and Thruster

An electronic speed controller (ESC) is a device that regulates the speed of an electric motor, in this case, a thruster. When we send a signal of 1500 microseconds, the thrusters arm, and we hear beeps from the ESC. Each beep signifies the ESC is ready to accept commands.

  • First 3 beeps: servos are powered up
  • 4th beep: signal detected
  • 5th beep: arming sequence detected (pwm value of 1500)

Sending a signal above 1500 microseconds will increase the thruster's speed, while sending a signal below 1500 microseconds will reverse the direction. Adjusting the signal between 1100 and 1900 microseconds changes the speed and direction of the thrusters.

Understanding PWM

Pulse-width modulation (PWM) is a technique used to control the amount of power delivered to an electrical device. By varying the width of the pulse, we can adjust the average voltage and, consequently, the speed of the thruster. The MCU uses timers to generate these precise PWM signals, allowing for smooth control of the thrusters.

For more information about ESCs and sample code, refer to this link from Blue Robotics, the manufacturer of our thruster and ESC: Blue Robotics ESC R3 Example Code for Arduino. This is the basic code from which we wrote our code.

Clone this wiki locally