Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   GearTooth Sensor Destroying Hopes of Autonomous~!!!!!! (http://www.chiefdelphi.com/forums/showthread.php?t=44428)

Prgrmin' 20-02-2006 18:30

GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
We have just hooked up our gear tooth sensors and finally started getting readouts. problem is there are 238 gear tooths and when we spin it around we get gear counts in the hundred millions. we have no idea of why the gear count is reading out like this. We are using the easyC to program the geartooth sensors. Any input on what to do or what might be causing this problem would be much appriciated.

Rombus 20-02-2006 22:36

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
Hate to be the bearer of bad news, but i THINK the gear tooth sensors only sense direction, not tooth count.

http://www2.usfirst.org/2006comp/oth..._Operation.pdf

Dad1279 20-02-2006 22:52

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
Quote:

Originally Posted by Rombus
Hate to be the bearer of bad news, but i THINK the gear tooth sensors only sense direction, not tooth count.

http://www2.usfirst.org/2006comp/oth..._Operation.pdf

They definitely count. With Easy C, are you preseting them with zero?

Mark_K 21-02-2006 19:48

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
The actual issue is the sample code included with EZ C. The printf display of the geartooth variable needs to be cast as a long. Otherwise the upper bytes will be filled in with random data that will make the count look incorrect.

TimCraig 21-02-2006 22:59

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
Actually, the gear tooth sensor should sense ONLY counts and give NO CLUE as to direction.

gnirts 21-02-2006 23:01

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
Quote:

Originally Posted by TimCraig
Actually, the gear tooth sensor should sense ONLY counts and give NO CLUE as to direction.

Apparently, direction is possible. Just a little more convoluted.

See "GTS Counting" at http://www.chiefdelphi.com/forums/sh...threadid=44479

Stuart 21-02-2006 23:26

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
well you should know what way you are turrning your motor . .so while the sensor may not know what way its going your code can.


if(motorPWM# <127)
gtscountdown():
if(motorPWM# >127)
gtscountup();

b_mallerd 22-02-2006 01:13

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
Sadly, that only works in theory.

When you are stopping and your motors are getting a pwm of 127 the gears still spin for a little bit. I guess this wouldn't matter too too much but then your gear count wouldn't register during these times.

Cuog 22-02-2006 09:09

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
i have found that using the IR sensors they gave us a few years ago and a visual encoder will also give fairly accurate results and with very little programming. The code to handle all the stuff for our visual encoders is about 10 lines in total including overload handling and reset capability.

jzampier 22-02-2006 10:59

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
I tried counting teeth (well sort of... I was using an optical sensor to count the number of revs of a shaft collar). I found the best way is to hook up the output of the sensor to an interrupt pin. That way when the sensor trips you increment your count (or decrement, depending on which way the motor was going last, use a tracking variable).

It's quite a bit more accurate than counting in the main loop as the IRQ time on those PICs is in the microseconds.
And, it's largely free.

Gdeaver 22-02-2006 11:43

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
In my opinion the gear tooth sensors are a pain. A cheap alternative solution is to use the vex encoders in place of the gear tooth sensors. They work with the same Easy-C functions as the gear tooth sensors. They are also higher resolution. They can be added to the kit chassis and frame very easily. The KOP trans output shaft is tapped. A piece of threaded rod can be coupled to a piece of 1/8" key stock. Attach the encoder with a piece of 1/16" aluminum angle. You'll need a female by female PWM extension cable.
Works very well for going "x" feet during autonomous. Could easily be done Thurs. morning.

Chriszuma 23-02-2006 16:39

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
Quote:

Originally Posted by Gdeaver
In my opinion the gear tooth sensors are a pain. A cheap alternative solution is to use the vex encoders in place of the gear tooth sensors. They work with the same Easy-C functions as the gear tooth sensors. They are also higher resolution. They can be added to the kit chassis and frame very easily. The KOP trans output shaft is tapped. A piece of threaded rod can be coupled to a piece of 1/8" key stock. Attach the encoder with a piece of 1/16" aluminum angle. You'll need a female by female PWM extension cable.
Works very well for going "x" feet during autonomous. Could easily be done Thurs. morning.

How do you interface with those in the code? Does it just give you a tick every revolution or something similar?

EDIT: 200th post! w00t!

Gdeaver 23-02-2006 20:27

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
The Vex encoders give 90 counts per revolution. There is no direction info. The same easy-c function that is for the gear tooth sensor can be used for the Vex encoder. They are not of the Grayhill quality or cost. You wouldn't want to use one to measure the shooter wheel RPM but for measuring distance they're not to bad.

Denz 25-02-2006 13:10

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
When using GTS do you have to use interrupts? Because we wrote a code using simple counters, it kinda works. It would be great if maybe someone could help us up and give like a sample code for the gts. Thanks!

Tom Bottiglieri 25-02-2006 13:16

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
Quote:

Originally Posted by Denz
When using GTS do you have to use interrupts? Because we wrote a code using simple counters, it kinda works. It would be great if maybe someone could help us up and give like a sample code for the gts. Thanks!

Using interrupts really isnt as hard as it seems. You can even use the same code you've already written.. Just take the guts of your counter, put it in a function that whenever called will add one to the counter, and call that function in the ISR for whatever interrupt you choose to use. (I1-I3 are the easiest to get set up and running.)

Denz 25-02-2006 22:05

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
How could I modify Kevin's Encoder code so I could use it with Gear Tooth Sensors, I'm a programming rookie, and I'm really having a tough time with these! :( I don't really have a way to test, except I have a switch hooked up to the proper dig inputs, which is supposed to represent 1 gear being counted everytime I press it. My counter code works with the switch, but I'm afraid that the gears will be moving too fast for a simple counter code to work.

jgannon 26-02-2006 12:12

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
Quote:

Originally Posted by Denz
How could I modify Kevin's Encoder code so I could use it with Gear Tooth Sensors, I'm a programming rookie, and I'm really having a tough time with these! :( I don't really have a way to test, except I have a switch hooked up to the proper dig inputs, which is supposed to represent 1 gear being counted everytime I press it. My counter code works with the switch, but I'm afraid that the gears will be moving too fast for a simple counter code to work.

Kevin Watson's encoder code will work with the gear tooth sensors with virtually no modification at all. If you drive the robot too fast, you will start to get weird readings, but if you drive at a reasonable pace, his code will work just fine.

Alan Anderson 26-02-2006 14:17

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
Quote:

Originally Posted by Denz
How could I modify Kevin's Encoder code so I could use it with Gear Tooth Sensors,...

The necessary change is trivial. Just take out the piece of the encoder interrupt service routine that checks the "B" phase, so that it always increments the counter when it gets an interrupt. Or, if you like, you can get fancy and read the motor pwm value to decide whether to increment or decrement the couter.
Quote:

My counter code works with the switch, but I'm afraid that the gears will be moving too fast for a simple counter code to work.
It's not so much the speed you need to worry about, but the narrow pulse width from the GTS. It's only active for a few tens of microseconds each time a tooth goes by, so reading its value in the Process_Data_From_Master_uP() loop is not likely to see it reliably. You really need to have it trigger an interrupt.

Kevin Watson 26-02-2006 15:56

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
Quote:

Originally Posted by Denz
How could I modify Kevin's Encoder code so I could use it with Gear Tooth Sensors, I'm a programming rookie, and I'm really having a tough time with these! :( I don't really have a way to test, except I have a switch hooked up to the proper dig inputs, which is supposed to represent 1 gear being counted everytime I press it. My counter code works with the switch, but I'm afraid that the gears will be moving too fast for a simple counter code to work.

Use encoder inputs one and two and change this code:

Code:

void Encoder_1_Int_Handler(void)
{
// Encoder 1's phase a signal just transitioned from zero to one, causing
// this interrupt service routine to be called. We know that the encoder
// just rotated one count or "tick" so now check the logical state of the
// phase b signal to determine which way the the encoder shaft rotated.
if(ENCODER_1_PHASE_B_PIN == 0)
{
Encoder_1_Count -= ENCODER_1_TICK_DELTA;
}
else
{
Encoder_1_Count += ENCODER_1_TICK_DELTA;
}
}

Into this:

Code:

void Encoder_1_Int_Handler(void)
{
Encoder_1_Count += ENCODER_1_TICK_DELTA;
}

Repeat the above for channel two.

If you want to change the direction the GTS counts, change the ENCODER_1_TICK_DELTA or ENCODER_2_TICK_DELTA value to -1 in encoder.h.

-Kevin

Denz 26-02-2006 22:22

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
Thanks! I'll test it on my temporary rig, and report back :) hopefully it works on the robot aswell, lol, considering I'm using a processor and a switch hooked up to the dig inputs.

EDIT:
If the GTS is stuck on a gear, does it's value stay at 0?

EDIT:
I must have done something wrong. I can see that the switch is being activated, but the count stays at 0.

I called all functions in autonomous mode and I modified this part of the code:

void Encoder_1_Int_Handler(void)
{
if(ENCODER_1 == 0)
{
Encoder_1_Count++;
}
printf("Encoder: %d", Encoder_1_Count);
printf("Switch: %d", rc_dig_in06);
}
Encoder_1 is rc_dig_in06

I read the readme, and I assume I did everything correctly.

Please keep in mind that this is my first year programming, and I'm most probably overlooking something obvious...

ericand 27-02-2006 04:12

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
The default encoder code from Kevin is great for seeing the interrupts
work. I would run that code (unmodified) on a test system and look at
the way it responds to interrupts generated by hand using a switch.
The default encoder code will print out the counts for the enabled interrupts
on a regular interval.

We wired up a bunch of switches and put them on digital I/O 1-6 to see
how they worked.

What digital I/O pins do you have the GTS wired to?
Your printf seems to say that the switch is on rc_dig_in06 and
you are expecting encoder_1_count to increment. That will not work.

You should not be trying to print from the interrupt handler. Printing takes
way too long to be done in the interrupt context.

We also used a switch to simulate the GTS input when we were developing
code on a test bed, so you should be able to get it to work.

You need to remember that all the interrupts are on the digital I/O pins 1-6.
encoder_1_count in Kevin's code refers to the count of interrupts on pin 1.
I encourage you to use digital I/O 1 and 2 for your GTS. For reasons why,
search the forum for posts on the difference between edge triggered and
level triggered interrupts.

Quote:

Originally Posted by Denz
Thanks! I'll test it on my temporary rig, and report back :) hopefully it works on the robot aswell, lol, considering I'm using a processor and a switch hooked up to the dig inputs.

EDIT:
If the GTS is stuck on a gear, does it's value stay at 0?

EDIT:
I must have done something wrong. I can see that the switch is being activated, but the count stays at 0.

I called all functions in autonomous mode and I modified this part of the code:

void Encoder_1_Int_Handler(void)
{
if(ENCODER_1 == 0)
{
Encoder_1_Count++;
}
printf("Encoder: %d", Encoder_1_Count);
printf("Switch: %d", rc_dig_in06);
}
Encoder_1 is rc_dig_in06

I read the readme, and I assume I did everything correctly.

Please keep in mind that this is my first year programming, and I'm most probably overlooking something obvious...


Denz 27-02-2006 07:21

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
I had the encoder to rc_dig_in06 aswell. I defined it in encoder.h. Where should I print from? Because it's printing, just it's only printing 0, not counting like it should.

And how do you see how the interrupts trigger on the test code if you don't have printfs? My code is not really modified, I just removed Encoder_3-6 because I wont be using them. I kept Encoder_1 and_2 and have them to rc_dig_in06 and 07. I defined it properly in encoder.h, but maybe I'll swithc them back to rc_dig_in01 and 02.
Thanks! Anything else I'm missing?

Alan Anderson 27-02-2006 08:25

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
Quote:

Originally Posted by Denz
Code:

void Encoder_1_Int_Handler(void)
{
        if(ENCODER_1 == 0)
        {
                Encoder_1_Count++;
        }
        printf("Encoder: %d", Encoder_1_Count);
        printf("Switch: %d", rc_dig_in06);
}

Encoder_1 is rc_dig_in06

Two big problems. First, the Encoder_1_Int_Handler() interrupt service routine will only be triggered by a transition on digital input 1. Move your gear tooth sensor to rc_dig_in_01. There's no interrupt connection to rc_dig_in06.

Second, you won't be incrementing the counter unless the code manages to execute quickly enough to read the value of the pin before it goes back high. Take out the if statement. The interrupt will occur only once per pulse of the input signal.

There's a small problem as well -- using printf() inside an interrupt routine is risky, as it can be a time-consuming function.

Denz 27-02-2006 16:19

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
Quote:

Originally Posted by Alan Anderson
Two big problems. First, the Encoder_1_Int_Handler() interrupt service routine will only be triggered by a transition on digital input 1. Move your gear tooth sensor to rc_dig_in_01. There's no interrupt connection to rc_dig_in06.

Second, you won't be incrementing the counter unless the code manages to execute quickly enough to read the value of the pin before it goes back high. Take out the if statement. The interrupt will occur only once per pulse of the input signal.

There's a small problem as well -- using printf() inside an interrupt routine is risky, as it can be a time-consuming function.

I moved it to rc_dig_in01. What should I put in place of the if statement to increment the counter?

Also, I'm getting a code error sometimes when I run the code.

6600gt 27-02-2006 23:14

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
Quote:

Originally Posted by Denz
I moved it to rc_dig_in01. What should I put in place of the if statement to increment the counter?

Also, I'm getting a code error sometimes when I run the code.

Nothing, just the encoder_1_count++ will work(everytime the interrupt occurs the count goes up by one)

Is this using Kevin's encoder code or you ported over the encoder.c and .h files over to your code?

If you did port over then look at his user_routines_fast.c file in Kevin's encoder code on how to call the interrupt handler.

print in the Process_Data_From_Master_uP() before putdata function.

Denz 27-02-2006 23:49

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
Oh man, this just doesn't seem to want to work! I've been working on it since friday! Ummm, ok I changed some things, now I'm getting a code error. (the red light of doom). I don't know what to do! I guess I'll start from scratch again! :( We need more programmers on my team! lol

EDIT: Ok, no more red light of death, but sitll not working, would it help if I posted my code?

Denz 28-02-2006 00:15

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
3 Attachment(s)
Here it is! Thanks guys so far for all the help, I guess I'm just not getting it!


EDIT: I changed encoder.c, still doesn't count however.

Alan Anderson 28-02-2006 07:27

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
Quote:

Originally Posted by Denz
...Ok, no more red light of death, but sitll not working, would it help if I posted my code?

It would help if you posted your code, and it would help even more if you clarified exactly what "not working" means. What are you expecting it to do, and what is it doing instead?

Looking at your code, I see a couple of small issues with a printf(). The encoder counts are defined as long, and you're not casting them to an int when printing their value. That could give unexpected results, as the %d format specifier expects a regular integer and might show you just the high two bytes of the value (which will be zero until you've counted a lot of teeth).

Also, if you're trying to read the value of the counter outside the interrupt service routine, you should not be accessing the variable directly. Instead, use the function provided to do it. That way you won't find your code being interrupted and changing the value in the middle of reading it, leaving you with an inconsistent result.

Denz 28-02-2006 14:46

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
I want the GTS to count everytime it senses a tooth. So it can count rotations of the wheels (say 90 teeth per rev). As of now, when I print the value, it stays at 0. That is what I mean by not working.
I uploaded a new version of encoder.c, it still doesn't count however. I made all the changes you suggested.

Alan Anderson 28-02-2006 16:23

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
Quote:

Originally Posted by Denz
I want the GTS to count everytime it senses a tooth. So it can count rotations of the wheels (say 90 teeth per rev). As of now, when I print the value, it stays at 0. That is what I mean by not working.
I uploaded a new version of encoder.c, it still doesn't count however. I made all the changes you suggested.

Your software looks like it should work. Do you trust your hardware?

Is the gear tooth sensor mounted as specified, in the correct orientation and at the correct distance from a ferrous gear? Does the board have 12v power on the proper pin? Does it have 5v and ground? Have you looked at the output with an oscilloscope to verify that it's providing pulses?

Denz 28-02-2006 17:02

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
My current setup is using a push switch to simulate the gear tooth sensor. I have it hooked up to rc_dig_in11. I have it printing to screen, and when pushed it shows up as 0, otherwise as 1, so looks like the hardware is working. I'm not sure what to do. The counter is still not counting, it just stays at 0. Thanks again for all the help, it is very much appreciated :)!

phrontist 28-02-2006 17:50

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
Quote:

Originally Posted by Denz
My current setup is using a push switch to simulate the gear tooth sensor. I have it hooked up to rc_dig_in11. I have it printing to screen, and when pushed it shows up as 0, otherwise as 1, so looks like the hardware is working. I'm not sure what to do. The counter is still not counting, it just stays at 0. Thanks again for all the help, it is very much appreciated :)!

You mean a mechanical switch?! That won't last long... but if you've got a lot of spares. :D

Denz 28-02-2006 18:11

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
Quote:

Originally Posted by phrontist
You mean a mechanical switch?! That won't last long... but if you've got a lot of spares. :D

It's only for testing purposes, since our robot is shipped, I only have a RC and an OI, so I have to make good use of it.

Alan Anderson 28-02-2006 18:33

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
Quote:

Originally Posted by Denz
My current setup is using a push switch to simulate the gear tooth sensor. I have it hooked up to rc_dig_in11.

Sigh.

As I explained yesterday morning, if you want to trigger the encoder interrupt when the switch changes state, you have to put it on digital input 1.

Denz 28-02-2006 18:38

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
Quote:

Originally Posted by Alan Anderson
Sigh.

As I explained yesterday morning, if you want to trigger the encoder interrupt when the switch changes state, you have to put it on digital input 1.

I will try that. Sorry, I remember seeing that now, however in Kevin's default code it was assigned to rc_dig_in11.

EDIT: YOU GUYS ARE WONDERFUL! I'm so happy it worked!!! THANKS!

Alan Anderson 28-02-2006 18:53

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
Quote:

Originally Posted by Denz
I will try that. Sorry, I remember seeing that now, however in Kevin's default code it was assigned to rc_dig_in11.

You misunderstood the part of the code that deals with configuring quadrature encoders.

Phase A of encoder 1 has always been documented as rc_dig_in_01, and phase A of encoder 2 has always been documented as rc_dig_in_02. The "B" phases for a quadrature encoder can be connected to any other digital inputs, but there is no phase B on a gear tooth sensor, which is why that part of the interrupt code is simply removed to handle a GTS.

Digital input 1 on the RC goes to one hardware interrupt on the PIC. Digital input 2 on the RC goes to another hardware interrupt. Changes on digital inputs 3-6 can be configured to cause a third hardware interrupt. If you want to use interrupts, you must use the input pins that support interrupts. (Now why am I suddenly having deja vu?)

Congratulations on getting it to work.

Denz 28-02-2006 19:07

Re: GearTooth Sensor Destroying Hopes of Autonomous~!!!!!!
 
Well, I guess you learn something new everyday (or maybe sometimes it takes a couple of days to understand it) but anyways, this is my first year programming anything, and I was in charge or programming the robot. I had alot on my plate I guess so I'm sorry if some of my questions seemed stupid. I really appreciate all the help, our team didn't have any mentors who knew programming, so I'm really glad I could find an e-mentor! Thanks again, now I just have to finish the rest of the autonomous before Rochester!


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

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