Hello,
I am very new to programming in this language and my mentor had to take a leave of absence so this is what ive come up with ive had everything working except pneumatics. I have a test station set up to test it on seeing as the robot had to be bagged but im having issues with it ive never programmed pneumatics and after reading tons of info i still havhad no luck this is my code any suggestions would be much appreciated.
#include “WPILib.h”
//#DEFINE FIRST_SOLENOID 1
class RobotDemo : public SimpleRobot
{
RobotDrive myRobot; // robot drive system
Joystick stick; // only joystick
Victor Victor1;
Victor SFX_Shooter1_Victor3;
Victor SFX_Shooter2_Victor4;
Relay SFX_Loader_Victor5;
Relay SFX_Tiltmotor; //spike connected to motor
DigitalInput DigitalInput_High;
DigitalInput DigitalInput_Low;
Solenoid Sole1;
Compressor Compress;
//Solenoid Solenoid1;
float Shoot1_Victor3_float;
float Shoot2_Victor4_float;
float Loader_Victor5_float;
public:
RobotDemo(void):
myRobot(1, 2), // these must be initialized in the same order
stick(1), // as they are declared above.
Victor1(1),
SFX_Shooter1_Victor3(3),
SFX_Shooter2_Victor4(4),
SFX_Loader_Victor5(3),
SFX_Tiltmotor(1),
DigitalInput_High(1),
DigitalInput_Low(2),
//Solenoid1(3)
//Relay_Solenoid(2)
Sole1(4,4),
Compress(3,3)
{
myRobot.SetExpiration(0.1);
}
/**
* Drive left & right motors for 2 seconds then stop
*/
void Autonomous(void)
{
/*
myRobot.SetSafetyEnabled(false);
myRobot.Drive(-0.5, 0.0); // drive forwards half speed
Wait(2.0); // for 2 seconds
myRobot.Drive(0.0, 0.0); // stop robot
*/
SFX_Shooter1_Victor3.Set(1.0);
SFX_Shooter2_Victor4.Set(1.0);
}
/**
* Runs the motors with arcade steering.
*/
void OperatorControl(void)
{
myRobot.SetSafetyEnabled(true);
Compress.Start();
while (IsOperatorControl())
{
myRobot.ArcadeDrive(stick); // drive with arcade style (use right stick)
//Victor1.Set(1.0);
//Shoot1_Victor3_float = 1.0;
//Activates shooter at full speed with button 1
if(stick.GetRawButton(1)== 1){
SFX_Shooter1_Victor3.Set(1.0);
SFX_Shooter2_Victor4.Set(1.0);
} else{
SFX_Shooter1_Victor3.Set(0.0);
SFX_Shooter2_Victor4.Set(0.0);
}
//Actvates loader at full speed with button 2
if(stick.GetRawButton(2)==1){
SFX_Loader_Victor5.Set(Relay::kOn);
}else{
SFX_Loader_Victor5.Set(Relay::kOff);
}
//Activates tilt in either forward or reverse dependant on button and sensor
if((stick.GetRawButton(4)==1)&& (DigitalInput_High.Get()==0)) {
SFX_Tiltmotor.Set(Relay::kForward);
//SFX_Tiltmotor.Set(Relay::kOn);
}else if((stick.GetRawButton(5)==1) && (DigitalInput_Low.Get()==0)) {
SFX_Tiltmotor.Set(Relay::kReverse);
//SFX_Tiltmotor.Set(Relay::kOn);
}
else{
SFX_Tiltmotor.Set(Relay::kOff);
}
/*
if(stick.GetRawButton(6)==1){
//Solenoid1.Set(True);
Relay_Solenoid.Set(Relay::kForward);
Relay_Solenoid.Set(Relay::kOn);
}else{
Relay_Solenoid.Set(Relay::kOff);
}*/
if(stick.GetRawButton(7)==1){
Sole1.Set(TRUE);
}else{
Sole1.Set(FALSE);
}
// link
//SFX_Shooter1_Victor3 = Shoot1_Victor3_float;
Wait(0.005); // wait for a motor update time
}
Compress.Stop();
}
/**
* Runs during test mode
*/
void Test() {
}
};
START_ROBOT_CLASS(RobotDemo);
Jayson,
Can you give a specific issue here? Aside from combing through code and looking for the possibility of an error, it’s tough to give remote help without hearing ‘Doc - it hurts when I do THIS’ … 
Many folks have issues getting their compressor to run or to switch off due to the coupling of the relay with the pressure switch. Others have issues with getting a piston to move either due to incorrect pneumatic setup (physical issues with what tubes go where) or due to the solenoids which control them not being well understood or hooked up right.
I will say that your use of (4,4) and (3,3) for your Solenoid and Compressor are indeed suspicious though. The Compressor object takes two inputs for the relay and the pressure switch. A solenoid, on the other hand, while capable of taking two inputs is usually done via one input. Unless you’re doing something sophisticated, you should have your modules setup in your cRio in the default arrangement - in which case you should be instantiating your solenoid with a single argument for its channel #. By giving two input parameters, you are specifying both the channel and module number which is not likely what you’re intention is - in my estimation.
bob
It gives no errors the issue is that the compressor will not turn on and i cannot properly program the solenoid
I dont feel i fully understand where they are even supposed to be wired to i have never used pneumatics before! any help would be greatly appreciated!
Thanks Jayson
and if i try my compress.Start(); it does not recognize start?
What do you mean by “does not recognize start”?
The compressor should be connected to the M+ and M- on a Spike relay module. The fuse in the Spike should be replaced with a 20A snap-action circuit breaker. The Spike’s three-wire control cable (it’s the same as a PWM cable, but it isn’t actually carrying PWM signals in this case) should be connected to one of the relay outputs of the Digital Sidecar.
The pressure switch should be connected to the white (SIG) and black (-) wires of another PWM-style cable, with the red center wire (+5v) taped off and not connected to anything. The other end of the cable should be connected to one of the DIO inputs of the Digital Sidecar.
The compressor object should be initialized with two numbers, telling it which Relay port and which DIO port you have wired things to. When you call the Start() method (and enable the robot), the compressor should run when the pressure switch indicates that the pressure has fallen below 90 PSI and has not yet reached 115 PSI.
So my code should look like this to activate the compressor if im using relay port 2 and DIO port 3?
Also how do i program a double valve solenoid to extend with button 6 and retract with button 7?
ive tried many ways ive seen on here but no luck so far i shall continue to try but help is greatly appreciated.
#include “WPILib.h”
class RobotDemo : public SimpleRobot
{
RobotDrive myRobot; // robot drive system
Joystick stick; // only joystick
Victor SFX_Shooter1_Victor3;
Victor SFX_Shooter2_Victor4;
Jaguar SFX_Loader_Victor5;
Relay SFX_Tiltmotor; //spike connected to motor
DigitalInput DigitalInput_High;
DigitalInput DigitalInput_Low;
float Shoot1_Victor3_float;
float Shoot2_Victor4_float;
float Loader_Victor5_float;
public:
RobotDemo(void):
myRobot(1, 2), // these must be initialized in the same order
stick(1), // as they are declared above.
SFX_Shooter1_Victor3(3),
SFX_Shooter2_Victor4(4),
SFX_Loader_Victor5(5),
SFX_Tiltmotor(1),
DigitalInput_High(1),
DigitalInput_Low(2),
Compress(2,3)
{
myRobot.SetExpiration(0.1);
}
/**
* Drive left & right motors for 2 seconds then stop
*/
void Autonomous(void)
{
SFX_Shooter1_Victor3.Set(1.0);
SFX_Shooter2_Victor4.Set(1.0);
SFX_Loader_Victor5.Set(Relay::kOn);
}
/**
* Runs the motors with arcade steering.
*/
void OperatorControl(void)
{
myRobot.SetSafetyEnabled(true);
Compress.Start();
while (IsOperatorControl())
{
myRobot.ArcadeDrive(stick); // drive with arcade style (use right stick)
//Activates shooter at full speed with button 1
if(stick.GetRawButton(1)== 1){
SFX_Shooter1_Victor3.Set(1.0);
SFX_Shooter2_Victor4.Set(1.0);
} else{
SFX_Shooter1_Victor3.Set(0.0);
SFX_Shooter2_Victor4.Set(0.0);
}
//Actvates loader at full speed with button 2
if(stick.GetRawButton(2)==1){
SFX_Loader_Victor5.Set(Relay::kOn);
}else{
SFX_Loader_Victor5.Set(Relay::kOff);
}
//Activates tilt in either forward or reverse dependant on button and sensor
if((stick.GetRawButton(4)==1)&& (DigitalInput_High.Get()==0)) {
SFX_Tiltmotor.Set(Relay::kForward);
//SFX_Tiltmotor.Set(Relay::kOn);
}else if((stick.GetRawButton(5)==1) && (DigitalInput_Low.Get()==0)) {
SFX_Tiltmotor.Set(Relay::kReverse);
//SFX_Tiltmotor.Set(Relay::kOn);
}
else{
SFX_Tiltmotor.Set(Relay::kOff);
}
/*
if(stick.GetRawButton(6)==1){
//Solenoid1.Set(True);
Relay_Solenoid.Set(Relay::kForward);
Relay_Solenoid.Set(Relay::kOn);
}else{
Relay_Solenoid.Set(Relay::kOff);
}*/
Wait(0.005); // wait for a motor update time
}
Compress.Stop();
}
void Test() {
}
};
START_ROBOT_CLASS(RobotDemo);
and as an error it tells me it does not recognize start as a function
That’s close, but you never declared Compress as a compressor object. I don’t know why you named your Jaguar using the word Victor, but you sure shouldn’t be trying to control it by setting its output with Relay constants instead of numbers.
It’s not easy to read the code with no indented lines. If you put **CODE] and **/CODE] tags around it, it will render much better.
If you copy the actual error message instead of paraphrasing it, we’ll be better able to interpret it for you. My guess right now is that it’s telling you that Compress.Start() is not a function because Compress doesn’t actually exist.
Taking a quick look at your code,
You stated that you have your pressure switch connected to digital 3, and your relay (that is then connected to the compressor) connected to relay 2 as well. In this case you have the Compressor instantiation in the wrong order. It should be Compress(3,2).
Also as noted by Alan, you have not declared your compressor object. You need to add the line: “Compressor Compress;” somewhere before the constructor… which starts with the lines
“public:
RobotDemo(void):”
I also noticed that you are not calling Compressor.Start() until the OperatorControl function which will not run until the robot is enabled in TeleOp. We generally start that process from our constructor (in your case this could be right after the line “myRobot.SetExpiration(0.1);”).
Also, are you getting any error messages displayed on the driverstation or the netconsole? Or is it just not working? Are you seeing a proper value on the digital input? (You can read this using: DigitalModule::GetInstance(1)->GetDIO(3)) and then printing to the netconsole or displaying on the dashboard).
If you see the digital correctly then is the relay being set? Do you see the LED next to relay 3 changing from color on the digital side car? Is it also changing on the relay itself? If either of these is not true then it could also be a wiring issue.
Hope this helps.