Thread: Stall detection
View Single Post
  #8   Spotlight this post!  
Unread 25-03-2013, 11:45
apalrd's Avatar
apalrd apalrd is offline
More Torque!
AKA: Andrew Palardy (Most people call me Palardy)
VRC #3333
Team Role: College Student
 
Join Date: Mar 2009
Rookie Year: 2009
Location: Auburn Hills, MI
Posts: 1,347
apalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond repute
Re: Stall detection

Quote:
Originally Posted by evinugur View Post
This class is seriously inefficient. Suggestions:

-You are literally copying each value back an entry in the table with a For loop which is really really inefficient. A more efficient solution while still retaining the table of history would be to use a circular buffer where you set an arbitrary array index as the start and work back from there, looping around at one end to the other. Then, you can move the 'front' of the buffer forward and overwrite the oldest history element each time you sample the value. Then the process of inserting a sample requires only a memory write to a known array index, an increment of the circular buffer index, and a case to wrap it back to 0 at the end.

-It would be significantly more efficient to use a racheting error counter than a large RAM array which you For through each iteration. A racheting error counter woud use a single threshold on the current sample each time you sampled, and a counter of failures. A failure would increment the counter, a success would decrement the counter (limited to 0 and a number above your threshold). A certain counter value would be thresholded to declare stall. The comparison on the sample is only done once per sample (ever), instead of multiple times on the same sample, and the function call to read the stall state only has to perform a comparison on the counter. The reset is also simple, as you just set the counter to 0.
__________________
Kettering University - Computer Engineering
Kettering Motorsports
Williams International - Commercial Engines - Controls and Accessories
FRC 33 - The Killer Bees - 2009-2012 Student, 2013-2014 Advisor
VEX IQ 3333 - The Bumble Bees - 2014+ Mentor

"Sometimes, the elegant implementation is a function. Not a method. Not a class. Not a framework. Just a function." ~ John Carmack