Advertisement
Juniormunk

OpenMV M7 RoboRio Code

Mar 23rd, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.56 KB | None | 0 0
  1.  
  2. /*----------------------------------------------------------------------------*/
  3. /* Copyright (c) 2018 FIRST. All Rights Reserved.                             */
  4. /* Open Source Software - may be modified and shared by FRC teams. The code   */
  5. /* must be accompanied by the FIRST BSD license file in the root directory of */
  6. /* the project.                                                               */
  7. /*----------------------------------------------------------------------------*/
  8.  
  9. package frc.robot.utilities;
  10.  
  11. import edu.wpi.first.wpilibj.DriverStation;
  12. import edu.wpi.first.wpilibj.SerialPort;
  13.  
  14. /**
  15.  * Add your docs here.
  16.  */
  17. public class ByteVision
  18. {
  19.  
  20.     SerialPort visionPortIntake;
  21.     double lastValue = 0.0;
  22.     int counter=0;
  23.  
  24.     public ByteVision()
  25.     {
  26.         try
  27.         {
  28.             visionPortIntake = new SerialPort(115200, SerialPort.Port.kUSB);
  29.  
  30.         }
  31.         catch (Exception e)
  32.         {
  33.             DriverStation.reportError("ERROR: Vision tracking intake camera", e.getStackTrace());
  34.         }
  35.     }
  36.  
  37.     public double getDataIntake()
  38.     {
  39.         if (visionPortIntake != null)
  40.         {
  41.            
  42.             try
  43.             {
  44.                 counter=0;
  45.                 lastValue = Double.parseDouble(visionPortIntake.readString());
  46.                 return lastValue;
  47.             }
  48.             catch(Exception e)
  49.             {
  50.                 counter++;
  51.                 if(counter<25)
  52.                     return lastValue;
  53.                 return 0.0;
  54.  
  55.             }
  56.         }
  57.         return 0.0;
  58.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement