SHARE
TWEET

Team 2601 sonar unit test

a guest Apr 4th, 2014 9 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*----------------------------------------------------------------------------*/
  2. /* Copyright (c) FIRST 2008. All Rights Reserved.                             */
  3. /* Open Source Software - may be modified and shared by FRC teams. The code   */
  4. /* must be accompanied by the FIRST BSD license file in the root directory of */
  5. /* the project.                                                               */
  6. /*----------------------------------------------------------------------------*/
  7.  
  8. package edu.wpi.first.wpilibj.templates;
  9.  
  10.  
  11. import edu.wpi.first.wpilibj.SimpleRobot;
  12. import edu.wpi.first.wpilibj.Ultrasonic;
  13.  
  14. /**
  15.  * The VM is configured to automatically run this class, and to call the
  16.  * functions corresponding to each mode, as described in the SimpleRobot
  17.  * documentation. If you change the name of this class or the package after
  18.  * creating this project, you must also update the manifest file in the resource
  19.  * directory.
  20.  */
  21. public class RobotTemplate extends SimpleRobot {
  22.    
  23.     Ultrasonic sonar1 = new Ultrasonic(2, 1);
  24.     Ultrasonic sonar2 = new Ultrasonic(4, 3);
  25.    
  26.     /**
  27.      * This function is called once each time the robot enters autonomous mode.
  28.      */
  29.     public void autonomous() {
  30.        
  31.     }
  32.  
  33.     /**
  34.      * This function is called once each time the robot enters operator control.
  35.      */
  36.     public void operatorControl() {
  37.         sonar1.setEnabled(true);
  38.         sonar1.setAutomaticMode(true);
  39.         sonar2.setEnabled(true);
  40.         sonar2.setAutomaticMode(true);
  41.        
  42.         while(isOperatorControl() && isEnabled()){
  43.             System.out.println(sonar1.getRangeInches() + ", " + sonar2.getRangeInches());
  44.         }
  45.     }
  46.    
  47.     /**
  48.      * This function is called once each time the robot enters test mode.
  49.      */
  50.     public void test() {
  51.    
  52.     }
  53. }
RAW Paste Data
Top