Coding 3rd motor differential gear to run on drivetrain only in Fwd/Rev not for turns

We are using RobotC graphical and are trying to figure out code to add a 3rd motor to the drivetrain that operates only when both joysticks are pushed forward or both are pushed back. The motor needs to NOT be on when only 1 joystick is being used or when 1 is forward and 1 is back, so we can’t just add it to one side of the drivetrain. Motor2 operates a motor attached to a differential gear attached to both front sprockets, and if it is running while turning it jams things up. If it isn’t running (stop motor?) then it turns fine (so if using only tank control with no reference to motor2 all actions work - but we lose the benfit of an extra motor in fwd/rev!). Motor1 and motor6 are attached to back sprockets on a tank tread drivetrain.

We’ve tried lots of variations at this point but we keep having the same problem. Forward and reverse work well with the added motor, 1 joystick forward and 1 joystick backward turns decently (with motor2 not running), BUT if 1 joystick is forward (or backward) and the other untouched it jams. I assume that for some reason motor2 is remaining on and that’s what we’ve been trying to fix. It has similar symptoms to how it originally jammed during 2 joystick turns, which we were eventually able to get fixed by using the attached code (which is supposed to stop motor2 for all turns).

I’m attaching code in graphical and regular, but we don’t have a lot of experience writing in regular and no real access to someone who does coding for robots with it. Is it possible to fix in graphical? I know the other is more advanced, but I don’t have a lot of time for us all to learn it before Regionals next weekend!

For extra credit :slight_smile: - is there any way to get a differential gear on the drivetrain to be running while doing turns (adding power to the side going forward in the turn without jamming the side going backwards)? We did lots of research and various experiments leading up to that change and really thought it could, so we were disappointed to determine in actual practice that we couldn’t get it to work as expected. It still helps with power on fwd/rev, but without turning power we can’t up our gear ratio for adding speed.


difftestc.pdf (199 KB)


Using a differential this way can be very complicated. I’m impressed with the progress your team’s made. Now, they just need to accurately understand exactly what speed they want Motor 2 to run at all times.

To get a slightly better idea, remove motor 2, turn the robot over (so the differential can be seen) and run the other motors using the joysticks. You should be able to see exactly when the differential moves and when it doesn’t.

Should observe: both joysticks forward: diff forward
Both joysticks back: diff back
joysticks opposite: diff doesn’t move
one joystick forward: (this case you haven’t exactly identified, yet) the diff should move forward at 1/2 speed

At this point, you may be able to figure out the pattern.
A: 100, D:100, diff 100
A: -100, D:-100, diff -100
A: 100, D -100: diff: 0
A: 0, D: 100, diff: 50

So, the differential speed is always the average of joystick A + joystick D or (A+D)/2

Here’s a text version:

repeat (forever) {
tankControl(ChA, ChD, 10);
M2 = getJoystickValue(ChA) + getJoystickValue(ChD);
M2 = M2 / 2;
setMotor(motor2, M2);

M2 is a variable, and the two lines starting with M2 are variable expressions. It should be pretty easy to create this in the graphic language, also.

For extra credit, Not really. This configuration can help it turn if you’re only moving one joystick, but not if you’re turning by moving joysticks opposite directions.

Motor 2 and the differential could be geared to help with turns, but then it wouldn’t help driving in a straight line. That’s a different mechanical setup.

Hope that helps

Thank you so much - that worked perfectly!! My son & I weren’t able to code it in graphical (it only allowed M2 to equal a single value and not a value plus a value, and we couldn’t figure out how to get around that), but we converted our regular drive program from graphical to RobotC and added the code you indicated above. After some experimenting, we even figured out that we needed to add “float M2;” to the top in order for it to compile correctly. It is now functioning exactly as we have been trying to get it to all week, so at the next meeting we’ll be able to share what we’ve learned with the team and walk through your demonstration. Thank you again!

In graphical, there are “variable expressions”. They will allow the calculations I used.

Glad to hear it works