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;
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.
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.
Okay. This is outside of what we have examples for but I can give you a little guidance.
You can use a brushed ESC that works similarly to the brushless ESC and is controlled with a PWM signal. Here’s an example: Pololu Simple Motor Controller 18v7. This one should work with the code that I sent.
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.
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.