ROBOTC.net forums
http://robotc.net/forums/

Using the average of two motor encoders to move the robot?
http://robotc.net/forums/viewtopic.php?f=52&t=10253
Page 1 of 1

Author:  Cyks [ Tue Jan 13, 2015 5:24 pm ]
Post subject:  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! :biggrin:

Author:  BurningLights [ Tue Jan 13, 2015 5:52 pm ]
Post subject:  Re: Using the average of two motor encoders to move the robo

It looks like you've pretty much got it, except that you're missing a set of parenthesis. You need your loop condition to be
Code:
while ((nMotorEncoder[motorE] + nMotorEncoder[motorF]) / 2 > -360)

because otherwise it's adding half of the encoder value of motorF to the full encoder value of motorE, which is definitely not what you want!! :shock:

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/