Help coding 3 motor ROV

Anything to do with programing the Arduino Platform.
Post Reply
soyboy97
Posts: 2
Joined: Feb 28th, 2019, 5:39 am

Help coding 3 motor ROV

Post by soyboy97 »

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.
User avatar
Bennachie
Posts: 113
Joined: Jul 6th, 2018, 11:38 am

Re: Help coding 3 motor ROV

Post by Bennachie »

Hi, you should just need two PWMs per motor.

Each PWM signal feeds two of the MOSFETs. See attached diagram.

-----

Also, I'm not sure your use of the joysticks is the most logical. It might be easier to use the left joystick to control the left motor, and the right joystick to control the right motor, the same way that a tank is driven. That way you steer left/right by moving the joysticks in opposite directions. Your coding then becomes a lot simpler. If you do it the way you propose, you either have to mix your inputs from the two joysticks, which can get complicated, or you can't go forwards/backwards and steer at the same time.

Of course, I'm assuming that you are using the usual thruster layout of one on the left side of the ROV and one on the right. From your description, you may be proposing to use one thruster for forwards/reverse, and one to steer the ROV. An odd layout, but it could work. Which is it?
Attachments
H bridge motor driver
H bridge motor driver
HBridge.jpg (27.01 KiB) Viewed 6302 times
Post Reply