Go to Post Such is life in the fast-paced, laugh-in-the-face-of-adversity, never-let-them-see-you-sweat, sometimes-you're-the-windshield-sometimes-you're-the-bug world of FIRST Robotics! - Sean Schuff [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 15-02-2015, 20:01
thatprogrammer's Avatar
thatprogrammer thatprogrammer is offline
Registered User
AKA: Ahad Bawany
no team (None)
Team Role: Programmer
 
Join Date: Apr 2014
Rookie Year: 2014
Location: Florida
Posts: 610
thatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond repute
Need Assistance with making autonmous work.

Hey, in our auto, we need two limit switches to be pressed. After they get pressed, the robot would need to go back. The distance code works very well, but I can't seem to get it to correspond to a limit press. Also, the autonomous height was reported as 0 before, but I MIGHT have fixed that. (I had noticed a missing variable, never tested the elevator after that)
Code:
#include "WPILib.h"

class Robot: public IterativeRobot
{
private:
	//Initializing livewindow
	LiveWindow *lw;
	//Initializing stick
	Joystick *stick, *Joy, *OtherJoy;
	//Initializing the Chassis parts
	Talon *kFrontLeftMotor;
	Talon *kFrontRightMotor;
	Talon *Elevator;
	RobotDrive *robot;
	Relay *Fan;
	DoubleSolenoid *shifter;
	Encoder *ChassisEnc;
	Encoder *OtherEnc;
	AnalogInput *ElevatorEnc;
	DigitalInput *LightLimit, *OtherLightLimit;
	Solenoid *Light, *OtherLight;
	//Initializing the values for Cheesy Drive
	float Rotation;
	float Acceleration;
	float rightMultiplier;
	float leftMultiplier;
    double automode;
    Gyro *gyro;
    bool robottime;
    double Angle;
    DoubleSolenoid *ElevSol;
    bool robotdrive;
   double Kp = 0.08;
   DigitalInput *Limit, *TopLimit, *OtherLimit;
   PIDController *ElevatorPID;
   double ElevatorKp;
   double ElevatorKd;
   double ElevatorHeight;
   double HeightError;
   double HeightSum;
   double Goal;
   double Out;
   double threshold;
   double numRotations;
   double lastAngle;
   double absAngle;
   double ActualRotation;
   bool Stop;
   bool TopStop;
  double DistancePerNum;
   double LastElevatorHeight;
   double Power;
   bool ShiftOpened;
   bool Goto;
   double SuperRotation;
   double Ultra;
   bool Lighton;
   bool OtherLighton;
   bool ElevSaftey;
	void RobotInit()
	{

		SmartDashboard::init();
		lw = LiveWindow::GetInstance();
		stick = new Joystick(0);
		Joy = new Joystick (2);
		OtherJoy = new Joystick(1);
		kFrontLeftMotor = new Talon(0);
		kFrontRightMotor = new Talon(1);
		Elevator = new Talon (2);
		robot = new RobotDrive(kFrontRightMotor, kFrontLeftMotor);
		Fan = new Relay (3);


		/* Setting the shifter as a DoubleSolenoid
		 * Because we're using both pistons off of
		 * one Double Solenoid
		 */
		shifter = new DoubleSolenoid (0,1);

		ChassisEnc = new Encoder (0,1, false, Encoder::EncodingType::k4X);
		OtherEnc= new Encoder (8,9, false, Encoder::EncodingType::k4X);
        ElevatorEnc = new AnalogInput (3);
		//Setting it so the fan is off by default
		Fan->Set(Relay::kOff);


		//Setting the Rotation and Accel values
		Rotation = stick->GetRawAxis(1);
		Acceleration = stick->GetRawAxis(3);

	    /*Setting the multipliers
	     * so that they don't allow
	     * a robot to go full forward
	     * while going full turn
	     */

		rightMultiplier = Rotation + Acceleration;
		leftMultiplier = Rotation - Acceleration;

		//Setting the shifter to Low Gear
		shifter->Set(DoubleSolenoid::kReverse);
		robot->SetInvertedMotor(RobotDrive::kFrontLeftMotor, true);
		robot->SetInvertedMotor(RobotDrive::kFrontRightMotor, true);

		ChassisEnc->SetDistancePerPulse(.084);
		OtherEnc->SetDistancePerPulse(.084);
	gyro = new Gyro (1);
	Angle = gyro->GetAngle();

	if (stick->GetRawButton(1))

		{
			automode = 1;
		}
		if (stick->GetRawButton(2))
		{
			automode = 2;
		} else {
			automode = 0;
		}
	SmartDashboard::PutNumber("Auto:", automode);
gyro->InitGyro();
ElevSol = new DoubleSolenoid (2,3);
gyro->InitGyro();
Limit = new DigitalInput(7);
TopLimit = new DigitalInput(3);
OtherLimit = new DigitalInput(2);
DistancePerNum = .05;
Goto = false;
Goal = 0;
Light = new Solenoid (4);
OtherLight = new Solenoid(5);
LightLimit = new DigitalInput(4);
OtherLightLimit = new DigitalInput (5);

//Out = ElevatorKp *HeightError + ElevatorKd *HeightSum;
//Out = (.5);
//ElevatorPID = new PIDController(0.5, 0.0, 0.0, ElevatorEnc, Elevator);
//ElevatorPID->Enable();


	}



	void AutonomousInit()
	{

		gyro->Reset();
kFrontRightMotor->SetSafetyEnabled(false);
kFrontLeftMotor->SetSafetyEnabled(false);
ChassisEnc->Reset();
threshold = 340;
absAngle = ElevatorEnc->GetVoltage() * 72;
if ( absAngle- lastAngle < -threshold) {
          numRotations++;
        	   } else if (absAngle - lastAngle > threshold){
        		   numRotations--;
        	   }
if (numRotations<0)
{
	numRotations = 0;
}
ActualRotation = ((340 * numRotations) + absAngle)- 300;
		        LastElevatorHeight = ElevatorHeight;
		        HeightError = Goal - ElevatorHeight;
		        HeightSum = ElevatorHeight - LastElevatorHeight;
		        ElevatorKp = .75;
		        ElevatorKd = .0;
		        SuperRotation = (360 * numRotations) - absAngle;
		        Power = ElevatorKp*HeightError + ElevatorKd*HeightSum;
		        ElevatorHeight= (ActualRotation/37.24)  ;
		        		if (ElevatorHeight < 0){
		        			ElevatorHeight =0;
		        		}
		        		ElevSol->Set(DoubleSolenoid::kForward);

	}

	void AutonomousPeriodic()
	{
		bool OtherDrive;
		if ( absAngle- lastAngle < -threshold) {
		          numRotations++;
		        	   } else if (absAngle - lastAngle > threshold){
		        		   numRotations--;
		        	   }
		absAngle = ElevatorEnc->GetVoltage() * 72;
		ElevatorHeight= (ActualRotation/37.24) ;
				if (ElevatorHeight < 0){
					ElevatorHeight =0;
				}
				Ultra = ((ActualRotation + absAngle - 600) + 4);
				ActualRotation = ((threshold * numRotations) + absAngle)- 300;
				        LastElevatorHeight = ElevatorHeight;
				        HeightError = Goal - ElevatorHeight;
				        HeightSum = ElevatorHeight - LastElevatorHeight;
				        ElevatorKp = .75;
				        ElevatorKd = .0;
				        SuperRotation = (360 * numRotations) - absAngle;
				        Power = ElevatorKp*HeightError + ElevatorKd*HeightSum;


		SmartDashboard::PutNumber("Angle", gyro->GetAngle());
		SmartDashboard::PutNumber("AutoHeight", ElevatorHeight);
		double Distace = ChassisEnc->GetDistance();
		float Angle = gyro->GetAngle();
        bool turner;
        bool Grab;
        bool Auton1;
        int Driveto;
		bool ElevSaftey;
		int DriveBack =0;
        Auton1 = true;
        if (OtherLimit->Get()||TopLimit->Get())
        {
        	ElevSaftey = true;
        } else {
        	ElevSaftey = false;
        }
        //bool Auton2;
        //bool Auton3;
        if (Goto==true)
                	{
                		Elevator->Set(Power);

                		if (Power > .68){
                			Power = .68;
                		}
                		if (Power < -.68)
                		{
                			Power = -.68;
                		}
                	}
        if (Auton1 == true){

        	 if (OtherLimit->Get() || TopLimit->Get())
        	        {
        	        	ElevSaftey = true;
        	        } else {
        	        	ElevSaftey = false;
        	        }
        	 if (ElevSaftey == true)




        	 {
        		 Elevator->Set(0);
        		 Goto = false;
        	 }
  Grab = true;
  if (Grab == true){


	  ElevSol->Set(DoubleSolenoid::kForward);
 Driveto = 0;

  }
  if (LightLimit->Get() || OtherLightLimit->Get()){
//	  Wait(2);
	  DriveBack= Driveto + 1;
	  Goto = true; }
	  if (Goto == true){
		  Grab = false;
       if (Grab == false)
       {
    	   if (DriveBack>0){
    		   DriveBack = 1;
    	   }
       }
	  }


  if (Grab == false && Goto == true)
  {


	 /* if (Goto==true){
		  Goal =5; }
	          else if (Goto== true && ElevSaftey == true)
	          {
	        	  Elevator->Set(0);
	          }*/


 	 if (OtherLimit->Get() || TopLimit->Get())
 	        {
 	        	ElevSaftey = true;
 	        } else {
 	        	ElevSaftey = false;
 	        }
 	 if (ElevSaftey == true)
 	 {
 		 Elevator->Set(0);

 		        		 Goto = false;
 		        	 }




	  if (ElevatorHeight>= Goal){
	    	Driveto = true;
	Goto= false;
	    }
	  if (ElevSaftey== true && Driveto == true)
	  {
		  Elevator->Set(0);
		  Goto = false;
	  } else if (ElevSaftey == true && Driveto == false)
	  {
		  Goto = true;
     	 if (OtherLimit->Get() || TopLimit->Get())
     	        {
     	        	ElevSaftey = true;
     	        } else {
     	        	ElevSaftey = false;
     	        }
     	 if (ElevSaftey == true)
     	 {
     		 Elevator->Set(0);


     	 		        		 Goto = false;

     	 }
	  }


  }

  if (DriveBack > 0)
		  {
	  if (Distace > -108 ){
	  	  		  robot->Drive(.5, -Angle*Kp);

	  	  		  Goto = false;
	  }

	  if (Distace <=108 && DriveBack >0 )
	  {
		  robot->Drive(0, 0);
		  DriveBack = 0;
		  OtherDrive = true;
		 /* if (ElevSaftey == true)
		  {
			  Elevator->Set(0);
			  OtherDrive = true;
		  } else {
			  Elevator->Set(-.5);
		  } */
  if (OtherDrive == true){
	  if (Distace < 112)
	  {
		  robot->Drive(.5, 0);
	  } else if (Distace > 112)
	  {
		  robot->Drive(0, 0);
	  }
  }

  }
	  SmartDashboard::PutNumber("AutoHeight", ElevatorHeight);

		  }}}
  #2   Spotlight this post!  
Unread 15-02-2015, 20:58
Christopher149 Christopher149 is offline
Registered User
FRC #0857 (Superior Roboworks) FTC 10723 (SnowBots)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2007
Location: Houghton, MI
Posts: 1,104
Christopher149 has a reputation beyond reputeChristopher149 has a reputation beyond reputeChristopher149 has a reputation beyond reputeChristopher149 has a reputation beyond reputeChristopher149 has a reputation beyond reputeChristopher149 has a reputation beyond reputeChristopher149 has a reputation beyond reputeChristopher149 has a reputation beyond reputeChristopher149 has a reputation beyond reputeChristopher149 has a reputation beyond reputeChristopher149 has a reputation beyond repute
Re: Need Assistance with making autonmous work.

Just to be sure, do you know if the switches work? They should have a connection between signal and ground on a DIO port.
__________________
2015-present: FTC 10723 mentor
2012-present: 857 mentor
2008-2011: 857 student

2015: Industrial Design, Excellence in Engineering, District Finalist, Archimedes Division (#6 alliance captain)
2014: Judges Award, District Engineering Inspiration, District Finalist, Galileo Division

  #3   Spotlight this post!  
Unread 15-02-2015, 21:45
thatprogrammer's Avatar
thatprogrammer thatprogrammer is offline
Registered User
AKA: Ahad Bawany
no team (None)
Team Role: Programmer
 
Join Date: Apr 2014
Rookie Year: 2014
Location: Florida
Posts: 610
thatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond reputethatprogrammer has a reputation beyond repute
Re: Need Assistance with making autonmous work.

Quote:
Originally Posted by Christopher149 View Post
Just to be sure, do you know if the switches work? They should have a connection between signal and ground on a DIO port.
They work 100% in teleop. Also, is there a way to make the robot wait until the piston is done opening before it starts with the rest of auto?
  #4   Spotlight this post!  
Unread 16-02-2015, 00:46
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,679
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Need Assistance with making autonmous work.

Quote:
Originally Posted by thatprogrammer View Post
.. is there a way to make the robot wait until the piston is done opening before it starts with the rest of auto?
You'll need some sort of sensor to detect when that happens. If your pistons have ferromagnetic plates, you can place magnetic switches on the outside of the pistons to detect when the piston is "done". These switches are usually provided by Bimba with the FIRST choice cylinders, or can be purchased easily enough. If your pistions are non-magnetic, a limit switch is your best bet. These can be triggered mechanically or through magnetism, or even optically. Figuring out what style of limit switch you need is very dependent on your application. If you can't think of how to place a limit switch on your device, I suggest going to google images and searching for "limit switch". Look at the pictures until something looks like it could work, or 100 pictures, whichever comes first.

FWIW, the 3946 robot has three distinctive styles of limit switch this year; two optical, six push-button, and four lever arm with roller.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.

Last edited by GeeTwo : 16-02-2015 at 00:49.
  #5   Spotlight this post!  
Unread 16-02-2015, 00:49
rich2202 rich2202 is offline
Registered User
FRC #2202 (BEAST Robotics)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Wisconsin
Posts: 1,242
rich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond repute
Re: Need Assistance with making autonmous work.

Two options:

1) Put a magnetic sensor on the piston. Then you can tell when it has moved to the desired location.

2) Put a time delay, and wait 1 second, or however long it takes the piston to move.
Closed Thread


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 21:08.

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