Changes between Version 5 and Version 6 of ControlSystems/SoftwareTeam/Training/GettingStarted/IntroRobotJava


Ignore:
Timestamp:
Oct 7, 2019, 11:08:35 PM (6 years ago)
Author:
David Albert
Comment:

--

Legend:

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

    v5 v6  
    553. WPI also provides a rich library of pre-written classes called WPIlib that makes robot programming faster and easier.
    66
     7== First Program: Xbox Controller
    78We write robot software in VSCode just as we did for Java, but we'll make use of the WPILib extensions to create, build, and run our robot programs.  The WPILib extension is available via the W icon in the toolbar.  Click on the icon and then:
    89* Select Create a new project
     
    5152* The program will run until it gets to that line and then stop.  Press the continue button to continue running.
    5253* Even though the program is running on the robot, you can set breakpoints, step through code, examine and change variables, etc. from your laptop.
     54
     55== Second program: Ultrasonic Rangefinder
     56
     57Create another program using the TimedRobot java template and name it UltrasonicTest. Modify the generated code as follows:
     58* import the Ultrasonic class {{{ import edu.wpi.first.wpilibj.Ultrasonic; }}}
     59* declare a ultrasonic variable in the Robot class {{{ private Ultrasonic f_ultrasonic; }}}
     60* in robotInit() instantiate an ultrasonic object and set it to start automatically ranging
     61  {{{
     62    f_ultrasonic = new Ultrasonic(1,0);
     63    f_ultrasonic.setAutomaticMode(true);
     64  }}}
     65* in robotPeriodic() read and display the range
     66  {{{
     67    if (f_ultrasonic.isRangeValid()) {
     68       SmartDashboard.putNumber("Front range", f_ultrasonic.getRangeInches());
     69    }
     70  }}}
     71
     72Run the program and observe the "Front range" value in the Smart Dashboard as you move the robot towards and away from the wall.
    5373 
    5474== Study some examples