View Single Post
  #8   Spotlight this post!  
Unread 24-02-2014, 10:56
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: BCD switch programming

Quote:
Originally Posted by Sparkyshires View Post
Yeah we do, with boolean values holding the state of most mechanism on the robot. I'm being a bit dense, but I fail to see how a switch case could be used for that.
If you need more than two states, you could use an unsigned integer or enum (which is effectively a uint with names) and a Switch through all of them.

For example, a shot sequencer last year had three states: idle, fire_execute, and fire_retract. It transitioned in a 'circle', with a condition from idle to fire_execute (fire trigger input), two conditions to return from fire_execute to fire_retract (gun speed accel threshold met, or failure timer met) and a timer to return to idle (shot interval reset timer). We could represent this with the following C code:

Code:
typedef enum {
stIDLE,
stFIRE_EXECUTE,
stFIRE_RETRACT
} fire_seq_t;

fire_seq_t state = stIDLE;

/* Somewhere in a temporal task */
switch(state) {
 case stIDLE:
  if(FIRE)
  {
   state = stFIRE_EXECUTE;
  }
 output_piston = 0;
 break;
 case stFIRE_EXECUTE:
  if(GSA_TRIG || TIMER > FIRE_FAIL_TIME)
  {
   state = stFIRE_RETRACT;
  }
 output_piston = 1;
 break;
 case stFIRE_RETRACT:
  if(TIMER > RETRACT_TIME)
  {
   state = stIDLE;
  }
  output_piston = 0;
  break;
}
__________________
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