Changes between Version 5 and Version 6 of ControlSystems/SoftwareTeam/Training/GettingStarted/IntroRobotJava
- Timestamp:
- Oct 7, 2019, 11:08:35 PM (6 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ControlSystems/SoftwareTeam/Training/GettingStarted/IntroRobotJava
v5 v6 5 5 3. WPI also provides a rich library of pre-written classes called WPIlib that makes robot programming faster and easier. 6 6 7 == First Program: Xbox Controller 7 8 We 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: 8 9 * Select Create a new project … … 51 52 * The program will run until it gets to that line and then stop. Press the continue button to continue running. 52 53 * 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 57 Create 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 72 Run the program and observe the "Front range" value in the Smart Dashboard as you move the robot towards and away from the wall. 53 73 54 74 == Study some examples