Go to Post Teams whose goal is to play on Einstein think about strategy differently from teams whose goal is to be selected for an alliance at a district event. - alopex_rex [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #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
  #2   Spotlight this post!  
Unread 20-02-2011, 18:35
CodeMonkeyMatt CodeMonkeyMatt is offline
Registered User
FRC #2605
 
Join Date: Jan 2011
Rookie Year: 2008
Location: WA
Posts: 46
CodeMonkeyMatt is on a distinguished road
Re: Take a quick look at our code?

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.
Reply With Quote
  #3   Spotlight this post!  
Unread 22-02-2011, 20:36
Matthew Blake's Avatar
Matthew Blake Matthew Blake is offline
Registered User
FRC #3481 (Bronc Botz)
 
Join Date: Feb 2011
Rookie Year: 2009
Location: Helotes, Texas
Posts: 43
Matthew Blake is an unknown quantity at this point
Re: Take a quick look at our code?

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

Code:
void OperatorControl(void)
	{
		rd.SetSafetyEnabled(true);
                          compress.Start();		
                          while (IsEnabled() && IsOperatorControl())
		{
__________________
FTC Team 4008: 2009-2012
FTC Team 4602: 2010-2012
FRC Team 3481: 2010-2012
Reply With Quote
  #4   Spotlight this post!  
Unread 30-03-2011, 23:40
Dacilndak's Avatar
Dacilndak Dacilndak is offline
Matt'); DROP TABLE Users; --
AKA: Matthew Haney
FRC #3729 (Red Knights)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Denver, Colorado
Posts: 12
Dacilndak is an unknown quantity at this point
Re: Take a quick look at our code?

Quote:
Originally Posted by tux
Code:
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);
}
I would strongly recommend you add the following cases:

Code:
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.
__________________
Team 3729 - Raiders - Programming Team Co-Captain
2011 Colorado Regional Semifinalist
2011 Colorado Regional Rookie All-Star Award
2011 Colorado Regional Highest Rookie Seed Award
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 13:07.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi