View unanswered posts | View active topics It is currently Sun Apr 26, 2015 10:28 pm






Reply to topic  [ 2 posts ] 
Using the average of two motor encoders to move the robot? 
Author Message
Rookie

Joined: Mon Dec 15, 2014 9:48 pm
Posts: 16
Post 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:


Tue Jan 13, 2015 5:24 pm
Profile
Professor
User avatar

Joined: Sat Aug 31, 2013 9:15 am
Posts: 256
Post 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:

_________________
FTC Team 6100 Chariots of Fire - Programmer (2012-2013)
FTC Team 7468 Blue Chariots of Fire - Programmer (2013-2014)
FTC Team 7468 Blue Chariots of Fire - Mentor (2014-2015)
Check out our team website at http://bluechariotsoffire.com/.


Tue Jan 13, 2015 5:52 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.