Take a quick look at our code?

I won’t be able to get to our robot again until ship day. I’d like to be able to walk in on Tuesday and deploy a working program.

This is our first time programming in C++ so we would appreciate any pointers (no pun intended).

What we need:

Tank drive
Compressor
Solenoids controlling 2 actuators

Here’s what I have:


#include "WPILib.h"

class Robot3842 : public SimpleRobot
{
	RobotDrive rd; // robot drive system
	
	Joystick lstick;
	Joystick rstick;

	Compressor compress;
	
	Solenoid armUp;
	Solenoid armDn;
	
	Solenoid miniOut;
	Solenoid miniIn;
	
public:
	Robot3842(void):
		rd(1, 2),	// these must be initialized in the same order
		lstick(1),		// as they are declared above.
		rstick(2),

		compress(14, 1),
	
		armUp(8, 1),
		armDn(8, 2),
		
		miniOut(8, 3),
		miniIn(8, 4)
	{
		rd.SetExpiration(0.1);
		
		compress.Start();
		
		armUp.Set(true);
		armDn.Set(false);
		
		miniOut.Set(false);
		miniIn.Set(true);
	}


	void Autonomous(void)
	{
		rd.SetSafetyEnabled(false);
		rd.Drive(0.5, 0.0); 	// drive forwards half speed
		Wait(2.0); 				//    for 2 seconds
		rd.Drive(0.0, 0.0); 	// stop robot
	}

	void OperatorControl(void)
	{
		rd.SetSafetyEnabled(true);

		while (IsEnabled() && IsOperatorControl())
		{
			rd.TankDrive(lstick, rstick);
			Wait(0.005);				// wait for a motor update time
			
			if (rstick.GetRawButton(1)){
				armUp.Set(false);
				armDn.Set(true);
			} else if (rstick.GetRawButton(2)){
				armUp.Set(true);
				armDn.Set(false);
			}
			
			if (rstick.GetRawButton(10)){
				miniOut.Set(true);
				miniIn.Set(false);
			} else if (rstick.GetRawButton(7)){
				miniOut.Set(false);
				miniIn.Set(true);
			}
		}
	}
};

START_ROBOT_CLASS(Robot3842);



It compiles, so that is a start.

Thanks for your help!

I don’t have much experience with the pneumatics, so I’ll let someone else help out with that.

One thing I noticed is that the “IsEnabled()” part of your while loop is redundant (I’m pretty sure). It’s my understanding that the program shuts down all outputs when it’s disabled, so even though it might run that code, it won’t actually move the motors or solenoids.

As far as I can tell, you’re drive and joysticks seem right.

To use the compressor, you must first declare it in the .h file in the inout interface using Compressor name where name is whatever you want to name the compressor in the code. Then, you set it up in the .cpp file by putting in these two values like this: name(x, y). x is the spike channel and y is the pressure regulator channel. If you have already done all this correctly, then the only other thing to check is if moving compress.Start() to the OperatorControl method right here will work

void OperatorControl(void)
	{
		rd.SetSafetyEnabled(true);
                          compress.Start();		
                          while (IsEnabled() && IsOperatorControl())
		{

I would strongly recommend you add the following cases:


if (rstick.GetRawButton(1)){
	armUp.Set(false);
	armDn.Set(true);
} else if (rstick.GetRawButton(2)){
	armUp.Set(true);
	armDn.Set(false);
} else {
	armUp.Set(false);
	armDown.Set(false);
}
			
if (rstick.GetRawButton(10)){
	miniOut.Set(true);
	miniIn.Set(false);
} else if (rstick.GetRawButton(7)){
	miniOut.Set(false);
	miniIn.Set(true);
} else {
	miniOut.Set(false);
	miniIn.Set(false);
}

As you have it at the moment, if you press, say, button 10 on the joystick, the miniOut solenoid will activate, but will not turn off if you release the button. That’s probably not what you would want it to do.