= Welcome to Software! = == Gear Needed To start developing robot software for team 2537 you will need the following * A laptop running Windows 7 or Windows 10 * USB [https://www.amazon.com/dp/B0769GFWCZ A-B cable] * USB [https://www.amazon.com/PXN-PRO-2113-Professional-Controller/dp/B01JY0RAW2 Joystick] or USB [https://www.amazon.com/Logitech-940-000110-Gamepad-F310/dp/B003VAHYQY XBox controller] * Optional: USB [https://www.amazon.com/Genius-120-degree-Conference-Webcam-WideCam/dp/B0080CE5M4 webcam] * One of: * A robot * A RoboRIO (the computer that controls the robot) and a 12v power supply == Setup your laptop: 1. Install Java * [https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html JDK 8] * Add an environment variable JAVA_HOME that points to the directory where you installed Java and add the bin sub-folder to your search path; see detailed instructions [https://javatutorial.net/set-java-home-windows-10 here]. 2. Install Git (if not already on your computer) from [https://git-scm.com/downloads here] 3. Install Microsoft [https://code.visualstudio.com/download VSCode], required extensions, and the [https://github.com/wpilibsuite/vscode-wpilib/releases latest WPILib] extension. Follow the detailed instructions [https://wpilib.screenstepslive.com/s/currentCS/m/79833/l/932382-installing-vs-code here] 4. Install the National Instruments (NI) FRC 2017 Vision Development Module [http://www.ni.com/download/vision-development-module-2017/6640/en/ here]. Choose the current user version, login to your NI account (or create one), and then choose to download the 2017 Vision Development Module (FRC). Unzip and install the module; you will later need to activate it using the instructions provided on the !DriverStation setup page 5. Install the National Instruments (NI) FRC 2018 Update Suite [http://www.ni.com/download/first-robotics-software-2015/5112/en/ here]. Detailed instructions are [https://wpilib.screenstepslive.com/s/4485/m/getting_started/l/599670-installing-the-frc-update-suite-all-languages here]. You won't be able to activate the 2018 vision module until we receive the 2018 Kit of Parts in January (so use the 2017 module until then. 6. Install the [http://www.ctr-electronics.com/control-system/hro.html#product_tabs_technical_resources CTRE Phoenix Framework] 7. Make sure Microsoft Internet Explorer (yep) is installed on your computer and install the [https://www.microsoft.com/silverlight/ SilverLight] extension == Update your roboRIO The roboRIO is a full, headless (no screen or keyboard) linux computer and runs lots of software in addition to the code you write to drive your robot. For example, there is a very useful web server that provides access to the roboRIO and connected devices and lets you test them. To extend this web server to include support for the CTRE/CAN-connected devices, launch the CTRE Hero Lifeboat Imager, choose the FRC roboRio tab, and press the Install Phoenix/Web-based Config button. == Start with an example The best way to learn about robot programming a robot is to start with a simple example program, run it, study what it does, and incrementally expand its functionality. The WPILib software you installed includes example programs that you can compile and run on a RoboRIO. Review [https://wpilib.screenstepslive.com/s/currentCS/m/79833/l/941601-vs-code-basics-and-wpilib-in-vs-code how to use VSCode] and then try [https://wpilib.screenstepslive.com/s/currentCS/m/79833/l/932465-creating-a-new-wpilib-project-in-vs-code creating a new robot project]. * WPILib provides [https://wpilib.screenstepslive.com/s/currentCS/m/java/l/599697-choosing-a-base-class 3 frameworks] for building robot programs. Build your first program using the iterative robot framework as described [https://wpilib.screenstepslive.com/s/currentCS/m/java/l/145307-creating-your-benchtop-test-program here]. * Connect your laptop to the RoboRIO USB port * Connect your joystick or xbox controller to another USB port on your laptop * Launch the NI Driver Station Software. For details see [https://wpilib.screenstepslive.com/s/4485/m/24192/l/144976-frc-driver-station-powered-by-ni-labview here] * Confirm that the software detects your joystick/controller and responds to button presses and stick movement * Use Microsoft Internet Explorer (not Chrome or Firefox) to connect to the RoboRIO's web interface (usually at http://172.22.11.2) and confirm that you have connectivity with the RobORIO * Create a test project and follow [https://wpilib.screenstepslive.com/s/currentCS/m/79833/l/932465-creating-a-new-wpilib-project-in-vs-code these instructions] to build, load, and run it on your RoboRIO/Robot **Congratulations**, you've just built and run your first robot program. * Create another WPILib project based on the IterativeRobot framework * Study an example program. This is a simple program for one of our test robots: Peanut 2. * 2-wheel-drive (2WD) robot with two CIM motors driving plaction wheels * Motors are controlled by Talon SRX smart motor controllers; these are networked to the roboRIO (robot control computer) using CAN bus and are at addresses 3 (left motor) and 4 (right motor) * An ultrasonic sensor for forward collision avoidance connected to roboRIO digital I/O pins (DIO) 0 and 1 * A USB camera so you can drive even when you can't see the robot * The driver controls the robot using the two analog sticks on an X-box game controller {{{ package frc.robot; // Import the classes of objects you will use import edu.wpi.first.wpilibj.IterativeRobot; import edu.wpi.first.wpilibj.XboxController; import edu.wpi.first.wpilibj.GenericHID.Hand; import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.drive.DifferentialDrive; import com.ctre.phoenix.motorcontrol.can.*; import edu.wpi.first.wpilibj.Ultrasonic; import edu.wpi.first.wpilibj.CameraServer; import edu.wpi.first.wpilibj.livewindow.LiveWindow; import edu.wpi.first.wpilibj.smartdashboard.SendableChooser; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; /** * The VM is configured to automatically run this class, and to call the * functions corresponding to each mode, as described in the IterativeRobot * documentation. If you change the name of this class or the package after * creating this project, you must also update the build.gradle file in the * project. */ public class Robot extends IterativeRobot { // Create instances of each object private static final String kDefaultAuto = "Default"; private static final String kCustomAuto = "My Auto"; private String m_autoSelected; private final SendableChooser m_chooser = new SendableChooser<>(); private XboxController xbox; private Timer timer; private WPI_TalonSRX m_rearLeft; private WPI_TalonSRX m_rearRight; private DifferentialDrive m_drive; private boolean f_safetyStop; private Ultrasonic f_ultrasonic; /** * This function is run when the robot is first started up and should be * used for any initialization code. */ @Override public void robotInit() { // initialize the objects and connect them to their underlying hardware m_chooser.addDefault("Default Auto", kDefaultAuto); m_chooser.addObject("My Auto", kCustomAuto); SmartDashboard.putData("Auto choices", m_chooser); xbox = new XboxController(0); timer = new Timer(); m_rearLeft = new WPI_TalonSRX(4); m_rearRight = new WPI_TalonSRX(3); m_drive = new DifferentialDrive(m_rearLeft, m_rearRight); f_ultrasonic = new Ultrasonic(1,0); // ping, echo f_ultrasonic.setAutomaticMode(true); f_ultrasonic.setEnabled(true); CameraServer.getInstance().startAutomaticCapture(); } /** * This function is called every robot packet, no matter the mode. Use * this for items like diagnostics that you want ran during disabled, * autonomous, teleoperated and test. * *

This runs after the mode specific periodic functions, but before * LiveWindow and SmartDashboard integrated updating. */ @Override public void robotPeriodic() { } /** * This autonomous (along with the chooser code above) shows how to select * between different autonomous modes using the dashboard. The sendable * chooser code works with the Java SmartDashboard. If you prefer the * LabVIEW Dashboard, remove all of the chooser code and uncomment the * getString line to get the auto name from the text box below the Gyro * *

You can add additional auto modes by adding additional comparisons to * the switch structure below with additional strings. If using the * SendableChooser make sure to add them to the chooser code above as well. */ @Override public void autonomousInit() { m_autoSelected = m_chooser.getSelected(); // autoSelected = SmartDashboard.getString("Auto Selector", // defaultAuto); System.out.println("Auto selected: " + m_autoSelected); timer.reset(); timer.start(); } /*public void teleopInit() { }*/ /** * This function is called periodically during autonomous. */ @Override public void autonomousPeriodic() { if (timer.get() < 2.0) { m_drive.curvatureDrive(0.1, 0.0, false); } else { m_drive.curvatureDrive(0.0, 0.0,false); } switch (m_autoSelected) { case kCustomAuto: // Put custom auto code here break; case kDefaultAuto: default: // Put default auto code here break; } } /** * This function is called periodically during operator control. */ @Override public void teleopPeriodic() { // Use front-mounted ultrasonic sensor to stop robot // if it gets too close to an obstacle double f_range = f_ultrasonic.getRangeInches(); if (f_ultrasonic.isRangeValid()) { if ((f_range < 15.0) && !f_safetyStop) { System.out.println("Safety stopped due to front obstacle"); f_safetyStop = true; } else if (f_range >= 15.0 && f_safetyStop) { System.out.println("Resuming..."); f_safetyStop = false; } } // Use controller joysticks to set drive speed, but // safety stop if too close to an obstacle double leftSpeed = -0.5*xbox.getY(Hand.kLeft); double rightSpeed = -0.5*xbox.getY(Hand.kRight); // If there's an obstacle in front of us, don't // allow any more forward motion if (f_safetyStop && (leftSpeed > 0.0) && (rightSpeed > 0.0)) { m_drive.stopMotor(); } else { // otherwise, set motors according to joysticks m_drive.tankDrive(leftSpeed, rightSpeed); } Timer.delay(0.01); } /** * This function is called periodically during test mode. */ @Override public void testPeriodic() { // LiveWindow.run(); } } }}} * You can learn more about FRC robot programming [https://frc-pdr.readthedocs.io/en/latest/index.html here] * You can learn more about game controllers [https://github.com/MTHSRoboticsClub/Documentation/wiki/Drive-Controller-Comparison here]