Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   encoders (http://www.chiefdelphi.com/forums/showthread.php?t=32611)

Workaphobia 08-02-2005 14:40

Re: encoders
 
I've got a few encoder questions. I'm trying to decide whether or not to spend $100 of my team's money on Greyhill optical quadrature encoders, when the kit already includes HAL-effect sensors. Things are beginning to look bleak in terms of the amount of time we have until ship-date, and it'll be hard enough finding someone in the construction section of the team to mount any sensor as it is.

First, I understand that quadrature encoders can detect direction, and that in addition optical encoders are more reliable, but would this high-end technology really be useful for a team that just needs to reliably determine how far the bot has traveled (or turned)?

Second, will Kevin's code work with non-quadrature encoders? I assume it wouldn't - in that case, is it difficult to write my own code to interface with them, or is it as simple as reading an input?

Third, is it possible to use encoders without interrupts, and just poll how many clicks have elapsed, or would polling only return whether or not it is currently clicked?

Thanks.

stephenthe1 08-02-2005 15:12

Re: encoders
 
well, it shouldn't be too much a pain to change his code to use the regular encoders. polling would only tell whether it's currenlty clicked or not. I've tried doing that and I always got messed up measurements, because it's random when it records a tick. therefore, no matter the speed of the shaft, I would suggest using interrupts always.

stephenthe1 08-02-2005 15:18

Re: encoders
 
if anyone has time, I would greatly appreciate it if you could upload the new compiler that Microchip temporarily released for free for me. I had it, but it's walked off to magical places. just let me know where you uploaded it to. or try Emailing it to me. idk what the max. file size limit is for my Email. or if Microchip hasn't taken the ftp link away yet, tell me the link, cause I couldn't find it. thank you a bunch.

Joe Ross 08-02-2005 15:58

Re: encoders
 
Quote:

Originally Posted by Workaphobia
Second, will Kevin's code work with non-quadrature encoders? I assume it wouldn't - in that case, is it difficult to write my own code to interface with them, or is it as simple as reading an input?

Third, is it possible to use encoders without interrupts, and just poll how many clicks have elapsed, or would polling only return whether or not it is currently clicked?

Kevin's code will work with non-quadrature encoders, as long as you don't hook anything else up to digital inputs 6 or 8. It will only count in one direction, though. You could remove the parts of his code that deal with quadrature fairly easily.

You can handle encoders without interrupts, as long as they tick slowly. If you can guarantee that you poll the pin at twice the rate it transitions, you would be able to poll it reliably.

stephenthe1 08-02-2005 16:13

Re: encoders
 
Quote:

Originally Posted by Joe Ross
You can handle encoders without interrupts, as long as they tick slowly. If you can guarantee that you poll the pin at twice the rate it transitions, you would be able to poll it reliably.

just thinking, if you poll it at twice the rate it transitions, chances are you will get more ticks than actually occur with the encoder.

Ssbfalcon 08-02-2005 16:29

Re: encoders
 
Based on what I see, interupts would be more reliable. However, assuming that the reliability of each method are equal, what are the pros and cons of polling and interupts, besides code complexity?

stephenthe1 08-02-2005 16:38

Re: encoders
 
Quote:

Originally Posted by Ssbfalcon
Based on what I see, interupts would be more reliable. However, assuming that the reliability of each method are equal, what are the pros and cons of polling and interupts, besides code complexity?

polling= slow roation only, less reliability overall, I'm not sure, but possibly unnecessary strain on the processor (but I doubt it), won't be prepared for using encoders in the future with interrupts on drive shafts, etc. adv. easy coding like you said.

interrupts=every advantage you could imagine, except tough coding. this is why Mr. Watson wrote code to handle encoders with interrupts, it's truly a wonderful thing he has made. go to www.kevin.org and scroll down to the robotics link, and look for frc encoders template. It's what I used to learn about encoders and interrupts, and it is so easy to use because all the work is already done pretty much. though I wish he would consider setting up a third encoder interrupt as well, but what he has is awesome.

Greg Ross 08-02-2005 17:30

Re: encoders
 
Quote:

Originally Posted by stephenthe1
if you poll it at twice the rate it transitions, chances are you will get more ticks than actually occur with the encoder.

No. You don't count a tick if the pin state hasn't changed since the last time you polled it.

stephenthe1 08-02-2005 17:33

Re: encoders
 
if the pin state hasn't changed, how does it know to not make another tick count? is there a flag, kind of like interrupts that must be cleared before you can register another tick? if so, that's pretty neat.

stephenthe1 08-02-2005 18:30

Re: encoders
 
can somebody please send me a copy of the new compiler? ( stephen51@safe-t.net ) thanks in advance.

Kevin Watson 08-02-2005 18:57

Re: encoders
 
Quote:

Originally Posted by stephenthe1
if the pin state hasn't changed, how does it know to not make another tick count? is there a flag, kind of like interrupts that must be cleared before you can register another tick? if so, that's pretty neat.

This is what state variables are for. As an example:

Code:

// assumptions:
//  left encoder phase-A signal goes to rc_dig_in01
//  left encoder phase-B signal goes to rc_dig_in06
//  right encoder phase-A signal goes to rc_dig_in02
//  right encoder phase-B signal goes to rc_dig_in08
 
static long left_encoder_count = 0;
static long right_encoder_count = 0;
static unsigned char prior_left_phase_a_state = 0;
static unsigned char prior_right_phase_a_state = 0;
 
// look for a rising edge on left phase A
if(rc_dig_in01 != prior_left_phase_a_state && rc_dig_in01 != 0)
{
  // get direction information from left phase B
  if(rc_dig_in06 != 0)
  {
          left_encoder_count++;
  }
  else
  {
          left_encoder_count--;
  }
}
 
// look for a rising edge on right phase A
if(rc_dig_in02 != prior_right_phase_a_state && rc_dig_in02 != 0)
{
  // get direction information from right phase B
  if(rc_dig_in08 != 0)
  {
          right_encoder_count++;
  }
  else
  {
          right_encoder_count--;
  }
}
 
// update state variables
prior_left_phase_a_state = rc_dig_in01;
prior_right_phase_a_state = rc_dig_in02;

Placed in the fast loop, this code will emulate the interrupt-driven code.

-Kevin

Mike Betts 08-02-2005 19:17

Re: encoders
 
Quote:

Originally Posted by stephenthe1
can somebody please send me a copy of the new compiler? ( stephen51@safe-t.net ) thanks in advance.

Stephen,

That would be illegal (copyright laws and all of that...). As they had announced at the kickoff, the V2.4 download was available for 2 weeks only and you had to link to it via the FIRST site. Now they have shut it down, as promised.

Please have your main team contact phone FIRST and they will send you a CD.

Mike

Workaphobia 08-02-2005 20:53

Re: encoders
 
It suddenly occurred to me that the encoders can be reused for next year's competition, so I told my adviser to go ahead with the order. I guess I'll take another look through the readme for the encoder module and prepare to implement some autonomous driving functionality.

stephenthe1 09-02-2005 11:49

Re: encoders
 
I think I found our copy. and I would have to say that I disagree about it being illegal. if I purchased (or in this case got it free) a cd, and simply broke it somehow, I wouldn't be cheating the business by getting a copy from someone else, because I already paid for thir product. anyway, is the newest compiler on the disk that came with the kit this year? just to be sure. thanks

Mark McLeod 09-02-2005 12:08

Re: encoders
 
Quote:

Originally Posted by stephenthe1
anyway, is the newest compiler on the disk that came with the kit this year? just to be sure. thanks

No it is not. The new compiler wasn't available until after the KOP CD was made.


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

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