Go to Post A true form of GP would be to send out a congratulations to all the teams that made it, regardless of whether or not you think they should have. - Molten [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 02-15-2016, 06:43 PM
Lesafian Lesafian is offline
Registered User
AKA: Jeremy Styma
FRC #6077 (Wiking Kujon)
Team Role: Programmer
 
Join Date: Feb 2016
Rookie Year: 2016
Location: Posen, Michigan
Posts: 19
Lesafian is an unknown quantity at this point
Issues with LimitSwitch

Hey guys!

I'm having troubles with programming limit switches. We're using a limit switch to stop our arms from going too low. The problem I'm having, is that the limit switch stops the motor, but then the entire robot stops working. Obviously that's a problem with the code. I'm not sure what to do though. I'll paste all of our robot code.

Code:
package org.usfirst.frc.team6077.robot;

import edu.wpi.first.wpilibj.CameraServer;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.Counter;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.SampleRobot;
import edu.wpi.first.wpilibj.Solenoid;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.VictorSP;
import edu.wpi.first.wpilibj.command.Scheduler;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;

public class Robot extends SampleRobot {

	// RobotDrive Declaration
	RobotDrive drive;

	Compressor compressor;
	DoubleSolenoid doublesolenoid;
	Solenoid solenoid;
	
	DigitalInput limitSwitch;
	Counter counter;
	
	CameraServer server;

	Joystick xboxController;

	VictorSP armMotor, slideMotor, drivemotor1, 
	drivemotor2, drivemotor3, drivemotor4;
	
	final String defaultAuto = "Default";
	final String customAuto = "Autonomous Choice 1";
	final String customAuto2 = "Autonomous Choice 2";
	final String customAuto3 = "Autonomous Choice 3";
	final String customAuto4 = "Autonomous Choice 4";
	final String customAuto5 = "Autonomous Choice 5";

	SendableChooser chooser;

	public void robotInit() {

		drivemotor1 = new VictorSP(0);
		drivemotor2 = new VictorSP(1);
		drivemotor3 = new VictorSP(2);
		drivemotor4 = new VictorSP(3);
		armMotor = new VictorSP(5);
		slideMotor = new VictorSP(6);

		compressor = new Compressor(0);
		compressor.setClosedLoopControl(true);
		
		drive = new RobotDrive(drivemotor1, drivemotor2, drivemotor3, drivemotor4);
		drive.setExpiration(0.1);

		xboxController = new Joystick(0);

		doublesolenoid = new DoubleSolenoid(0, 1);
		//solenoid = new Solenoid(2);

		server = CameraServer.getInstance();
		server.setQuality(100);
		server.startAutomaticCapture("cam1");
		
		chooser = new SendableChooser();

		chooser.addDefault("Default Auto", defaultAuto);
		chooser.addObject("Autonomous Choice 1", customAuto);
		chooser.addObject("Autonomous Choice 2", customAuto2);
		chooser.addObject("Autonomous Choice 3", customAuto3);
		chooser.addObject("Autonomous Choice 4", customAuto4);
		chooser.addObject("Autonomous Choice 5", customAuto5);
		SmartDashboard.putData("Autonomous Chooser", chooser);
	}

	public void autonomous() {
		drive.setSafetyEnabled(false);
		String autoSelected = (String) chooser.getSelected();
		System.out.println("Autonomous Mode selected: " + autoSelected);

		switch (autoSelected) {

		case customAuto5:
			break;
		case customAuto4:
			break;
		case customAuto3:
			break;
		case customAuto2:
			break;
		case customAuto:
			break;
		case defaultAuto:
		default:
			break;
		}
		Scheduler.getInstance().run();
	}

	public void operatorControl() {
		drive.setSafetyEnabled(true);
		while (isOperatorControl() && isEnabled()) {
			while (counter.get() > 0) {
                             armMotor.stopMotor();
		}
			
		//drive.tankDrive(xboxController.getRawAxis(2), xboxController.getRawAxis(5));
		drive.arcadeDrive(xboxController.getRawAxis(1), -xboxController.getRawAxis(0));

		// Lift and lower the arms using the left and right trigger.

		if (Math.abs(xboxController.getRawAxis(3)) > .1) {
			armMotor.set(xboxController.getRawAxis(3));
		} else if (Math.abs(xboxController.getRawAxis(2)) > .1) {
			armMotor.set(-xboxController.getRawAxis(2));
		} else {
			armMotor.stopMotor();
		}
		
		// Move sliding mechanism forwards and backwards

		if (Math.abs(xboxController.getRawAxis(5)) > .1) {
			slideMotor.set(xboxController.getRawAxis(5));
		} else {
			slideMotor.stopMotor();
		}
		
		// Open and close the claw

		if (xboxController.getRawButton(2)) {
			doublesolenoid.set(DoubleSolenoid.Value.kForward);
		} else if (xboxController.getRawButton(1)) {
			doublesolenoid.set(DoubleSolenoid.Value.kReverse);
		}
		
		Timer.delay(0.005); //Wait for a motor update time
		}
	}
	public void test() {

	}
}
I feel like it's a problem with the while loop.
Code:
			while (counter.get() > 0) {
                            armMotor.stopMotor();
		}
Reply With Quote
 


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 08:05 AM.

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