View Single Post
  #1   Spotlight this post!  
Unread 20-02-2011, 16:48
tux tux is offline
Registered User
AKA: Lee Harr
FRC #3842 (Shock-a-Bots)
Team Role: Mentor
 
Join Date: Apr 2005
Rookie Year: 2005
Location: Rochester, NY
Posts: 91
tux is an unknown quantity at this point
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:

Code:
#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!
Reply With Quote