Changes between Initial Version and Version 1 of ControlSystems/SoftwareTeam/Training/IntroRobotJava/XboxExample


Ignore:
Timestamp:
Oct 7, 2019, 9:39:55 PM (6 years ago)
Author:
David Albert
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ControlSystems/SoftwareTeam/Training/IntroRobotJava/XboxExample

    v1 v1  
     1{{{
     2/*----------------------------------------------------------------------------*/
     3/* Copyright (c) 2017-2018 FIRST. All Rights Reserved.                        */
     4/* Open Source Software - may be modified and shared by FRC teams. The code   */
     5/* must be accompanied by the FIRST BSD license file in the root directory of */
     6/* the project.                                                               */
     7/*----------------------------------------------------------------------------*/
     8
     9package frc.robot;
     10
     11import edu.wpi.first.wpilibj.IterativeRobot;
     12import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
     13import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
     14import edu.wpi.first.wpilibj.XboxController;
     15import edu.wpi.first.wpilibj.GenericHID.Hand;
     16
     17/**
     18 * The VM is configured to automatically run this class, and to call the
     19 * functions corresponding to each mode, as described in the IterativeRobot
     20 * documentation. If you change the name of this class or the package after
     21 * creating this project, you must also update the build.gradle file in the
     22 * project.
     23 */
     24public class Robot extends IterativeRobot {
     25  private static final String kDefaultAuto = "Default";
     26  private static final String kCustomAuto = "My Auto";
     27  private String m_autoSelected;
     28  private final SendableChooser<String> m_chooser = new SendableChooser<>();
     29  private XboxController xbox;
     30
     31  /**
     32   * This function is run when the robot is first started up and should be
     33   * used for any initialization code.
     34   */
     35  @Override
     36  public void robotInit() {
     37    m_chooser.setDefaultOption("Default Auto", kDefaultAuto);
     38    m_chooser.addOption("My Auto", kCustomAuto);
     39    SmartDashboard.putData("Auto choices", m_chooser);
     40    xbox = new XboxController(0);
     41  }
     42
     43  /**
     44   * This function is called every robot packet, no matter the mode. Use
     45   * this for items like diagnostics that you want ran during disabled,
     46   * autonomous, teleoperated and test.
     47   *
     48   * <p>This runs after the mode specific periodic functions, but before
     49   * LiveWindow and SmartDashboard integrated updating.
     50   */
     51  @Override
     52  public void robotPeriodic() {
     53    SmartDashboard.putNumber("Left Joystick X", xbox.getX(Hand.kLeft));
     54  }
     55
     56  /**
     57   * This autonomous (along with the chooser code above) shows how to select
     58   * between different autonomous modes using the dashboard. The sendable
     59   * chooser code works with the Java SmartDashboard. If you prefer the
     60   * LabVIEW Dashboard, remove all of the chooser code and uncomment the
     61   * getString line to get the auto name from the text box below the Gyro
     62   *
     63   * <p>You can add additional auto modes by adding additional comparisons to
     64   * the switch structure below with additional strings. If using the
     65   * SendableChooser make sure to add them to the chooser code above as well.
     66   */
     67  @Override
     68  public void autonomousInit() {
     69    m_autoSelected = m_chooser.getSelected();
     70    // autoSelected = SmartDashboard.getString("Auto Selector",
     71    // defaultAuto);
     72    System.out.println("Auto selected: " + m_autoSelected);
     73  }
     74
     75  /**
     76   * This function is called periodically during autonomous.
     77   */
     78  @Override
     79  public void autonomousPeriodic() {
     80    switch (m_autoSelected) {
     81      case kCustomAuto:
     82        // Put custom auto code here
     83        break;
     84      case kDefaultAuto:
     85      default:
     86        // Put default auto code here
     87        break;
     88    }
     89  }
     90
     91  /**
     92   * This function is called periodically during operator control.
     93   */
     94  @Override
     95  public void teleopPeriodic() {
     96  }
     97
     98  /**
     99   * This function is called periodically during test mode.
     100   */
     101  @Override
     102  public void testPeriodic() {
     103  }
     104}
     105}}}