Go to Post Just wear your safety glasses. They can be stylish, too! - Eugenia Gabrielov [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 08-02-2017, 20:40
charlier999's Avatar
charlier999 charlier999 is offline
Registered User
FRC #1662 (Raptor Force Engineering)
Team Role: Programmer
 
Join Date: Feb 2017
Rookie Year: 2013
Location: Lodi, CA
Posts: 19
charlier999 is an unknown quantity at this point
Post Pneumatics code problems.

Recently, I have been dealing with newly written pneumatics code not actuating Cylinders for a gear holder and shifters.
This is what I am trying to do
PHP Code:
"A" button is pressed Cylinder extends > "A" button is pressed again Cylinder retracts 
I have tried to use a bool to act as a to swich between True and False when the cylinder extends or retracts, but that didn't do what I wanted above. Is there any other way of doing this.

Please ignore spelling mistakes in comments in code
If there is any other mistakes in the code that are not related to Pneumatics, feel free to say so.
Robot Code \/
Code:
#include <iostream>
#include <memory>
#include <string>
#include <IterativeRobot.h>
#include <LiveWindow/LiveWindow.h>
#include <SmartDashboard/SendableChooser.h>
#include <SmartDashboard/SmartDashboard.h>
#include "WPILib.h"
#include "CANTalon.h"

class Robot: public frc::IterativeRobot {
public:
//-------------------------------------------------------//
//    Other Decerations                                  //
//-------------------------------------------------------//
	bool shifter_varable = true;
	bool gear_enabled = false;
//-------------------------------------------------------//
//   Deceration of Objects                               //
//-------------------------------------------------------//
	Joystick *driver;
	Joystick *driverV2;
	Joystick *op;

	CANTalon *drive_right_a, *drive_right_b, *drive_left_a, *drive_left_b;
	CANTalon *intake;
	CANTalon *aggitater;
	CANTalon *shooter;
	CANTalon *climber;

	RobotDrive *drive_base;

	Compressor *compressor;

	DoubleSolenoid *gear;
	DoubleSolenoid *shifter;

	//WIP  \/
	//Encoder *shooter_encoder;

	Robot() {
//-------------------------------------------------------//
//    Asigning Objects to Componints and Electronics     //
//-------------------------------------------------------//
		driver = new Joystick(0);
		op = new Joystick(1);
		driverV2 = new Joystick(2);

		drive_right_a = new CANTalon(8);
		drive_right_b = new CANTalon(9);
		drive_left_a = new CANTalon(1);
		drive_left_b = new CANTalon(2);

		intake = new CANTalon(4);
		shooter = new CANTalon(7);
		climber = new CANTalon(6);
		aggitater = new CANTalon(3);

		drive_base = new RobotDrive(drive_right_a, drive_right_b, drive_left_a, drive_left_b);

		compressor = new Compressor(0);

		gear = new DoubleSolenoid(1, 3);
		shifter = new DoubleSolenoid(2, 4);
	}
	void RobotInit() {
//-------------------------------------------------------//
//                Robot vision Code                      //
//-------------------------------------------------------//
		auto cam = frc::CameraServer::GetInstance();
		cam->StartAutomaticCapture();
//-------------------------------------------------------//
//                Robot Compressor                       //
//-------------------------------------------------------//
		compressor->SetClosedLoopControl(true);
	}

	void AutonomousInit() override {}

	void AutonomousPeriodic() {
		drive_right_a->Set(1.0);
	}

	void TeleopInit() {}

	void TeleopPeriodic() {

		// drive train; (left joystick; y axis; left drive) (right joystick: y axis; right drive)
		drive_base->TankDrive(-driver->GetRawAxis(1), -driver->GetRawAxis(5));
//-------------------------------------------------------//
//                 Drive Remote                          //
//-------------------------------------------------------//

		//shooter; left bumper
		if(driver->GetRawButton(5)) {
			shooter->Set(0.60);
		}else{
			shooter->Set(0.0);
		}

		//intake in; right trigger
		if (driver->GetRawButton(7)) {
			intake->Set(-1.0);
		}else{
			intake->Set(0.0);
		}

		//aggitator; "B" button
		if (driver->GetRawButton(3)){
			aggitater->Set(1.0);
		}else{
			aggitater->Set(0.0);
		}

		//shifters; "A" button
		if (driver->GetRawButton(2)){
			if (shifter_varable==true){
				shifter->Set(DoubleSolenoid::Value::kReverse);
				shifter_varable = false;
			}else{
				shifter->Set(DoubleSolenoid::Value::kForward);
				shifter_varable = true;
			}
		}
		//Gear open close; "Y" button
		if (driver->GetRawButton(4)){
			if (gear_enabled == true){
				gear->Set(DoubleSolenoid::Value::kReverse);
				gear_enabled = false;
			}else{
				gear->Set(DoubleSolenoid::Value::kForward);
				gear_enabled = true;
			}
		}
//-------------------------------------------------------//
//  		       Operator Remote                       //
//-------------------------------------------------------//
		//climber up; right bumper; op
		if (op->GetRawAxis(1)){
			climber->Set(1.0);
		}
	}
private:
};
START_ROBOT_CLASS(Robot);
Sorry for being a long post

Thx.
Reply With Quote
  #2   Spotlight this post!  
Unread 08-02-2017, 20:44
charlier999's Avatar
charlier999 charlier999 is offline
Registered User
FRC #1662 (Raptor Force Engineering)
Team Role: Programmer
 
Join Date: Feb 2017
Rookie Year: 2013
Location: Lodi, CA
Posts: 19
charlier999 is an unknown quantity at this point
Re: Pneumatics code problems.

Pneumatics are run through a manifold.
If this ends up being some thing non related to programming, I will reply if it is.

Thx.
Reply With Quote
  #3   Spotlight this post!  
Unread 08-02-2017, 23:06
euhlmann's Avatar
euhlmann euhlmann is offline
CTO, Programmer
AKA: Erik Uhlmann
FRC #2877 (LigerBots)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2015
Location: United States
Posts: 410
euhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud of
Re: Pneumatics code problems.

Code:
bool wasAPressed = false;

// then in in teleopPeriodic...

if (driver->GetRawButton(2)) {
    if (!wasAPressed) {
        wasAPressed = true;
        shifter->Set(shifter->Get() == DoubleSolenoid::Value::kReverse ? DoubleSolenoid::Value::kForward : DoubleSolenoid::Value::kReverse);
    }
} else {
    wasAPressed = false;
}
__________________
Creator of SmartDashboard.js, an extensible nodejs/webkit replacement for SmartDashboard


https://ligerbots.org

Last edited by euhlmann : 08-02-2017 at 23:09.
Reply With Quote
  #4   Spotlight this post!  
Unread 09-02-2017, 17:25
charlier999's Avatar
charlier999 charlier999 is offline
Registered User
FRC #1662 (Raptor Force Engineering)
Team Role: Programmer
 
Join Date: Feb 2017
Rookie Year: 2013
Location: Lodi, CA
Posts: 19
charlier999 is an unknown quantity at this point
Re: Pneumatics code problems.

Does the word "Value" in
DoubleSolenoid::Value::kReverse ?
represents the value in the Double Solenoid is pluged into the PCM or something else?
Thx.
Reply With Quote
  #5   Spotlight this post!  
Unread 09-02-2017, 17:53
charlier999's Avatar
charlier999 charlier999 is offline
Registered User
FRC #1662 (Raptor Force Engineering)
Team Role: Programmer
 
Join Date: Feb 2017
Rookie Year: 2013
Location: Lodi, CA
Posts: 19
charlier999 is an unknown quantity at this point
Re: Pneumatics code problems.

Never mind what I said. I found out what it means
Quote:
Originally Posted by charlier999 View Post
Does the word "Value" in
DoubleSolenoid::Value::kReverse ?
represents the value in the Double Solenoid is pluged into the PCM or something else?
Thx.
Thx.
Reply With Quote
  #6   Spotlight this post!  
Unread 09-02-2017, 22:01
charlier999's Avatar
charlier999 charlier999 is offline
Registered User
FRC #1662 (Raptor Force Engineering)
Team Role: Programmer
 
Join Date: Feb 2017
Rookie Year: 2013
Location: Lodi, CA
Posts: 19
charlier999 is an unknown quantity at this point
Re: Pneumatics code problems.

Quote:
Originally Posted by euhlmann View Post
Code:
bool wasAPressed = false;

// then in in teleopPeriodic...

if (driver->GetRawButton(2)) {
    if (!wasAPressed) {
        wasAPressed = true;
        shifter->Set(shifter->Get() == DoubleSolenoid::Value::kReverse ? DoubleSolenoid::Value::kForward : DoubleSolenoid::Value::kReverse);
    }
} else {
    wasAPressed = false;
}
The one problem with this code is that when i press the button longer than 1/50th of a second(50 cycles per second the rio reads the code), it hastily switches back and forth between on and off. Is there any way of fixing the problem or do i just need to have extremely fast fingers for that button.

Thx.
Reply With Quote
  #7   Spotlight this post!  
Unread Yesterday, 01:18
euhlmann's Avatar
euhlmann euhlmann is offline
CTO, Programmer
AKA: Erik Uhlmann
FRC #2877 (LigerBots)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2015
Location: United States
Posts: 410
euhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud of
Re: Pneumatics code problems.

Quote:
Originally Posted by charlier999 View Post
The one problem with this code is that when i press the button longer than 1/50th of a second(50 cycles per second the rio reads the code), it hastily switches back and forth between on and off. Is there any way of fixing the problem or do i just need to have extremely fast fingers for that button.

Thx.
My code shouldn't do that. Notice how it sets a flag wasAPressed to make sure it doesn't continuously run shifting. Make sure wasAPressed is a member variable, not a local variable
__________________
Creator of SmartDashboard.js, an extensible nodejs/webkit replacement for SmartDashboard


https://ligerbots.org
Reply With Quote
  #8   Spotlight this post!  
Unread Yesterday, 18:23
charlier999's Avatar
charlier999 charlier999 is offline
Registered User
FRC #1662 (Raptor Force Engineering)
Team Role: Programmer
 
Join Date: Feb 2017
Rookie Year: 2013
Location: Lodi, CA
Posts: 19
charlier999 is an unknown quantity at this point
Re: Pneumatics code problems.

Quote:
Originally Posted by euhlmann View Post
My code shouldn't do that. Notice how it sets a flag wasAPressed to make sure it doesn't continuously run shifting. Make sure wasAPressed is a member variable, not a local variable
Code:
bool shifter_varable = true;

//later in teleopPeriodic

if (driver->GetRawButton(2)){
  if (!shifter_varable){
    shifter_varable = true;
    shifter->Set(shifter->Get() == 
DoubleSolenoid::Value::kReverse ?
DoubleSolenoid::Value::kForward :
DoubleSolenoid::Value::kReverse);

}else{
  shifter_varable = false;
  }
}
all tho i did the exact same thing except change the name of the wasAPressed to shifter_varable. It still does the exact same thing as before, going hyper-speed switching back and forth.
Reply With Quote
  #9   Spotlight this post!  
Unread Today, 01:10
euhlmann's Avatar
euhlmann euhlmann is offline
CTO, Programmer
AKA: Erik Uhlmann
FRC #2877 (LigerBots)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2015
Location: United States
Posts: 410
euhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud of
Re: Pneumatics code problems.

Quote:
Originally Posted by charlier999 View Post
all tho i did the exact same thing except change the name of the wasAPressed to shifter_varable. It still does the exact same thing as before, going hyper-speed switching back and forth.
Ok let me make it a bit more clear:

Code:
// File: Robot.cpp

class Robot: public IterativeRobot {
public:
    bool wasAPressed = false; // MEMBER VARIABLE. not local variable
    
    // robotInit, teleopInit, autonomousInit, autonomousPeriodic, etc

    void teleopPeriodic() {
        if (driver->GetRawButton(2)) {
            if (!wasAPressed) {
                wasAPressed = true;
                shifter->Set(shifter->Get() == DoubleSolenoid::Value::kReverse ? DoubleSolenoid::Value::kForward : DoubleSolenoid::Value::kReverse);
            }
        } else {
            wasAPressed = false;
        }
    }
}
Please read: http://www.cplusplus.com/doc/tutorial/classes/
__________________
Creator of SmartDashboard.js, an extensible nodejs/webkit replacement for SmartDashboard


https://ligerbots.org
Reply With Quote
  #10   Spotlight this post!  
Unread Today, 14:53
charlier999's Avatar
charlier999 charlier999 is offline
Registered User
FRC #1662 (Raptor Force Engineering)
Team Role: Programmer
 
Join Date: Feb 2017
Rookie Year: 2013
Location: Lodi, CA
Posts: 19
charlier999 is an unknown quantity at this point
Re: Pneumatics code problems.

Code:
#includes stuff

class Robot: public frc::IterativeRobot
{
public:

bool shifter_varable = false; //shifter_varable = wasAPressed

DoubleSolenoid *shifter;

// other random decoration of other varables non 
// robotInit, teleopInit, autonomousInit, autonomousPeriodic, etc

 void teleopPeriodic() {

if (driver->GetRawButton(2)){

  if (!shifter_varable){ // shifter_varable = wasAPressed

    shifter_varable = true;

    shifter->Set(shifter->Get() == 

DoubleSolenoid::Value::kReverse ?
DoubleSolenoid::Value::kForward :
DoubleSolenoid::Value::kReverse);

}else{

  shifter_varable = false;

  }
}
I copied your code and replaced wasAPressed to shifter_varable and.... it still did the same thing. I think the Rio hates me
Reply With Quote
  #11   Spotlight this post!  
Unread Today, 15:08
Ben Wolsieffer Ben Wolsieffer is offline
Dartmouth 2020
AKA: lopsided98
FRC #2084 (Robots by the C)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Manchester, MA (Hanover, NH)
Posts: 521
Ben Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud of
Re: Pneumatics code problems.

Quote:
Originally Posted by charlier999 View Post
I copied your code and replaced wasAPressed to shifter_varable and.... it still did the same thing. I think the Rio hates me
The roboRIO is doing exactly what you told it to do. Look closely at your brackets: your code is different from what euhlmann posted. Using correct indentation makes it a lot easier to spot problems like these.
__________________



2016 North Shore District - Semifinalists and Excellence in Engineering Award
2015 Northeastern University District - Semifinalists and Creativity Award
2014 Granite State District - Semifinalists and Innovation in Control Award
2012 Boston Regional - Finalists
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 19:18.

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