Go to Post you must understand when wearing that FIRST Volunteer shirt, you personally & directly represent FIRST, and you do the best job for FIRST as an organization, that you can in performing that job....Period. - cglrcng [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 22-02-2010, 18:30
superstretch superstretch is offline
Registered User
FRC #0417
 
Join Date: Feb 2010
Location: Mt Sinai
Posts: 7
superstretch is an unknown quantity at this point
Solenoid Code Does Not Work!

We are using 12volt solenoids hooked up through the solenod break out. Everything in the code so far works besides the solenoids. The lights on the module don't light up either. The solenoids work and the pistons fire when the buttons are pressed manually.

Quote:
#include "WPILib.h"

/**
* This is a demo program showing the use of the RobotBase class.
* The SimpleRobot class is the base of a robot application that will automatically call your
* Autonomous and OperatorControl methods at the right time as controlled by the switches on
* the driver station or the field controls.
*/
class MyCode : public SimpleRobot
{
RobotDrive *myRobot; // robot drive system pointer
Joystick *stick; // arcade drive joystick pointer
DriverStation *ds; // driver station object
Solenoid *s1;
Solenoid *s2;
Solenoid *s3;
Solenoid *s4;
Solenoid *s5;
Solenoid *s6;
Compressor *c;
bool btn1state;
bool btn2state;
bool btn6state;
bool btn7state;
bool quickReleaseState;
bool resetPistonState;


public:
/**
*
*
* Constructor for this robot subclass.
* Create an instance of a RobotDrive with left and right motors plugged into PWM
* ports 1 and 2 on the first digital module.
*/
MyCode(void)
{
ds = DriverStation::GetInstance();
myRobot = new RobotDrive(1, 2); // create robot drive base
stick = new Joystick(1); // create the joystick
s1 = new Solenoid(1); // allocate the Solenoid objects
s2 = new Solenoid(1);
s3 = new Solenoid(1);
s4 = new Solenoid(1);
s5 = new Solenoid(1);
s6 = new Solenoid(1);
c = new Compressor(1,1);
c->Start();

GetWatchdog().SetExpiration(5.0);
//AxisCamera &myCamera = AxisCamera::getInstance();

}

/**
* Drive left & right motors for 2 seconds, enabled by a jumper (jumper
* must be in for autonomous to operate).
*/
void Autonomous(void)
{
GetWatchdog().SetEnabled(false);

for (int j = 0; j<3; j++)
{
// myRobot->Drive(0.5, 0.0); // drive forwards half speed
s1->Set(true); //activate quick release retract
Wait(1.0);
s1->Set(false); //for 2 seconds
s3->Set(true); //activate reset piston extend
Wait(1.0);
s3->Set(false);
s2->Set(true); //activate quick release piston extend
Wait(1.0);
s2->Set(false);
s4->Set(true); //activate reset piston retract
Wait(1.0);
s4->Set(false);
}
myRobot->Drive(0.0, 0.0); // stop robot

GetWatchdog().SetEnabled(true);
}

/**
* Runs the motors under driver control with either tank or arcade steering selected
* by a jumper in DS Digin 0. Also an arm will operate based on a joystick Y-axis.
*/
void OperatorControl(void)
{
btn1state = 0;
btn2state = 0;
btn6state = 0;
btn7state = 0;
quickReleaseState = 1; //quick release piston is extended
resetPistonState = 0; //reset pistion is retracted


while (IsOperatorControl())
{
GetWatchdog().Feed();

myRobot->ArcadeDrive(stick); // drive with arcade style

if (stick->GetRawButton(1) && !btn1state) //button is pressed but not being held
{
btn1state = 1; //button is being pressed
s1->Set(true); //activate quick release retract
Wait(1.0); //for 2 seconds
s1->Set(false); //reset state
s1->Set(true); //activate reset piston extend
Wait(1.0);
s3->Set(false); //restet state
s2->Set(true); //activate quick release piston extend
Wait(1.0);
s2->Set(false); //reset state
s4->Set(true); //activate reset piston retract
Wait(1.0);
s4->Set(false); //reset state

}

else if(!stick->GetRawButton(1) && btn1state) //button is not being pressed
{
btn1state = 0; //reset state
}

if (stick->GetRawButton(6) && !btn6state)
{
btn6state = 1;

if (quickReleaseState)
{
s2->Set(false);
s1->Set(true); //activate quick release retract
quickReleaseState = 0; //quick release piston is retracted
}

else
{
s1->Set(false);
s2->Set(true); //activate quick release extend
quickReleaseState = 1; //quick release piston is extended
}

}
else if(!stick->GetRawButton(6) && btn6state) //button is not being pressed
{
btn6state = 0; //reset state
}

if (stick->GetRawButton(7) && !btn7state)
{
btn7state = 1;

if (!resetPistonState)
{
s4->Set(false);
s3->Set(true); //activate reset extend
resetPistonState = 1; //reset piston is extended
}

else
{
s3->Set(false);
s4->Set(true); //activate reset retract
resetPistonState = 0; //reset piston is retracted
}

}
else if(!stick->GetRawButton(7) && btn7state) //button is not being pressed
{
btn7state = 0; //reset state
}


}
}
};

START_ROBOT_CLASS(MyCode);
What is wrong with my code? Please help me!
Reply With Quote
  #2   Spotlight this post!  
Unread 22-02-2010, 18:45
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 667
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Solenoid Code Does Not Work!

You posted long code without indentation. Use the "#" button the next time. I didn't look through the entire code because of the readability but for the first mistake, you were creating six solenoids on the same DO channel (channel 1)???
Reply With Quote
  #3   Spotlight this post!  
Unread 22-02-2010, 18:58
superstretch superstretch is offline
Registered User
FRC #0417
 
Join Date: Feb 2010
Location: Mt Sinai
Posts: 7
superstretch is an unknown quantity at this point
Re: Solenoid Code Does Not Work!

well, thats embarrasing... sorry

also, thanks for the tip on posting code
Edit: if i repost the code with proper format would you mind giving it a look over for any other obvious mistakes?

Last edited by superstretch : 22-02-2010 at 19:01.
Reply With Quote
  #4   Spotlight this post!  
Unread 22-02-2010, 19:05
superstretch superstretch is offline
Registered User
FRC #0417
 
Join Date: Feb 2010
Location: Mt Sinai
Posts: 7
superstretch is an unknown quantity at this point
Re: Solenoid Code Does Not Work!

I suppose that also explains the error:
Quote:
Fatal error "Attempting to reuse an allocated resource" in Allocate() in C:/WindRiver/workspace/WPLib/Resource.cpp at line 76
that I was getting in the diagnostics tab
Reply With Quote
  #5   Spotlight this post!  
Unread 22-02-2010, 19:08
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 667
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Solenoid Code Does Not Work!

Yep.
Reply With Quote
  #6   Spotlight this post!  
Unread 22-02-2010, 19:10
superstretch superstretch is offline
Registered User
FRC #0417
 
Join Date: Feb 2010
Location: Mt Sinai
Posts: 7
superstretch is an unknown quantity at this point
Re: Solenoid Code Does Not Work!

My code with formatting preserved:

Code:
#include "WPILib.h"

/**
 * This is a demo program showing the use of the RobotBase class.
 * The SimpleRobot class is the base of a robot application that will automatically call your
 * Autonomous and OperatorControl methods at the right time as controlled by the switches on
 * the driver station or the field controls.
 */
class MyCode : public SimpleRobot
{
	RobotDrive *myRobot;			// robot drive system pointer
	Joystick *stick;				// arcade drive joystick pointer
	DriverStation *ds;				// driver station object
	Solenoid *s1;
	Solenoid *s2;
	Solenoid *s3;
	Solenoid *s4;
	Solenoid *s5;
	Solenoid *s6;
	Compressor *c;
	bool btn1state;
	bool btn2state;
	bool btn6state;
	bool btn7state;
	bool quickReleaseState;
	bool resetPistonState;


public:
	/**
	 * 
	 * 
	 * Constructor for this robot subclass.
	 * Create an instance of a RobotDrive with left and right motors plugged into PWM
	 * ports 1 and 2 on the first digital module.
	 */
	MyCode(void)
	{
		ds = DriverStation::GetInstance();
		myRobot = new RobotDrive(1, 2);			// create robot drive base
		stick = new Joystick(1);				// create the joystick
		s1 = new Solenoid(1);					// allocate the Solenoid objects
		s2 = new Solenoid(2);
		s3 = new Solenoid(3);
		s4 = new Solenoid(4);
		s5 = new Solenoid(5);
		s6 = new Solenoid(6);
		c = new Compressor(1,1);
		c->Start();
		
		GetWatchdog().SetExpiration(5.0);
		//AxisCamera &myCamera = AxisCamera::getInstance();
		
	}

	/**
	 * Drive left & right motors for 2 seconds, enabled by a jumper (jumper
	 * must be in for autonomous to operate).
	 */
	void Autonomous(void)
	{
		GetWatchdog().SetEnabled(false);
		
			for (int j = 0; j<3; j++)
			{
//			myRobot->Drive(0.5, 0.0);			// drive forwards half speed
			s1->Set(true);					//activate quick release retract
			Wait(1.0);
			s1->Set(false);					//for 2 seconds
			s3->Set(true);					//activate reset piston extend
			Wait(1.0);
			s3->Set(false);
			s2->Set(true);					//activate quick release piston extend
			Wait(1.0);
			s2->Set(false);
			s4->Set(true);					//activate reset piston retract
			Wait(1.0);
			s4->Set(false);
			}
			myRobot->Drive(0.0, 0.0);			// stop robot
			
		GetWatchdog().SetEnabled(true);
	}

	/**
	 * Runs the motors under driver control with either tank or arcade steering selected
	 * by a jumper in DS Digin 0. Also an arm will operate based on a joystick Y-axis. 
	 */
	void OperatorControl(void)
	{
		btn1state = 0;
		btn2state = 0;
		btn6state = 0;
		btn7state = 0;
		quickReleaseState = 1; 					//quick release piston is extended
		resetPistonState = 0;					//reset pistion is retracted

	
		while (IsOperatorControl())
		{
			GetWatchdog().Feed();
			
				myRobot->ArcadeDrive(stick);	 // drive with arcade style
				
			if (stick->GetRawButton(1) && !btn1state) //button is pressed but not being held
			{
				btn1state = 1;						//button is being pressed
				s1->Set(true);					//activate quick release retract
				Wait(1.0);							//for 2 seconds
				s1->Set(false);					//reset state
				s1->Set(true);					//activate reset piston extend
				Wait(1.0);
				s3->Set(false);					//restet state
				s2->Set(true);					//activate quick release piston extend
				Wait(1.0);
				s2->Set(false);					//reset state
				s4->Set(true);					//activate reset piston retract
				Wait(1.0);
				s4->Set(false);					//reset state
				
			}
			
			else if(!stick->GetRawButton(1) && btn1state) //button is not being pressed
			{
				btn1state = 0;						//reset state
			}
			
			if (stick->GetRawButton(6) && !btn6state)
			{
				btn6state = 1;
				
				if (quickReleaseState)
				{
					s2->Set(false);
					s1->Set(true);					//activate quick release retract
					quickReleaseState = 0;				//quick release piston is retracted
				}
				
				else
				{
					s1->Set(false);
					s2->Set(true);					//activate quick release extend
					quickReleaseState = 1;				//quick release piston is extended
				}
				
			}
			else if(!stick->GetRawButton(6) && btn6state) //button is not being pressed
			{
				btn6state = 0;						//reset state
			}
				
			if (stick->GetRawButton(7) && !btn7state)
			{
				btn7state = 1;
				
				if (!resetPistonState)
				{
					s4->Set(false);
					s3->Set(true);					//activate reset extend
					resetPistonState = 1;				//reset piston is extended
				}
				
				else
				{
					s3->Set(false);
					s4->Set(true);					//activate reset retract
					resetPistonState = 0;				//reset piston is retracted
				}
				
			}
			else if(!stick->GetRawButton(7) && btn7state) //button is not being pressed
			{
				btn7state = 0;						//reset state
			}
			

		}
	}
};

START_ROBOT_CLASS(MyCode);
thanks for any and all help
Reply With Quote
  #7   Spotlight this post!  
Unread 22-02-2010, 19:27
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 667
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Solenoid Code Does Not Work!

Assuming your code is reflecting the connection of channels accurately, the code looks find. However, without knowing what the solenoid configurations are, I would guess there is one more mistake.
Code:
			if (stick->GetRawButton(1) && !btn1state) //button is pressed but not being held
			{
				btn1state = 1;						//button is being pressed
				s1->Set(true);					//activate quick release retract
				Wait(1.0);							//for 2 seconds
				s1->Set(false);					//reset state
				s1->Set(true); <<< Should this be s3???					//activate reset piston extend
				Wait(1.0);
				s3->Set(false);					//restet state
				s2->Set(true);					//activate quick release piston extend
				Wait(1.0);
				s2->Set(false);					//reset state
				s4->Set(true);					//activate reset piston retract
				Wait(1.0);
				s4->Set(false);					//reset state
				
			}
Reply With Quote
  #8   Spotlight this post!  
Unread 22-02-2010, 19:38
superstretch superstretch is offline
Registered User
FRC #0417
 
Join Date: Feb 2010
Location: Mt Sinai
Posts: 7
superstretch is an unknown quantity at this point
Re: Solenoid Code Does Not Work!

ooh, nice catch, thank you.
Gah still 12hours till i can test my code again!
Reply With Quote
  #9   Spotlight this post!  
Unread 23-02-2010, 10:30
Mageofdancingdr's Avatar
Mageofdancingdr Mageofdancingdr is offline
Mageofdancingdragons
AKA: DJ Hoffman
FRC #0599 (Robodox)
Team Role: Alumni
 
Join Date: Jan 2008
Rookie Year: 2008
Location: Los Angeles
Posts: 24
Mageofdancingdr is an unknown quantity at this point
Re: Solenoid Code Does Not Work!

also, one of the simplest ways to mess up that pneumatics board is double checking that it's in slot 8 on the CRIO and using the constructor that specifies slot as well as channel, for code clarity mostly.
__________________
3.1415926535897932384626433832
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Solenoid code not working ssmith2 NI LabVIEW 6 03-02-2010 10:11
Eclipse does not work jasonpeinko Programming 7 22-02-2008 09:51
Autonomous mode does not work Sunny Programming 9 16-01-2008 15:31
Arcade Mode (12) does NOT work jakk Programming 2 10-07-2006 19:27
Chaos theory does not work!!!!! S9ar7acu3 General Forum 3 09-02-2003 11:46


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

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