
Using the average of two motor encoders to move the robot?
Right now our robot has two motors on the right side and two on the left side. Both motors on each side were connected to the same port in the motor controller. So the program could just move the left or right side and it would move both motors on that side. We have decided to connect all four motors separately so that we can use the average of both motor's encoders to make encoder movement more accurate.
How our encoder movement code was before to move the robot straight:
while (nMotorEncoder[motorE] > -360)
{
motor[motorE] = -20;//left side of robot
motor[motorG] = 20;//right side of robot
}
motor[motorE] = 0;
motor[motorG] = 0;
How we want to code our new motors using the average of two encoders:
while (nMotorEncoder[motorE] + nMotorEncoder[motorF] / 2 > -360)
{
motor[motorE] = -20;//left side of robot
motor[motorF] = -20;//------
motor[motorG] = 20;//------
motor[motorH] = 20;//right side of robot
}
motor[motorE] = 0;
motor[motorG] = 0;
Is it possible to use the average value of two encoders to move the robot like this? If so, could someone please provide an example of how you would code that? Thank you!
