Our electronics team has decided to use the solenoid (sp?) breakout on the cRio this year. My question is … how do you define a solenoid (sp?) and control it in C++?
You use the (big surprise… spoiler alert…) Solenoid class. Pass the channel (and optionally the module slot) to the constructor. Then call Set to set the value. Probably the simplest class in the library.
I’m guessing you posted this before looking at the library. Or did you have a specific question that you forgot to include?
I tried getting this to work today; I managed to get a green light on the solenoid breakout, but after defining the solenoid objects, using the Set() function did nothing.
Our code looks something like this.
Solenoid *solenoidOne;
Solenoid *solenoidTwo;
solenoidOne = new Solenoid(1);
solenoidTwo = new Solenoid(2);
Into operator code…
if(joystick->GetTrigger()) {
solenoidOne->Set(true);
solenoidTwo->Set(false);
}
else {
solenoidOne->Set(false);
solenoidTwo->Set(true);
}
I might be doing something completely wrong here. This our first year using pneumatics with the new control system, so I’m a bit confused. The code manages to get into the if statement, but the solenoid commands do nothing. Is there anything glaringly wrong that you can see?
We were having the same problem today on our robot, does your solenoid have little buttons you can press to release pressure also? If so try pressing them and if it works it means you have your solenoid wired correctly.
Before we do any detailed debugging, did you remember to Enable the robot?
Yes. Everything else ran fine, (except for the stuttering caused by the watchdog glitch) including the jaguars and camera feed. We just plugged the solenoid breakout into the cRIO and then ran two wires from the solenoid breakout, one to each end of the solenoid assembly. Again, we haven’t used the new system to control pneumatics, so I may be missing a critical step here.
Which slot did you plug the module into? The code expects it in slot 8 by default. Do you have the compressor working? Most solenoid valves won’t do anything without air pressure. Have you observed whether or not the green lights on the cRIO digital output module are changing when you press the trigger?
I’m pretty sure we didn’t have it in slot eight; we were running the compressor off an external battery, so that code wouldn’t be the problem. Why would the cRIO digital output be affected? We’re running the solenoids from the solenoid breakout, right?
EDIT: We hooked the solenoid breakout to the 9472 module in slot eight. We connected the two cables to either side of the solenoid and used the code above…but nothing worked.
The buttons on the solenoid do work for switching, but the trigger does not.
The solenoid breakout had better be on the digital output module, or it won’t do anything.
EDIT: We hooked the solenoid breakout to the 9472 module in slot eight. We connected the two cables to either side of the solenoid and used the code above…but nothing worked.
You’re providing power to the solenoid breakout, right? The voltage needs to match what the solenoid expects, either 12 or 24 volts, following the power diagram on the FIRST web site.
When you say “nothing worked”, does that include no green lights on the output module?
We solved our problem; it turned out to be a multitude of different problems with our code. I changed the code from using “true” and “false” to using “0” and “1” and also moved the module to slot eight. By removing all of our code except the solenoid commands, we were able to get the solenoid to switch back and forth between the two outputs every few seconds. Thanks!
shouldn’t using true/false or 1/0 not make a difference?
That probably didn’t; we changed a few things to make it work. But it works now, so I’m not worried.