Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add line following #66

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ repositories {

// Somewhere after the deploy block, and before the dependencies block
// https://github.com/pjreiniger/SnobotSim/wiki/Setting-Up-The-Simulator
// apply plugin: com.snobot.simulator.plugin.SnobotSimulatorPlugin
apply plugin: com.snobot.simulator.plugin.SnobotSimulatorPlugin

// configurations {
// snobotSimCompile
// }
configurations {
snobotSimCompile
}

// Defining my dependencies. In this case, WPILib (+ friends), and vendor libraries.
// Also defines JUnit 4.
Expand All @@ -65,7 +65,7 @@ dependencies {
compile 'com.moandjiezana.toml:toml4j:0.7.2'

// SnobotSim
// snobotSimCompile snobotSimJava()
snobotSimCompile snobotSimJava()
}

// Setting up my Jar File. In this case, adding all libraries into the main jar ('fat jar')
Expand Down
35 changes: 31 additions & 4 deletions src/main/java/frc/robot/Drivetrain.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.ctre.phoenix.motorcontrol.ControlMode;
import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX;

import edu.wpi.first.wpilibj.DigitalInput;
import frc.robot.loggable.LoggableTalonSRX;
import frc.robot.logging.DataLogger;
import frc.robot.logging.Loggable;
Expand All @@ -24,6 +25,10 @@ public class Drivetrain implements Loggable {
private LoggableTalonSRX rightTalon;
private LoggableTalonSRX rightSlave;

private DigitalInput leftLine;
private DigitalInput midLine;
private DigitalInput rightLine;

/**
* Constructor
*
Expand Down Expand Up @@ -86,10 +91,10 @@ public void arcadeDrive(double xDrive, double yDrive) {
/**
* Drives the robot with an tank style drive
*
* @param xDrive The speed to drive the left drivetrain (ranges
* from -1.0 to +1.0)
* @param yDrive The speed to drive the right drivetrain (ranges
* from -1.0 to +1.0)
* @param xDrive The speed to drive the left drivetrain (ranges from -1.0 to
* +1.0)
* @param yDrive The speed to drive the right drivetrain (ranges from -1.0 to
* +1.0)
*/
public void tankDrive(double leftDrive, double rightDrive) {
this.driveLeft(leftDrive);
Expand Down Expand Up @@ -122,6 +127,28 @@ public void log(DataLogger logger) {
rightSlave.log(logger);
}

/**
* Uses outside line sensors to follow the line.
*
* @param maxMotorPercent maximum motor percent
*/
public void followLine(double maxMotorPercent) {
double leftMotorPower = 1;
double rightMotorPower = 1;
if (leftLine.get() && !rightLine.get()) {
leftMotorPower = 0.75;
}
if (!leftLine.get() && rightLine.get()) {
rightMotorPower = 0.75;
}
if (leftLine.get() && rightLine.get()) {
leftMotorPower = 0;
rightMotorPower = 0;
}
driveLeft(leftMotorPower * maxMotorPercent);
driveRight(rightMotorPower * maxMotorPercent);
}

public Double getOutputCurrent(WPI_TalonSRX talon) {
if (RuntimeDetector.isSimulation()) {
return 0.0;
Expand Down
43 changes: 41 additions & 2 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,15 @@ private void humanControl() {
if (driver.getBumper(GenericHID.Hand.kRight)) {
speedInput = -speedInput;
}
}

drive.arcadeDrive(turnInput, speedInput);
// System.out.printf("Speed: %f\n", speedInput);
// Call line following
if (driver.getXButton()) {
followLine(0.8);
} else {
drive.arcadeDrive(turnInput, speedInput);
}
}

manipulation.lift(operator.getY(Hand.kLeft));
scoring.tilt(operator.getY(Hand.kRight));
Expand Down Expand Up @@ -349,6 +355,7 @@ private void humanControl() {

double collectionSpeed = speedRight - speedLeft;
scoring.roll(collectionSpeed);

}

/**
Expand Down Expand Up @@ -377,4 +384,36 @@ public void testPeriodic() {
public void disabledInit() {
dataLogger.close();
}

public void followLine(double maxMotorPercent) {
double leftMotorPower = .1;
double rightMotorPower = .1;
double turnspeed = 0.0;
double turnmodifier = 0.3;
double forwardspeed = -0.15;

int l = (leftLine.get()) ? 1 : 0;
int m = (midLine.get()) ? 1 : 0;
int r = (rightLine.get()) ? 1 : 0;

String bin = String.format("%d%d%d", l, m, r);
System.out.println(bin);

if (bin.equals("100")) {
turnspeed -= turnmodifier;
} else if (bin.equals("110")) {
turnspeed -= turnmodifier;
} else if (bin.equals("001")) {
turnspeed += turnmodifier;
} else if (bin.equals("011")) {
turnspeed += turnmodifier;
} else if (bin.equals("101")) {
System.out.println("Subscribe to Pewdiepie");
leftMotorPower = 0;
rightMotorPower = 0;
} else {
System.out.println("Jordan");
}
drive.arcadeDrive(turnspeed, forwardspeed);
}
}