View Single Post
  #7   Spotlight this post!  
Unread 13-02-2015, 10:46
Ozuru's Avatar
Ozuru Ozuru is offline
It's always the programmer's fault.
no team
 
Join Date: May 2013
Rookie Year: 2010
Location: Earth
Posts: 268
Ozuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to behold
Re: Encoders and rpm

I have a DriveForDistance method that uses encoders. I'm assuming you're using command based. Think of what you want to do:

1. Clear the current count of the encoders
Code:
I recommend you create a method in your driveTrain called clearEncoders():
public void clearEncoder() {
		_leftEncoder.reset();
		_rightEncoder.reset();
}

While you're in your drive train subsystem, go ahead and create getter methods for your encoders.

public double getRightDistance() {
		return _rightEncoder.getDistance();
}
In your initialize, you want to clear the encoders.

In your execute, you want to tell the motors to go the appropriate direction that the robot should be moving.

In your isFinished:

Code:
// code from Joe 2729
double left = Robot._driveTrain.getLeftDistance();
    	double right = Robot._driveTrain.getRightDistance();
    	double distance = Math.abs(left) > Math.abs(right) ? left : right;
    	if(_forw) {
    		return distance >= _distance;
    	} else {
    		return distance <= _distance;
}
That's how the general layout of your program should be if you want to drive for a distance.
Reply With Quote