View Single Post
  #3   Spotlight this post!  
Unread 14-12-2011, 18:42
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: Target Exception Error from Solenoid Array

I see a few problems:

-You lack a semicolon on the line that is bad; C generally prefers semicolons (although I suspect you did not copy-paste the code, but rather re-typed it)

-You are assigning 4 buttons to toggle the state of 4 pistons when pressed (yes?), however, it appears as though the If will run every cycle that the button is pressed (constantly inverting/setting the piston while the button is held), you would need a check to see if the button is pressed but wasn't last iteration.

-Is there any need for states and prestates? Couldn't you just say
Code:
state[b] = !state[b]; solenoid[b]->set(state[b]);
and get the same result?

-What are you doing where you need an array of solenoids? In embedded programming such as FRC robots, I've always hated working with arrays of objects, as most objects we use have a specific purpose and are handled in different ways (depending on the subsystem they operate under, for example), and usually robots are simple enough where having a few references isn't a bad or messy thing.
__________________
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