Go to Post Just goes to show that you don't need to be like everyone else to make it to Einstein. - O'Sancheski [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 12-02-2013, 07:51
evinugur evinugur is offline
Registered User
FRC #1073
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2010
Location: US
Posts: 13
evinugur is an unknown quantity at this point
Lightweight Extensions to WPILib (C++)

I've developed some classes throughout the course of build season this year that have extend off some WPILib classes to provide added functionality.

https://github.com/FRCTeam1073-TheFo...ILibExtensions

I pushed them into another repository so that they can be easily cloned if you're interested.

Some features include a base class for stall detection on Jaguars and analog channels, as well as a Joystick extension that provides support for different drive modes.

Check it out! There's a lot more that can be done with this, and my thinking is that a lot of other teams have to frequently build off WPILib to add a feature that they need. If you've done this in the past, please fork and submit a pull request so we can build a more comprehensive library of features that people might need to use. This might be helpful to teams who are tight on time or with rookie programmers.

Good luck in your competitions. 7 days left ...
  #2   Spotlight this post!  
Unread 12-02-2013, 09:14
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: Lightweight Extensions to WPILib (C++)

-For stallable, there's a much more efficent way to implement this that dosen't require For loops (those are always the enemy of realtime embedded controls) - using a racheting error counter. Basically, you have a single number which is the number of iterations of good or bad data. You sample the data at a constant frequency and perform the delta comparison each time. If the data is good, you decrement the error counter by some number (for 100hz systems, 3 or 4 seems about right). If the data is bad, you increment the counter. To sample the state, you return a gt check on the counter vs a constant. To reset the state, you just reset the counter to 0.

psudocode:
Quote:
double val_last;
char counter;
#define VAL_NOISE_THRESH_LT 0.1
#define STALL_CNT_GT 10
bool is_stalled(double ana_val, bool reset)
{
if(abs(val_last - ana_val) < VAL_NOISE_THRESH_LT))
{
counter++;
}
else
{
counter -= 3;
}
counter = max(counter,0);
counter = min(counter,(VAL_NOISE_THRESH_LT + 2));

if(reset)
{
counter=0;
}

val_last = ana_val;

return(counter > STALL_CNT_GT);
}

You could also replace the entire limit switch class with an inlined function for efficiency. Also, I believe you want the comparison to be 0== instead of 1== due to the pull-up resistor (the logic line would idle high and be pulled low by pressing the switch, a 0== compare would return 1 when the switch is pressed).
__________________
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
  #3   Spotlight this post!  
Unread 12-02-2013, 14:08
evinugur evinugur is offline
Registered User
FRC #1073
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2010
Location: US
Posts: 13
evinugur is an unknown quantity at this point
Re: Lightweight Extensions to WPILib (C++)

Greetings apalrd,

Thank you very much for your sound advice. I did not know what an inline function was in C++ until you gave me your suggestion to implement one it did make sense to use a simple function.

Originally we had thought of using a Queue for Stallable so that we could easily push data through (we shuffle through our array of collected voltages right now), but the rookie we were working with did not know much about programming so we thought it would be a good idea to teach her some basic concepts like looping and such before handing her more complicated data structures. Even though iterative looping might not be the best approach on our hardware, the array is very tiny, and we have a hefty 700Mhz processor to work with so we should be fine for now.
Your solution was still much more efficient than dancing through a queue, and we will implement it once we're actually done with our main robot code.

Cheers
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 02:29.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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