Go to Post Just wondering what types of food you have been living off of while working on your robot? Our team has had pizza almost 3-4 times a week or more. Just wondering. SGS DRAGONS - sgsdragons [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #16   Spotlight this post!  
Unread 14-02-2011, 13:57
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 674
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
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);
}
__________________
Reply With Quote
  #17   Spotlight this post!  
Unread 14-02-2011, 13:59
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 674
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Encoders in Auto Mode

Quote:
Originally Posted by Ether View Post
You might the discussion of forward kinematics on Pages 7,8,&9 of this paper of interest.
Thanks Ether, I will read it.
__________________
Reply With Quote
  #18   Spotlight this post!  
Unread 14-02-2011, 14:07
tomy tomy is offline
Registered User
FRC #3038 (I.C.E. Robotics)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Stacy, Minnesota
Posts: 503
tomy has a spectacular aura abouttomy has a spectacular aura about
Re: Encoders in Auto Mode

Quote:
Originally Posted by mikets View Post
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?
Reply With Quote
  #19   Spotlight this post!  
Unread 14-02-2011, 14:56
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 674
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
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.
__________________
Reply With Quote
  #20   Spotlight this post!  
Unread 14-02-2011, 15:23
tomy tomy is offline
Registered User
FRC #3038 (I.C.E. Robotics)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Stacy, Minnesota
Posts: 503
tomy has a spectacular aura abouttomy has a spectacular aura about
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);
}
Reply With Quote
  #21   Spotlight this post!  
Unread 14-02-2011, 15:24
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 674
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Encoders in Auto Mode

Yep, unless you have some other restriction/requirements.
__________________
Reply With Quote
  #22   Spotlight this post!  
Unread 14-02-2011, 15:27
tomy tomy is offline
Registered User
FRC #3038 (I.C.E. Robotics)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Stacy, Minnesota
Posts: 503
tomy has a spectacular aura abouttomy has a spectacular aura about
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
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 13:38.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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