Moving 4 Wheel Drive for Autonomous

I haven’t been programming for a while and just started using Vexcode Pro. How do you move all four motors in a four wheel drive forward – for some reason, it seems that when I run the code below only the Left Motors move at all.
FrontLeftMotor.spinFor(forward, 500, deg);
BackLeftMotor.spinFor(forward, 500, deg);
FrontRightMotor.spinFor(forward, 500, deg);
BackRightMotor.spinFor(forward, 500, deg);

If you are talking about driver control you can use the joy sticks to move the robot similar to this:

 FrontRight.spin(forward, 120 * Controller1.Axis2.position(percent), voltageUnits::mV); 

The controller is sending a -100 to 100 and times 120 at its max = 12000 and 12000 mv is 12 which is max power.

An important note is that you would also need to make sure that you have configured the motor directions correctly. Often the right side of the drive needs to have its motor “forward” directions swapped. You can do this by clicking the little robot configuration menu and then selecting the motor you would like invert direction and click the slider.

The reason that your code might not be working is that you might be trying to spin in the opposite direction of the 500 deg mark.

1 Like

I already have the the driver control programmed and for some reason if works perfectly fine. The code I was testing out was meant for autonomous, is there a reason why I can’t sync the motors?

the only thing that I can think of right now is what I mentioned before at the end. you might be trying to spin to -500 deg on the right motor rather than 500 because your forward is different

I feel like this shouldn’t be the problem since I already have the right motors reversed and all four motors are facing the same direction when we built it. When I ran that random code I had above it wasn’t that the right motors were moving backwards, they weren’t moving at all

It isn’t the problem. The problem is that spinFor doesn’t run the next command until the current command is done. If you let the program run, you should see each of your motors spin 1 at a time for 500 degrees.

2 Likes

Is there a way to make all of the motors spin simultaneously then, what function is best for this?

Kashmir that since you didn’t now this you are new to code (not trying to be offensive just make things easiest). The best way to do it would be to make motor groups and then use spin for.

Drive(Motor1, motor2, motor3…);
Drive.spinFor(500, degrees);

1 Like

Yeah, I’ve never used Vexcode before. It says in my compiler that Drive is undeclared. How would I do this?

Try adding false at the end of the first three lines. If I recall correctly, spinFor (degrees) is a blocking command, which means it will prevent any code under it to run before the current command if finished. By adding the false at the end, the code below it will run as well.

So it would be
FrontLeftMotor.spinFor(forward, 500, deg, false);
BackLeftMotor.spinFor(forward, 500, deg, false);
FrontRightMotor.spinFor(forward, 500, deg, false);
BackRightMotor.spinFor(forward, 500, deg);

5 Likes

Drive is a motor group. You have to define it.

motor_group Drive(rightFront,rightBack, leftBack, leftFront);

This should be correct for your motors.

1 Like