Hi Mike,
I assume you are referring to this example code.
First, what kind of control are you looking for in your ROV? The simple 3-thruster ROVs targeted by that code are capable of forward/reverse, up/down, and yaw control. 4-thruster ROVs with two side-by-side vertical thrusters as shown in QGC are capable of all three as well as roll control, although in our experience roll is not nearly as important as the other three controls. Are you looking to directly adapt the code to behave the same on your 4-thruster ROV as it would on a 3-thruster ROV (i.e. forward/reverse, up/down, and yaw), or do you wish to also add roll control?
If you just want to add the fourth thruster without adding roll control, modifying the example code is pretty straightforward. You just need the second vertical thruster to act exactly the same as the first one. Add a new servo object for your fourth thruster (for example thrusterVertical2
), define which pin it should be on (say, pin 12), attach the servo to the pin, and then duplicate every line concerning thrusterVertical for thrusterVertical2 (i.e. thrusterVertical2.writeMicroseconds(...);
), and the two thrusters should do the same thing.
As a side note, you don’t actually need to modify the code to do this: the same PWM output can be used for both vertical thrusters. Just split the signal coming off of pin 11 and send it to both of your vertical thrusters’ ESCs.
If you want to add roll control, you will first need to duplicate all the lines concerning the joystick inputs (lines 42~50, 59~61) for your fourth joystick axis, then duplicate the lines that convert the raw joystick values to input commands (92~106) to calculate the rollCommand
from your fourth joystick input. Like the above case, you will need to create a new servo object as well (I recommend differentiating them as thrusterVerticalLeft
and thrusterVerticalRight
). Much like the left/right thruster controls, you will need to combine the vertical and roll control inputs:
thrusterVerticalLeft.writeMicroseconds(CENTER_THROTTLE+verticalCommand+rollCommand);
thrusterVerticalRight.writeMicroseconds(CENTER_THROTTLE+verticalCommand-rollCommand);
The signs of the rollCommand
terms don’t really matter, so long as one is positive and one is negative. If the ROV rolls the wrong way, just swap the signs.