Home        Store        Docs        Blog

ROV 3 motor coding help!

(Paul) #1

Hi, Im helping to build an ROV for a local competition but have ran into some difficulty. My role is to provide code to help the motors operate. The motors will run off of 3, 2 input H-bridges with mosfets…

How many pwm pins should the rov need per motor? Ive been told from some people that each motor should require 2 pwm pins (Forward & Back), although ive heard from another source that each motor should have 4 pins.

FYI the ROV is to be controlled by 2 Joysticks, the left joystick will control the forwards and backwards motion of the rov when pressed up&down, and will control the vertical motion of the rov when pushed left/right. The right joystick will turn the rov.

#include <Servo.h>

// Joystick Settings
static const int JS_CENTER_0 = 511; // Analog reading at center, 0-1023
static const int JS_CENTER_1 = 511;
static const int JS_CENTER_2 = 511;
static const int JS_RANGE_0 = 128; // Analog range, 0-1023
static const int JS_RANGE_1 = 128; //
static const int JS_RANGE_2 = 128;
static const int JS_DIR_0 = 1; // +1 or -1
static const int JS_DIR_1 = 1;
static const int JS_DIR_2 = 1;

// Arduino Pins
static const byte JS_ADC_0 = A0;
static const byte JS_ADC_1 = A1;
static const byte JS_ADC_2 = A2;
static const byte THRUSTER_LEFT_FWD = 9;
static const byte THRUSTER_LEFT_REV = 5;
static const byte THRUSTER_RIGHT_FWD = 3;
static const byte THRUSTER_RIGHT_REV = 10;
static const byte THRUSTER_VERTICAL_UP = 11;
static const byte THRUSTER_VERTICAL_DOWN = 12;

// Servos
Servo thrusterLeftForward;
Servo thrusterLeftReverse;
Servo thrusterRightForward;
Servo thrusterRightReverse;
Servo thrusterVerticalUp;
Servo thrusterVerticalDown;

That’s the code I have so far, If anyone has any tips on where to go now then that would be really helpful.

(Rusty) #2

Hi Paul,

You just need one pin and one Servo per thruster. You can check out some similar example code here that shows you how to operate the thrusters with analog joystick input.

Instructions: https://github.com/bluerobotics/br-esc-examples/tree/master/arduino/AnalogJoystickControl

Code: https://github.com/bluerobotics/br-esc-examples/blob/master/arduino/AnalogJoystickControl/AnalogJoystickControl.ino

-Rusty

(Paul) #3

Hi Rusty,

Thanks a lot for your quick response.

Does that code allow for forward and backwards motion?

Also, I don’t think we are using ESC’s, will that make much of a difference to that code?

Paul

(Rusty) #4

Hi Paul,

Yes, this code will allow forward and backward motion. Are you using our thrusters? If so, they are brushless motors and require speed controllers (ESCs) to operate. If you are using brushed motors, like a bilge pump motor, then the code will have to be different.

-Rusty

(Paul) #5

Hi rusty,

I’ve just checked with fellow group members and we are indeed using brushed motors… Will the code need to be modified a lot?

Thanks
Paul

(Rusty) #6

Hi Paul,

Okay. This is outside of what we have examples for but I can give you a little guidance.

  1. You can use a brushed ESC that works similarly to the brushless ESC and is controlled with a PWM signal. Here’s an example: https://www.pololu.com/product/1373. This one should work with the code that I sent.

  2. You can build your own H-bridge to control the motor. I wouldn’t recommend this option as there are some subtleties that can cause big issues.

-Rusty

(Paul) #7

Hi Rusty,

We have designed our own H-bridge to control the motor, each H-bridge has 2 inputs.

Is there any examples of code that would guide me in the right path? Thanks again.

Paul

(Rusty) #8

Hi Paul,

Okay, cool. I’m sure you can find examples of how to use an H-bridge with an Arduino. I would work on getting the motors spinning first and then start adding the ability to control them.

-Rusty