Add lidar to drivetrain
authorKevin Zhang <icestormf1@gmail.com>
Thu, 11 Feb 2016 03:10:11 +0000 (19:10 -0800)
committerKevin Zhang <icestormf1@gmail.com>
Thu, 11 Feb 2016 03:10:11 +0000 (19:10 -0800)
src/org/usfirst/frc/team3501/robot/Robot.java
src/org/usfirst/frc/team3501/robot/subsystems/DriveTrain.java

index a86721d0a1a4ac73903f5ba6a2c63cae614c1137..051aac623c756d54bc2f5ecf1e3555ceafcebcb2 100644 (file)
@@ -5,7 +5,6 @@ import org.usfirst.frc.team3501.robot.subsystems.DriveTrain;
 import org.usfirst.frc.team3501.robot.subsystems.Scaler;
 import org.usfirst.frc.team3501.robot.subsystems.Shooter;
 
-import edu.wpi.first.wpilibj.I2C;
 import edu.wpi.first.wpilibj.IterativeRobot;
 import edu.wpi.first.wpilibj.command.Scheduler;
 import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
@@ -22,15 +21,12 @@ public class Robot extends IterativeRobot {
   SendableChooser positionOneDefense, positionTwoDefense, positionThreeDefense,
       positionFourDefense, positionFiveDefense;
 
-  public static Lidar lidar;
-
   @Override
   public void robotInit() {
     driveTrain = new DriveTrain();
     oi = new OI();
     shooter = new Shooter();
     scaler = new Scaler();
-    lidar = new Lidar(I2C.Port.kOnboard);
 
     // Sendable Choosers allows the driver to select the position of the robot
     // and the positions of the defenses from a drop-down menu on the Smart
@@ -123,18 +119,11 @@ public class Robot extends IterativeRobot {
 
   @Override
   public void teleopInit() {
-    lidar.start();
   }
 
   @Override
   public void teleopPeriodic() {
-    printLidarValues();
     Scheduler.getInstance().run();
 
   }
-
-  public void printLidarValues() {
-
-    System.out.println(lidar.pidGet());
-  }
 }
index 6969ed1d961de1130ef7f9658578a770b4a09662..6936abf72335a05142e400b45f673cf63342fcb1 100644 (file)
@@ -1,15 +1,18 @@
 package org.usfirst.frc.team3501.robot.subsystems;
 
 import org.usfirst.frc.team3501.robot.Constants;
+import org.usfirst.frc.team3501.robot.Lidar;
 
 import edu.wpi.first.wpilibj.CANTalon;
 import edu.wpi.first.wpilibj.CounterBase.EncodingType;
 import edu.wpi.first.wpilibj.Encoder;
+import edu.wpi.first.wpilibj.I2C;
 import edu.wpi.first.wpilibj.command.Subsystem;
 
 public class DriveTrain extends Subsystem {
   // Drivetrain related objects
   private Encoder leftEncoder, rightEncoder;
+  public static Lidar lidar;
   private CANTalon frontLeft, frontRight, rearLeft, rearRight;
 
   public DriveTrain() {
@@ -18,6 +21,7 @@ public class DriveTrain extends Subsystem {
     rearLeft = new CANTalon(Constants.DriveTrain.REAR_LEFT);
     rearRight = new CANTalon(Constants.DriveTrain.REAR_RIGHT);
 
+    lidar = new Lidar(I2C.Port.kOnboard);
     leftEncoder = new Encoder(Constants.DriveTrain.ENCODER_LEFT_A,
         Constants.DriveTrain.ENCODER_LEFT_B, false, EncodingType.k4X);
     rightEncoder = new Encoder(Constants.DriveTrain.ENCODER_RIGHT_A,
@@ -35,6 +39,10 @@ public class DriveTrain extends Subsystem {
     rightEncoder.reset();
   }
 
+  public double getLidarDistance() {
+    return lidar.pidGet();
+  }
+
   public double getRightSpeed() {
     return rightEncoder.getRate(); // in inches per second
   }