Thread: Magnetic Sensor
View Single Post
  #16   Spotlight this post!  
Unread 28-02-2013, 17:18
Kevin Sevcik's Avatar
Kevin Sevcik Kevin Sevcik is offline
(Insert witty comment here)
FRC #0057 (The Leopards)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Houston, Texas
Posts: 3,685
Kevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond repute
Send a message via AIM to Kevin Sevcik Send a message via Yahoo to Kevin Sevcik
Re: Magnetic Sensor

Inf would be because you're getting 0 for the period. Try setting the MaxPeriod to something reasonable. gts.SetMaxPeriod(0.25) or so. The counter class clears out the buffer if it doesn't see a pulse in within MaxPeriod seconds, and I don't know what the default is. Past that, I made my own class that did a little filtering of values so I'd ignore values I knew were bad. I've attached the files, you can try using it. You'd just need to modify "prevResult = 60.0 / period;" to read "prevResult = 10.0 / period;" And you'd want to reduce periodThreshold in the .h file to something like 1e-3 just so it doesn't limit the max RPM to something less that what you can actually output. It's set up so you can use it as a PIDSource for a PIDController.
Attached Files
File Type: h RPMCounter.h (1.0 KB, 2 views)
File Type: cpp RPMCounter.cpp (2.0 KB, 2 views)
__________________
The difficult we do today; the impossible we do tomorrow. Miracles by appointment only.

Lone Star Regional Troubleshooter
Reply With Quote