Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Magnetic Sensor (http://www.chiefdelphi.com/forums/showthread.php?t=114435)

tomy 27-02-2013 14:41

Magnetic Sensor
 
Im working on a magnetic sensor for our shooter this year. We can get a reading off of it using the counter class. The problem is that it keeps counting. Is there a way to set some kind of interupt so it reset every second so we can get a type of rpm?

Kevin Sevcik 27-02-2013 14:45

Re: Magnetic Sensor
 
What kind of magnetic sensor is this? How many counts are you getting per revolution of your shooter wheel?

tomy 27-02-2013 14:48

Re: Magnetic Sensor
 
i believe it was this one im not 100% sure because i dont have the packaging its with the our other robotics stuff right now.

http://www.digikey.com/product-detai...8-2-ND/2626345

Kevin Sevcik 27-02-2013 15:49

Re: Magnetic Sensor
 
Hrm. Are you using that to sense a magnet on a wheel, or teeth on a gear? I'm trying to figure out how many counts per revolution of your wheel you're expecting to get. If you're only expecting 1 count/pulse per revolution of your wheel, there's a better way to determine your wheel speed.

tomy 27-02-2013 16:00

Re: Magnetic Sensor
 
1 Attachment(s)
I can get a reading off of it by using the counter class and counter.Get();

Kevin Sevcik 27-02-2013 19:36

Re: Magnetic Sensor
 
Quote:

Originally Posted by tomy (Post 1241215)
I can get a reading off of it by using the counter class and counter.Get();

You seem to be in a sort of no-man's land here with that setup. You should be getting 6 counts per revolution like that. That's not enough counts per second to do any reasonable speed control. On the other hand, it's probably too many counts per second to use 60/counter.GetPeriod() to give you an RPM to control. You can try this method, but I don't think it'll be super stable for your current sensor setup.

What I'd recommend is changing your sensor to this:
http://www.digikey.com/product-detai...330-ND/2075330

Then gluing a small magnet to your wheel with the south pole facing that hall switch. That will work similarly to your current setup, except you'll only get one pulse per revolution, which will make the 60/counter.GetPeriod() RPM value much more stable.

Your other option may be to change out 5 of those screws with flat head screws and countersink the holes so that the you only have one screwhead that will trigger your gear tooth sensor.

Or, if that aluminum hub has a setscrew in it, you might re-orient your sensor to pick up the setscrew as it comes around. Or add a setscrew just for this sensing purpose. The whole idea here is that you only want one pulse per revolution of the wheel.

Ether 27-02-2013 20:40

Re: Magnetic Sensor
 
Quote:

Originally Posted by Kevin Sevcik (Post 1241274)
You seem to be in a sort of no-man's land here with that setup. You should be getting 6 counts per revolution like that. That's not enough counts per second to do any reasonable speed control. On the other hand, it's probably too many counts per second to use 60/counter.GetPeriod() to give you an RPM to control. You can try this method, but I don't think it'll be super stable for your current sensor setup.
...
The whole idea here is that you only want one pulse per revolution of the wheel.

Kevin,

If he's getting good counts with that sensor, all he has to do is change the getPeriod() FPGA sample averaging ring buffer from the default value of "1" to "6".

For Java and C++, this requires making a small change to the WPILib code.

http://www.chiefdelphi.com/forums/sh...7&postcount=24




tomy 27-02-2013 21:37

Re: Magnetic Sensor
 
So im still confused how will that help me? im getting current counts and its counting right i checked it. for the rpm im planing on doing something like:


Code:

Counter gts;
float rpm
.
.
.

rpm = ( ((1/gts.GetPeriod())/6)*60)

I might have missed a ( somewhere

Kevin Sevcik 27-02-2013 21:39

Re: Magnetic Sensor
 
Quote:

Originally Posted by Ether (Post 1241313)
Kevin,

If he's getting good counts with that sensor, all he has to do is change the getPeriod() FPGA sample averaging ring buffer from the default value of "1" to "6".

For Java and C++, this requires making a small change to the WPILib code.

http://www.chiefdelphi.com/forums/sh...7&postcount=24

I thought there was something like that, was just leery to suggest it because the period between each of the 6 pulses would likely be a bit different. Though I suppose it works out with a buffer of 6, as it'd have a full revolution of pulses, so physical variance between the pulses should cancel out.

tomy,
You other other option is doing as Ether suggests and changing the averaging ring buffer for the counter, then using 10/counter.GetPeriod() as your feedback RPMs.

Ether 27-02-2013 21:45

Re: Magnetic Sensor
 
Quote:

Originally Posted by Kevin Sevcik (Post 1241347)
the period between each of the 6 pulses would likely be a bit different. Though I suppose it works out with a buffer of 6, as it'd have a full revolution of pulses, so physical variance between the pulses should cancel out.

Exactly.



Kevin Sevcik 27-02-2013 21:48

Re: Magnetic Sensor
 
Quote:

Originally Posted by tomy (Post 1241346)
So im still confused how will that help me? im getting current counts and its counting right i checked it. for the rpm im planing on doing something like:


Code:

Counter gts;
float rpm
.
.
.

rpm = ( ((1/gts.GetPeriod())/6)*60)

I might have missed a ( somewhere

The idea there is correct, our concern is that your screwheads aren't perfectly spaced and there's 6 of them. That means you're going to have a noisy signal. 6 screws means pulses are 1/6th as long, means at 5000 RPM, your period is 2ms. Ether will probably come in with the exact formula for how much inherent noise you'll see in a 2ms period, but it's definitively more than with the 12ms pulse. Add in the fact that each screw head is going to trigger the pulse at a different time, and you could end up with pretty noisy feedback that won't be fun to control.

You can fix that by making the edit to WPILib that Ether suggested. That will create a buffer of the last 6 period measurements and output the average of those. That means you'll get an average over all 6 of your unevenly spaced screws, which will even things out and greatly reduce the noise in your feedback.

tomy 27-02-2013 21:57

Re: Magnetic Sensor
 
So where is this file that i have to change?

EDIT: found it

so now my function would be

(1/gts.GetPeriod)/60 which would give me my rpm right?

Ether 27-02-2013 23:05

Re: Magnetic Sensor
 
Quote:

Originally Posted by tomy (Post 1241359)
so now my function would be

(1/gts.GetPeriod)/60 which would give me my rpm right?

Your question was answered in a previous post.



tomy 27-02-2013 23:48

Re: Magnetic Sensor
 
Quote:

Originally Posted by Ether (Post 1241385)
Your question was answered in a previous post.



ahh kk ty

tomy 28-02-2013 16:55

Re: Magnetic Sensor
 
Well i changed that values from a 1 to a 6 so it looked likes:

Code:

m_counter->writeTimerConfig_AverageSize(6, &localStatus);
Then in my code I have this:

Code:

float rpm
Counter gts;
.
.
.
rpm = (((1/gts.GetPeriod()) / 6) *60);

to find the rpm and when i print out the rpm i get strange results. most of the prints say inf the others say something like 23334.053 for rpm. What is going on with that?


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

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