Go to Post Ask the right questions and you can get the right answers. - Chief Hedgehog [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
  #1   Spotlight this post!  
Unread 13-02-2011, 22:22
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: 495
tomy has a spectacular aura abouttomy has a spectacular aura about
Encoders in Auto Mode

Anyone know how to use encoders in auto mode?
Reply With Quote
  #2   Spotlight this post!  
Unread 14-02-2011, 00:24
ChristopherBuck's Avatar
ChristopherBuck ChristopherBuck is offline
Registered User
FRC #0612
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: United States
Posts: 38
ChristopherBuck is a jewel in the roughChristopherBuck is a jewel in the roughChristopherBuck is a jewel in the rough
Re: Encoders in Auto Mode

Your question is pretty vague. Could you please provide more details as to what you are trying to accomplish, and what the problem currently is? Also, it would be helpful to know what language you are using to program the robot, so responses could be tailored to that language.

In theory, using encoders in autonomous would be just the same as using them in teleop. You first must open a reference to an encoder, indicating what DIO it is on and any other necessarry variables, and then use the supplied methods, functions, or nodes/SubVIs to start and count ticks to measure distance or rotations.
Reply With Quote
  #3   Spotlight this post!  
Unread 14-02-2011, 00:34
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: 495
tomy has a spectacular aura abouttomy has a spectacular aura about
Re: Encoders in Auto Mode

I'm using c++, all I need to know is what funcution do I call to make our robot go forward until the encoders turn x amount of times
Reply With Quote
  #4   Spotlight this post!  
Unread 14-02-2011, 01:32
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: 671
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

Still, there are many variations of using encoders. For example, do you care uisng PID? How many encoders do you have? One for left wheel and one for right wheel? Do you have mecanum wheels? In the simplest, your code should look something like this:
Code:
In some periodic function or in a loop:
if ((leftEncoder->GetDistance() + rightEncoder->GetDistance()) /2 < targetDistance)
{
    ArcadeDrive(0.5, 0.0);
}
else
{
    ArcadeDrive(0.0, 0.0);
}
__________________
Reply With Quote
  #5   Spotlight this post!  
Unread 14-02-2011, 10:01
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: 495
tomy has a spectacular aura abouttomy has a spectacular aura about
Re: Encoders in Auto Mode

We will have 4 encoders and we are using mecanum wheels. Want to just post my code?
Reply With Quote
  #6   Spotlight this post!  
Unread 14-02-2011, 12:32
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: 671
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

4 encoders on mecanum wheels are tricky to deal with for using in autonomous drive. Basically, you need to look at the source code RobotDrive.cpp in the WPI library. For example, look at the function MecanumDrive_Polar. Read all four encoder readings (encoder->GetDistance()) and combine them using a reverse algorithm from MecanumDrive_Polar to calculate the magnitude, direction and rotation. Our team used mecanum wheels for last year and use them again this year. So we want to develop a library module to deal with 4 encoders for autonomous drive. Unfortunately, our build head selected gearboxes that made mounting the KOP encoders impossible. So we never get a chance to develop that library module. But if we were really going ahead to implement it, that would be how I would do it.
__________________
Reply With Quote
  #7   Spotlight this post!  
Unread 14-02-2011, 12:43
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: 495
tomy has a spectacular aura abouttomy has a spectacular aura about
Re: Encoders in Auto Mode

i thought it would be simple cause all we want to do is drive forward (for starters) my thought was that you would say in telop encoder.getdistante() and then play that back in auto mode or is it harder than that?
Reply With Quote
  #8   Spotlight this post!  
Unread 14-02-2011, 12:54
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,098
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Encoders in Auto Mode

Quote:
Originally Posted by mikets View Post
look at the function MecanumDrive_Polar. Read all four encoder readings (encoder->GetDistance()) and combine them using a reverse algorithm from MecanumDrive_Polar to calculate the magnitude, direction and rotation.
Have you developed this algorithm?


Reply With Quote
  #9   Spotlight this post!  
Unread 14-02-2011, 13:04
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: 671
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, if I had, I would have posted it. I probably would take some time to do this after the season. Too busy at the moment. I have an algorithm in mind, but I need to enter the algorithm into excel and make sure the numbers will go a round trip without problem. i.e. With a given set of magnitude, direction and rotation numbers, use the algorithm in MecanumDrive_Polar to calculate the four wheel speeds and then calculate a set of encoder distances with a given drive time, apply the reverse algorithm to the encoder distances that should give me a set of: magnitude of distance traveled, direction of distrance travel, rotation delta since start. If I divide it by drive time, I should get back a set of number corresponding to the original numbers. I probably got some aspects wrong. That's why I need to simulate that in excel to figure out the details of the reverse algorithm.
__________________
Reply With Quote
  #10   Spotlight this post!  
Unread 14-02-2011, 13:11
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: 495
tomy has a spectacular aura abouttomy has a spectacular aura about
Re: Encoders in Auto Mode

so then what is the easiest way of doing it in auto mode?
Reply With Quote
  #11   Spotlight this post!  
Unread 14-02-2011, 13:12
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: 671
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

Tomy, if you only care about going straight forward, the algorithm may be a lot simpler without considering all the corner cases. When going straight forward, all four wheels will turn in the same direction with the same strength. So you could do the following:
Code:
double distanceTraveled = (leftfrontEncoder->GetDistance() +
                                     rightFrontEncoder->GetDistance() +
                                     leftRearEncoder->GetDistance() +
                                     rightRearEncoder->GetDistance())/4.0;
if (distanceTraveled < targetDistance)
{
    MecaumDrive_Polar(forwardPower, 0.0, 0.0);
}
else
{
   MecaumDrive_Polar(0.0, 0.0, 0.0);
}
__________________
Reply With Quote
  #12   Spotlight this post!  
Unread 14-02-2011, 13:25
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: 495
tomy has a spectacular aura abouttomy has a spectacular aura about
Re: Encoders in Auto Mode

where do you set the target distance and why do you divide it by 4?
Reply With Quote
  #13   Spotlight this post!  
Unread 14-02-2011, 13:40
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: 671
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

Add the four encoder values and divide by 4 is averaging them. targetDistance is the distance you want to travel. For example, if you want to travel 5 ft (60 inches), you first set the encoder unit by calling encoder->SetDistancePerPulse for inches. Then set your targetDistance to 60.0.
__________________
Reply With Quote
  #14   Spotlight this post!  
Unread 14-02-2011, 13:44
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: 495
tomy has a spectacular aura abouttomy has a spectacular aura about
Re: Encoders in Auto Mode

ok so correct my if im wrong but for 60 inches it would look something like this?


Code:
encoder->Setdistanceperpulse (60.0)
double distanceTraveled = (leftfrontEncoder->GetDistance() +
                                     rightFrontEncoder->GetDistance() +
                                     leftRearEncoder->GetDistance() +
                                     rightRearEncoder->GetDistance())/4.0;
if (distanceTraveled < targetDistance)
{
    MecaumDrive_Polar(forwardPower, 0.0, 0.0);
}
else
{
   MecaumDrive_Polar(0.0, 0.0, 0.0);
}
thanks for the help in advance im new to c++
Reply With Quote
  #15   Spotlight this post!  
Unread 14-02-2011, 13:55
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,098
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Encoders in Auto Mode

Quote:
Originally Posted by mikets View Post
No, if I had, I would have posted it. I probably would take some time to do this after the season. Too busy at the moment. I have an algorithm in mind, but I need to enter the algorithm into excel and make sure the numbers will go a round trip without problem. i.e. With a given set of magnitude, direction and rotation numbers, use the algorithm in MecanumDrive_Polar to calculate the four wheel speeds and then calculate a set of encoder distances with a given drive time, apply the reverse algorithm to the encoder distances that should give me a set of: magnitude of distance traveled, direction of distrance travel, rotation delta since start. If I divide it by drive time, I should get back a set of number corresponding to the original numbers. I probably got some aspects wrong. That's why I need to simulate that in excel to figure out the details of the reverse algorithm.
You might the discussion of forward kinematics on Pages 7,8,&9 of this paper of interest.



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 03:05.

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