4 Encoders

Is there any way I wan program a robot to use 4 encoders each for a particular motor, and each particular motor moving a wheel (total of 4 wheels)? I was trying to program a robot for the autonomous period using a auto-straightening code and a while loop to set the robot to travel 1,200 degrees. I tried coding the left front motor and the right front motor using a while loop with an && statement making them stop at 1,200 degrees, the same was done for the back left motor and the back right motor. However the code seems to jump over parts of the code and just basically not even move the robot. I don’t know if I coded something wrong or not but if anyone can help me that would be great.

P.S. I attached a screenshot of what I have done.

Regards, Bryan



Frankly this code is not going to work, at all. The thing is with your auto straightening program, you have such a large change in the motor value to try and straighten out the drive that it’s going to over-correct a lot. This is going to result in a VERY jerky movement from the drive, almost as if it’s trying to swerve turn down a line. If you really need an auto straightening program for the drive then I would suggest PID control. That’s what we’re using on our robot this year and it’s a lot better than just going forward for a number of encoder counts. I just started learning and working with PID this year but now that I know how to do it I really wish I would have done it a long time ago(just in case you don’t want to do that kind of work; trust me, you’ll be glad you did)

Your robot doesn’t move because after you assign motor values to the drive you immediately assign another value telling them to shut off, resulting in a “dead robot.” Rather you need to have something like this:

while(sensorValue[quad encoder] < target)
{
motor[drive motor1] = 63;
motor[drive motor2] = 63;
motor[drive motor3] = 63;
motor[drive motor4] = 63;
}

motor[drive motor1] = 0;
motor[drive motor2] = 0;
motor[drive motor3] = 0;
motor[drive motor4] = 0;

This code will make the robot drive until the quad encoder you name above reaches the target; once that while loop goes false it will exit, looking for the next line of code to run, it will then find the command telling the motors to shut off and there you go, a simple move forward command using quad encoders.
As for the sideways movement your trying to do; it looks like your trying to use a time program so for that you just need to take out those unnecessary curly brackets and you should be good(it would also be good if you added a wait time in between the drive motors stop part and the sideways movement part just so that the motors don’t try and rapidly change values and jerk).

Hope this all makes sense to you and I hope you figure it out soon :slight_smile:
Btw, MartinMaVexForever’s YouTube channel has a very good PID tutorial.

try chaining your base as well

I forgot to mention; if you do decide to go for PID then you can take two of the encoders off the wheels so that you can just have 2 on either the front or the back wheels so that you have two extra quad’s to put somewhere else on the robot :slight_smile: