Ok, I’m having problems with the gear tooth sensor. I have the sensor wired up correctly and everything, but when I print the value of the digital port, it stays at 0. I have tried puting a gear in front of it in all sorts of postitions. I’ve tested the power connection and the connection to the rc and it seems all to be right. Am I missing something? Thanks
I know you said you wired it correctly, but that’s still the first place to start. What do you have connected to the six connection points on the sensor?
Have you configured the port as an input? You probably didn’t need to do anything special, because the default code sets all digital pins to inputs in User_Initialization().
How exactly are you printing the value? Show us the line of code that you’re using.
Once we’ve determined that you can indeed read the state of the input pin, you’re only half finished. Unless you intend to monitor a gear that has only a few teeth going by per second, you will almost certainly need to use interrupts in order to count gear teeth reliably.
I faced that problem with I was playing with encoders last year. If you don’t print it out correctly, it will display as zero. Please post the part of your code that prints out the values and make sure you have the code configured correctly. Read and re-read the readme.txt file.
this is what it looks like :
printf("%d\r",rc_dig_in01);
Thanks for all of the help
Hi, sorry for bumping in, but we just recieved the 2 GTS pieces and we’d like to know how exactly do we use it?(where do we connect, what values to we use, what we need to code or what code to download to make it work etc…)
Everythng you need to know is in this thread…
First off, download and read Kevin Watsons encoder code and encoder FAQ
http://www.kevin.org/frc/encoder/
http://www.kevin.org/frc/frc_encoder.zip
To make his code work with the gear tooth sensors you need to remove the “Phase B” logic from it.
Second you wire them to digital I/O 1 and digital I/O 2 with a pwm cable. You also need to power them on a 12volt power supply as well.
See the 2007 Sensor Manual for more information.
To wire the sensor…
Take one end of a pwm cable, and solder it to J2, the black wire to GB (ground-black) the red wire to 5R (+5 volts-red) the white wire to SW (signal white). Connect the other end of this pwm to digital I/O 1.
Take a 2nd pwm cable and solder it to J1, the black wire to GB, the white wired to (12W), the red wire is unused. Connect the other end to a 20amp circut on one of your atc breaker panels.
Mount the sensor from .5 to 2.75 mm away from the gear to be measured.
Repeat this for the second one except connect it to digital I/O 2.
As for the code…
Use encoder 1 and encoder 2, disable the others. Then remove the “Phase B” logic in the interrupt handler for encoder 1 and encoder 2.
i just wanted to clear up a misconception, the GTS 2007 does indeed indicate the direction but in a manor different than the 2006.
reading the datasheet for the sensor,
http://www.allegromicro.com/datafile/0642.pdf
we see on page 10 that if the gear rotates past the sensor in a ‘pin 1 to pin 4’ direction, then the output produces a square wave pattern, about 50% duty cycle.
but
if the same wheel rotates past the same sensor the other direction, now pin 4 to pin 1, that same square wave pattern is produced BUT the signal is inverted!
now… who wants to provide the code for this
slloyd
From what I understood from our mentor, the GTS has 4 holes to insert 4 certain screws that are supposed to “tick” with the gear teeth. Those screws are to be, as you say, .5 to 2.7 mm from the certain geartooth?
And another thing, Kevin mentioned this illustration in his Encodr FAQ:
What is this illustration about?
And even furthermore, why are there 6 encoder counts in Kevin’s Encoder code(we did understand that the first 2 are to calculate velocity of the gear teeth, the 3rd and 4th for the positioning[in relation to the begining point in each intialization of the RC and everything])?
And could someone please send an exact illustration how to connect the GTS to the geer tooth or a picture of a team’s GTS connection?
You understand incorrectly. Have you ever seen the GTS board? Please find it and get familiar with it. Many of your questions can be answered by simply looking at it.
The GTS board has two holes. Those holes are just for mounting the board in place. The actual sensor part is a black block at the edge of the board. Its face should be placed a millimeter or so from the teeth of a rotating steel gear. Nothing on the board touches the gear. It senses the passage of teeth by detecting changes in the magnetic field around the sensor.
OH, SWEET!!!
So could you answer my other questions related to Kevin’s Encoder code?
Ok, I understood how to connect the GTS…well, except for the connection to the 20 AMP one. How do we do that?
And what’s with the phase B, what is it, what’s the illustration in Kevin’s FAQ and what do I need to do with it in Kevin’s Encoder code to make things work?
One wire goes from a 20-amp-protected tab on the black breaker panel to the +12v connection on the board. Another wire goes from the ground connection on the board to a ground tab on the breaker panel.
And what’s with the phase B, what is it, what’s the illustration in Kevin’s FAQ and what do I need to do with it in Kevin’s Encoder code to make things work?
References to “phase B” apply to quadrature encoders. The Gear Tooth Sensor is not one of those; it has no “phase B” signal.
The illustration I believe you are referring to shows how a too-fast quadrature signal can be misread if the software is not responsive enough to process an interrupt before the signals change. It is not relevant to the Gear Tooth Sensor. (A different problem is possible if the GTS interrupt rate gets too high, but “too high” in this case means more than several thousand pulses per second.)
If you use inputs 1 and 2 and leave the associated phase B inputs disconnected so they remain high, I think Kevin’s encoder software will work without modification. To change it so that it works specifically with a single-phase pulse instead of a quadrature signal, just remove the test for the level of the phase B input, and make the code always increment the counter when the interrupt occurs. If you want to, you can get fancier and choose whether to increment or decrement the counter based on which direction you think the gear is turning.
Quadrature signal??? (O_o’)
our team’s head programmer (GO 1221!!) got the encoder going earlier this week. the posts on this message board and kevin’s code/FAQ were invaluable.
now… what to do with this information? we would like to use it to help the mobility of our robot become smooth and accurate. i have read the FIRST document for PID control of motors, it was linked somewhere but i forget now. seems this is a good match and is the right way to go.
but, looks really tough to program. maybe need floating point math?
also, has anyone successfully determined which direction the gear is rotating (see my earlier post that proves it IS at least possible with 2007 sensor). i’d appreciate your comments if you have.
slloyd
Just realized, haven’t got an answer from this question and the programming sub-team is about to start working soon, so if we could get assistance we that we’ll be able to work on this encoder faster.
So, anyone, quardrate signal and stuff? Anyone knows?
Is that last question asking for an explanation of Quadrature Output? OK if it is, Wikipedia has a pretty basic one and there are a lot others but look at
http://en.wikipedia.org/wiki/Rotary_encoder And scroll down to the section headed “Incremental rotary encoder”. They also explain that backward count problem so kudos to them for being through.
This same theory applies to rotary and strip encoding schemes so the entire article is a good read.
Hope that’s what you were asking.
Steve
Thank you, that was an excellent read!
I even tried with the mouse (yes…I admit…I use old mouses :rolleyes: ) and if I spinned one of the “scrollers” top fast the mouse on the screen actually bounced to the other side and then back!
I think I might have a question about the “two sensors” thing. I belive the GTS has those “two sensors” (as in Phase A and Phase B) inside them, is that correct?
I’m just quite tired now and I don’t think I’ll be able to go over the encoder code now, but I’m hoping to do so tommorow and maybe finally understand how to work with this stuff.
Thanks again.
NO… the Gear Tooth sensor only give ONE signal. The Quadrature output refers to a device that can give two signals with one being 90 degrees from the other. IF you could use TWO GTS sensors and align one so that it peaks 90 degrees after the other then you could use the Quad scheme for direction.
Single GTS is intended to give you theoretical distance traveled on a wheel but you keep track of direction by knowing WHICH direction you are driving the motor.
IN other words if my PWM is > 127 and I get a signal I add to my counter… < 127 and I get a signal then I subtract from the count. Same with a relay driving a motor. if the forward direction is set and the interrupt occurs you add to the count…well you get the idea.
Rotary optical encoder have two sensors built in at 90 degree offsets so they are very accurate and directional information comes from knowing what the previous state was… or in hardware by using a simple flipflop. clocked by the A phase. (See the banebot encoder schematic for their divider page 5 of the manual http://banebots.com/pc/ELECTRONICS/EN-A0001-KT )
Now ALL this tells you how much the motor and wheel have rotated but do not take into account slippage of the wheel to the ground, so one more “fly in the ointment” ( Where do we get these old sayings anyway? )
OK that’s my piece for now
Steve
assuming a momentum-less world, are we?
Ah! I see what you are saying… you kill power but the bot still rolls. Well ok you have to “remember” which direction you were rolling and allow the bot to come to a complete stop… before changing direction with a single GTS. Yes in that case Quad is preferable.
But probably not a problem with something like positioning an arm.
In any case… this is still a “dead reckoning” scheme so it’s an approximation anyway. (If it were easy it wouldn’t be worth doing. )
In an aside… to obtain Quad with GTS… one suggestion has been that :
- using a gear with an odd number of teeth.
- using two GTS
- IF you carefully position them at 90 degrees to the gear center, you get a 90 degree phase shift and can treat them as an A B phased encoder.
I haven’t done the math on this but it seems plausible.
Steve