|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#16
|
||||
|
||||
|
Re: Encoders in Auto Mode
No, you must call SetDistancePerPulse for all four encoders after they are instantiated (as part of the encoder initialization). The parameter to SetDistancePerPulse must be calculated or experimented. Basically, one revolution of the encoder will give you x pulses (I forgot what the KOP encoder is, probably 1440 pulses per revolution), then you have to multiply with the gear ratio if the encoders are mounted on the motor side instead of the wheel side.
Code:
Do this in your encoder intiialization:
distancePerPulse = (wheel_diameter*PI/pulses_per_revolution)*gear_ratio;
leftfrontEncoder->SetDistancePerPulse(distancePerPulse);
leftrearEncoder->SetDistancePerPulse(distancePerPulse);
rightfrontEncoder->SetDistancePerPulse(distancePerPulse);
rightrearEncoder->SetDistancePerPulse(distnacePerPulse);
Then do this in your autonomous loop:
double distanceTraveled = (leftfrontEncoder->GetDistance() +
rightFrontEncoder->GetDistance() +
leftRearEncoder->GetDistance() +
rightRearEncoder->GetDistance())/4.0;
if (distanceTraveled < 60.0)
{
MecaumDrive_Polar(forwardPower, 0.0, 0.0);
}
else
{
MecaumDrive_Polar(0.0, 0.0, 0.0);
}
|
|
#17
|
||||
|
||||
|
Re: Encoders in Auto Mode
Quote:
|
|
#18
|
|||
|
|||
|
Re: Encoders in Auto Mode
Quote:
my question is isnt there any easier way of doing it because you can fine the distance traveled by using the .getdistance in telop mode. why cant you just say something like myrobot.drive till encoder turn so many revolutions? |
|
#19
|
||||
|
||||
|
Re: Encoders in Auto Mode
That's basically what the code is doing: drive until the encoder->GetDistance() say it has traveled 60 inches.
You could put the code in a function like this: Code:
void DriveDistance(float targetDistance)
{
float distanceTraveled = (leftfrontEncoder->GetDistance() +
rightFrontEncoder->GetDistance() +
leftRearEncoder->GetDistance() +
rightRearEncoder->GetDistance())/4.0;
while (distanceTraveled < targetDistance)
{
MecanumDrive_Polar(forwardPower, 0.0, 0.0);
}
MecanumDrivePolar(0.0, 0.0, 0.0);
}
|
|
#20
|
|||
|
|||
|
Re: Encoders in Auto Mode
so the best and easiest way is the way you described in post 16
Quote:
|
|
#21
|
||||
|
||||
|
Re: Encoders in Auto Mode
Yep, unless you have some other restriction/requirements.
|
|
#22
|
|||
|
|||
|
Re: Encoders in Auto Mode
ok i will try that thanks for the help
if i need more i will send you a message or put another post here |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|