From 52c3d5326184336bd6e43c0b55e47d4b17142e37 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 20 Feb 2017 23:24:59 -0500 Subject: Write Autonomous. --- .../usfirst/frc/team4272/robot2016/Autonomous.java | 38 +++++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/org/usfirst/frc/team4272/robot2016/Autonomous.java b/src/org/usfirst/frc/team4272/robot2016/Autonomous.java index 7b2194c..39b792d 100644 --- a/src/org/usfirst/frc/team4272/robot2016/Autonomous.java +++ b/src/org/usfirst/frc/team4272/robot2016/Autonomous.java @@ -1,26 +1,46 @@ package org.usfirst.frc.team4272.robot2016; -import edu.wpi.first.wpilibj.Timer; -import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; - public class Autonomous { - private final Timer time = new Timer(); private final HwRobot robot; public Autonomous(HwRobot robot) { this.robot = robot; - time.reset(); - time.start(); + robot.lDriveE.reset(); + robot.rDriveE.reset(); } public Control run(Control c) { + double lDist = robot.lDriveE.getDistance(); + double rDist = robot.rDriveE.getDistance(); + + double speed = 0.6; + double thresh = 10; + double target = 15; + double max = 16; + if (lDist < thresh) { + c.lDrive = speed; + } else if (lDist < max) { + c.lDrive = speed*Math.sqrt((target-lDist)/(target-thresh)); + } else { + c.lDrive = 0; + } - if (time.get() < 15) { + if (rDist < thresh) { + c.rDrive = speed; + } else if (rDist < max) { + c.rDrive = speed*Math.sqrt((target-rDist)/(target-thresh)); + } else { + c.rDrive = 0; } - else { + + if (Math.abs(lDist - rDist) > 0.25) { + if (lDist > rDist) { + c.lDrive *= 0.2; + } else { + c.rDrive *= 0.2; + } } - SmartDashboard.putNumber("autoTime", time.get()); return c; } -- cgit v1.2.3-54-g00ecf