View Single Post
  #3   Spotlight this post!  
Unread 09-02-2016, 22:04
NegaNexus NegaNexus is offline
Registered User
AKA: Thys Ballard
FRC #2130 (Alpha+)
Team Role: Programmer
 
Join Date: Oct 2012
Rookie Year: 2012
Location: Coeur d'Alene, Idaho
Posts: 16
NegaNexus is an unknown quantity at this point
Re: Toggle or Digital Switches

When looking through some stuff, I found a Reddit post with a way that seems effective. When I tried it on the code below I get an odd error. When we select a mode, it works fine. When we disable, select another mode, and re-enable the program, it runs both cases at the same time. Any ideas anyone?

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


import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.command.Scheduler;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj.CANTalon;
import edu.wpi.first.wpilibj.IterativeRobot;

public class Robot extends IterativeRobot {
	
    RobotDrive myRobot;
    CANTalon talon;
    CANTalon talon1;
    final String defaultAuto = "Default";
    final String customAuto = "My Auto";
    SendableChooser chooser;
    int mode = 1;

    public Robot() {
        myRobot = new RobotDrive(0, 1);
        myRobot.setExpiration(0.1);
        talon = new CANTalon(2);
        talon1 = new CANTalon(4);
    }
    
    public void robotInit() {
        chooser = new SendableChooser();
        chooser.addDefault("Run 2", 1);
        chooser.addObject("Run 4", 2);
        SmartDashboard.putData("Auto modes", chooser);
    }

    public void autonomousInit() {
    	mode = (int) chooser.getSelected();

    }
    
    public void autonomousPeriodic(){
    	switch(mode) {
	case 1:
		talon.set(0.25);
		break;
	case 2:
		talon1.set(1);
		break;
	}
    }
    
    public void operatorControl() {
        myRobot.setSafetyEnabled(true);
        while (isOperatorControl() && isEnabled()) {
            talon.set(0.25);
        }
    }
    
    public void test() {
    }
}
Reply With Quote