Guest User

Test Robo Code

a guest
Jan 27th, 2016
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.98 KB | None | 0 0
  1. package org.usfirst.frc.team224.robot;
  2.  
  3. import java.util.Arrays;
  4.  
  5. //SingleDriver
  6.  
  7. import edu.wpi.first.wpilibj.*;
  8. import edu.wpi.first.wpilibj.RobotDrive.MotorType;
  9. import edu.wpi.first.wpilibj.image.NIVisionException;
  10. import edu.wpi.first.wpilibj.networktables.NetworkTable;
  11. import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
  12. import edu.wpi.first.wpilibj.vision.AxisCamera;
  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 IterativeRobot
  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 Robot extends IterativeRobot {
  22.     RobotDrive drive;
  23.  
  24.     Servo servo;
  25.     Joystick joystick;
  26.     NetworkTable table;
  27.     AxisCamera ac;
  28.     boolean currentButtonState=false;
  29.     String test="";
  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.     //
  36.     public Robot(){
  37. //      table = NetworkTable.getTable("GRIP/myCountoursReport");
  38.     }
  39.     public void robotInit() {
  40.         NetworkTable.initialize();
  41.         System.out.println("HI");
  42.         ac = new AxisCamera("cam1");
  43.         drive = new RobotDrive(1, 2);
  44.         servo = new Servo(3);
  45.         joystick = new Joystick(1);
  46.         table = NetworkTable.getTable("GRIP/myCountoursReport");
  47.         //while(true){
  48.             double[] areas=table.getNumberArray("area",new double[0]);
  49.             for(double area:areas){
  50.                 SmartDashboard.putDouble("Area",area);
  51.         //  }
  52.         }
  53.     }
  54.  
  55.     public void autonomousInit() {
  56.     }
  57.  
  58.     /**
  59.      * This function is called periodically during autonomous
  60.      */
  61.     public void autonomousPeriodic() {
  62.  
  63.     }
  64.  
  65.     public void teleopInit() {
  66.        
  67.     }
  68.  
  69.     /**
  70.      * This function is called periodically during operator control
  71.      */
  72.     public void teleopPeriodic() {
  73.         test="Keys: ";
  74.         if (joystick.getThrottle() > 0) {
  75.             servo.set(2.4);
  76.         } else
  77.             servo.set(1);
  78.         currentButtonState=joystick.getRawButton(5);
  79.         SmartDashboard.putBoolean("Button5", currentButtonState);
  80.         SmartDashboard.putNumber("CurrentTime", System.currentTimeMillis());
  81.         SmartDashboard.putNumber("Framerate", NetworkTable.getTable("GRIP").getNumber("myNumber", Double.NaN));
  82.         SmartDashboard.putBoolean("HasArea", table.containsKey("area"));
  83.        
  84.         for (String i: NetworkTable.getTable("GRIP").getKeys())
  85.             test+=i+", ";
  86.         test+="\n";
  87.         SmartDashboard.putString("Keys", test);
  88.         if (currentButtonState) {
  89.             try {
  90.                 SmartDashboard.putString("Area: ", Arrays.toString(table.getNumberArray("area", new double[0])));
  91.                 SmartDashboard.putBoolean("Errored", false);
  92.                 SmartDashboard.putString("CenterX: ", Arrays.toString(table.getNumberArray("centerX", new double[0])));
  93.                 SmartDashboard.putString("CenterY", Arrays.toString(table.getNumberArray("centerY",new double[0])));
  94.             } catch (Exception e) {
  95.                 SmartDashboard.putBoolean("Errored", true);
  96.             }
  97.         }
  98.         drive.arcadeDrive(joystick.getTwist(), joystick.getY());
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment