Skip to content
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
9 changes: 9 additions & 0 deletions .github/.idea/.github.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .github/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .github/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions .github/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .run/Build Robot.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" />
<option name="scriptParameters" value="--scan" />
<option name="taskDescriptions">
<list />
</option>
Expand Down
3 changes: 3 additions & 0 deletions gradle/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions gradle/.idea/gradle.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions gradle/.idea/libraries/gradle_wrapper.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions gradle/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions gradle/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions gradle/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

package competition.subsystems.drive;

import javax.inject.Inject;
Expand All @@ -21,7 +22,7 @@ public class DriveSubsystem extends BaseDriveSubsystem implements DataFrameRefre
public final XCANMotorController frontRight;

DoubleProperty dp;

public boolean isPrecisionModeOn = false;
@Inject
public DriveSubsystem(XCANMotorController.XCANMotorControllerFactory motorControllerFactory, ElectricalContract electricalContract, PropertyFactory pf) {
log.info("Creating DriveSubsystem");
Expand All @@ -35,7 +36,6 @@ public DriveSubsystem(XCANMotorController.XCANMotorControllerFactory motorContro
pf.setPrefix(this);
dp = pf.createPersistentProperty("DriveSubsystem", 1.5);
}

public void tankDrive(double leftPower, double rightPower) {
// You'll need to take these power values and assign them to all of the motors.
// As an example, here is some code that has the frontLeft motor to spin
Expand Down Expand Up @@ -69,7 +69,7 @@ public PIDManager getRotateDecayPid() {

@Override
public void move(XYPair translate, double rotate) {
throw new RuntimeException("Not yet implemented");
throw new RuntimeException("Not yet implemented");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,62 @@

import javax.inject.Inject;

import competition.subsystems.pose.PoseSubsystem;
import xbot.common.command.BaseCommand;
import competition.subsystems.drive.DriveSubsystem;

public class DriveToOrientationCommand extends BaseCommand {

DriveSubsystem drive;
PoseSubsystem pose;
double p = 10;

double d = 10;

double speed = 0;

double previousPosition;

double goal;

double currentRotation;

double targetHeading;

@Inject
public DriveToOrientationCommand(DriveSubsystem driveSubsystem) {
public DriveToOrientationCommand(DriveSubsystem driveSubsystem, PoseSubsystem a) {
this.drive = driveSubsystem;
this.pose = a;
}

public void setTargetHeading(double heading) {
// This method will be called by the test, and will give you a goal heading.
// You'll need to remember this target position and use it in your calculations.
targetHeading = heading;
}

@Override
public void initialize() {
currentRotation = pose.getCurrentHeading().getDegrees();
goal = targetHeading;
previousPosition = currentRotation;
currentRotation = -currentRotation;
System.out.println("MY GOAL:" + goal);
System.out.println("MY starting pos:" + currentRotation);
// If you have some one-time setup, do it here.
}

@Override
public void execute() {
currentRotation = pose.getCurrentHeading().getDegrees();
double error = goal - currentRotation;
speed = currentRotation - previousPosition;
if (error >= 180) {
error = error - 360;
}
double power = p * error - d * speed;
drive.tankDrive(-power,power);
previousPosition = currentRotation;
// Here you'll need to figure out a technique that:
// - Gets the robot to turn to the target orientation
// - Gets the robot stop (or at least be moving really really slowly) at the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,31 @@
public class DriveToPositionCommand extends BaseCommand {

DriveSubsystem drive;

PoseSubsystem pose;

double goalPosition = 0;

double d =50;

double p = 50;

double previousPosition = 0;

double currentPosition = 0;

double speed = 0;

@Inject
public DriveToPositionCommand(DriveSubsystem driveSubsystem, PoseSubsystem pose) {
this.drive = driveSubsystem;
this.pose = pose;
}

public void setTargetPosition(double position) {
public void setTargetPosition(double newGoalPosition) {
// This method will be called by the test, and will give you a goal distance.
// You'll need to remember this target position and use it in your calculations.
goalPosition = newGoalPosition;
}

@Override
Expand All @@ -34,18 +48,23 @@ public void execute() {
// - Hint: use pose.getPosition() to find out where you are
// - Gets the robot stop (or at least be moving really really slowly) at the
// target position

// How you do this is up to you. If you get stuck, ask a mentor or student for
// some hints!
drive.tankDrive(0.25,0.25);
pose.getPosition();
}
currentPosition = pose.getPosition();
double error = goalPosition - currentPosition;
speed = currentPosition - previousPosition;
double power = p * error - d * speed;
drive.tankDrive(power,power);

previousPosition = currentPosition;
}
@Override
public boolean isFinished() {
// Modify this to return true once you have met your goal,
// and you're moving fairly slowly (ideally stopped)
return false;
boolean atGoalPosition = Math.abs(currentPosition - goalPosition) < 0.01;
boolean notMoving = Math.abs(speed) < 0.001;
return atGoalPosition && notMoving;
}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

package competition.subsystems.drive.commands;

import javax.inject.Inject;
Expand Down Expand Up @@ -35,11 +36,15 @@ public void execute() {
// Here's how to get how far the left joystick's Y-axis is pushed:
double leftValue = operatorInterface.gamepad.getLeftVector().getY();
// TODO: get how far the RIGHT joystick's Y-axis is pushed as well

double rightValue = operatorInterface.gamepad.getRightVector().getY();
// Pass values into the DriveSubsystem so it can control motors:
// right now, this just sends the left power to the left part of the drive.
// You'll need to give it a right power value as well.
drive.tankDrive(leftValue, 0);
if(drive.isPrecisionModeOn = true) {
leftValue = leftValue / 2;
rightValue = rightValue / 2;
}
drive.tankDrive(leftValue, rightValue);
}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

package competition.subsystems.drive.commands;

import javax.inject.Inject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,21 @@
public class TurnLeft90DegreesCommand extends BaseCommand {

DriveSubsystem drive;

PoseSubsystem pose;

double p = 10;

double d = 10;

double speed = 0;

double previousPosition;

double goal;

double currentRotation;

@Inject
public TurnLeft90DegreesCommand(DriveSubsystem driveSubsystem, PoseSubsystem pose) {
this.drive = driveSubsystem;
Expand All @@ -19,10 +32,24 @@ public TurnLeft90DegreesCommand(DriveSubsystem driveSubsystem, PoseSubsystem pos

@Override
public void initialize() {
currentRotation = pose.getCurrentHeading().getDegrees();
goal = currentRotation + 90;
previousPosition = currentRotation;
currentRotation = -currentRotation;
System.out.println("MY GOAL:" + goal);
System.out.println("MY starting pos:" + currentRotation);
}

@Override
public void execute() {
currentRotation = pose.getCurrentHeading().getDegrees();
double error = goal - currentRotation;
speed = currentRotation - previousPosition;
if (error >= 180) {
error = error - 360;
}
double power = p * error - d * speed;
drive.tankDrive(-power,power);
previousPosition = currentRotation;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import competition.BaseCompetitionTest;
import xbot.common.command.XScheduler;

public class AObserveHowCommandsWork extends BaseCompetitionTest {
public class AObserveHowCommandsWork extends BaseCompetitionTest {

protected Logger log;

Expand Down
Loading