Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Encoders in Auto Mode (http://www.chiefdelphi.com/forums/showthread.php?t=91763)

mikets 14-02-2011 13:57

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);
}


mikets 14-02-2011 13:59

Re: Encoders in Auto Mode
 
Quote:

Originally Posted by Ether (Post 1022728)
You might the discussion of forward kinematics on Pages 7,8,&9 of this paper of interest.

Thanks Ether, I will read it.

tomy 14-02-2011 14:07

Re: Encoders in Auto Mode
 
Quote:

Originally Posted by mikets (Post 1022729)
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);
}


so this funtion will make the robot drive until it goes 60 inches.

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?

mikets 14-02-2011 14:56

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);
}

But this function is blocking. You cannot do anything else why the while loop is waiting. Not to mention this will starve your watchdog although by calling the MecanumDrive_Polar function, you probably will feed the per motor watchdog for this year's WPI library. So it's better to do what I suggested in the previous post of checking the target distance in your autonomous loop.

tomy 14-02-2011 15:23

Re: Encoders in Auto Mode
 
so the best and easiest way is the way you described in post 16

Quote:

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);
}


mikets 14-02-2011 15:24

Re: Encoders in Auto Mode
 
Yep, unless you have some other restriction/requirements.

tomy 14-02-2011 15:27

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


All times are GMT -5. The time now is 14:25.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi