Skip to content

Commit

Permalink
started elevator
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierCraw committed Nov 2, 2024
1 parent 419c44d commit 371977d
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 50 deletions.
12 changes: 4 additions & 8 deletions src/main/java/com/team766/robot/rookie_bot/OI.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,14 @@ public void run(final Context context) {
context.takeOwnership(Robot.drive);
while (true) {
// wait for driver station data (and refresh it using the WPILib APIs)

RobotProvider.instance.refreshDriverStationData();

// Add driver controls here - make sure to take/release ownership
// of mechanisms when appropriate.

Robot.drive.setArcadeDrivePower(joystick0.getAxis(1), joystick0.getAxis(3));
context.waitFor(() -> RobotProvider.instance.hasNewDriverStationData());
}


Robot.drive.setArcadeDrivePower(-1 * joystick0.getAxis(1), joystick0.getAxis(3));
context.waitFor(() -> RobotProvider.instance.hasNewDriverStationData());
}

}

}
5 changes: 5 additions & 0 deletions src/main/java/com/team766/robot/rookie_bot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
public class Robot implements RobotConfigurator {
// Declare mechanisms (as static fields) here
public static Drive drive;
public static Elevator elevator;

@Override
public void initializeMechanisms() {
// Initialize mechanisms here
drive = new Drive();
elevator = new Elevator();
}

@Override
Expand All @@ -24,4 +26,7 @@ public Procedure createOI() {
public AutonomousMode[] getAutonomousModes() {
return AutonomousModes.AUTONOMOUS_MODES;
}



}
36 changes: 19 additions & 17 deletions src/main/java/com/team766/robot/rookie_bot/mechanisms/Drive.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,23 @@
import com.team766.hal.RobotProvider;

public class Drive extends Mechanism {
private MotorController leftMotor;
private MotorController rightMotor;
public Drive(){
leftMotor = RobotProvider.instance.getMotor("drive.leftMotor");
rightMotor = RobotProvider.instance.getMotor("drive.rightMotor");
}
public void setDrivePower(double leftPower, double rightPower){
checkContextOwnership();
leftMotor.set(leftPower);
rightMotor.set(rightPower);
}
public void setArcadeDrivePower(double forward, double turn) {
double leftMotorPower = turn + forward;
double rightMotorPower = -turn + forward;
setDrivePower(leftMotorPower, rightMotorPower);
}
private MotorController leftMotor;
private MotorController rightMotor;

}
public Drive() {
leftMotor = RobotProvider.instance.getMotor("drive.leftMotor");
rightMotor = RobotProvider.instance.getMotor("drive.rightMotor");
}

public void setDrivePower(double leftPower, double rightPower) {
checkContextOwnership();
leftMotor.set(leftPower);
rightMotor.set(rightPower);
}

public void setArcadeDrivePower(double forward, double turn) {
double leftMotorPower = turn + forward;
double rightMotorPower = -turn + forward;
setDrivePower(leftMotorPower, rightMotorPower);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.team766.rookie_bot.mechanisms;

import com.team766.hal.RobotProvider;
import com.team766.hal.SpeedController;
import com.team766.hal.EncoderReader;

public class Elevator extends Mechanism{
private SpeedController m_elevator;
private EncoderReader m_elevatorEncoder;

public Elevator() {
m_elevator = RobotProvider.instance.getMotor("elevator");
m_elevatorEncoder = RobotProvider.instance.getEncoder("elevator_encoder");
resetEncoder();
}

public void move(double power){
m_elevator.set(power);
}

public double getElevatorDistance(){
return m_elevatorEncoder.getDistance();
}

public void resetEncoder(){
m_elevatorEncoder.reset();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@

public class DriveStraight extends Procedure {

public void run(final Context context) {
context.takeOwnership(Robot.drive);
Robot.drive.setDrivePower(0.5, 0.5);
context.waitForSeconds(1);
Robot.drive.setDrivePower(0, 0);

}
}
public void run(final Context context) {
context.takeOwnership(Robot.drive);
Robot.drive.setDrivePower(0.5, 0.5);
context.waitForSeconds(1);
Robot.drive.setDrivePower(0, 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@

public class DriveinaSquare extends Procedure {
public void run(Context context) {
//This loop repeats 4 times
// This loop repeats 4 times
for (int i = 0; i < 4; ++i) {
//Drive along the side of the square
new DriveStraight().run(context);
//Turn at corner
new TurnRight().run(context);
// Drive along the side of the square
new DriveStraight().run(context);

// Turn at corner
new TurnRight().run(context);
}
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.team766.robot.rookie_bot.procedures;
import com.team766.framework.Procedure;
import com.team766.controllers.PIDController;
import com.team766.framework.Context;
import com.team766.robot.rookie_bot.Robot;

public class PIDElevator {

Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
import com.team766.robot.rookie_bot.Robot;

public class TurnRight extends Procedure {
public void run(Context context) {
context.takeOwnership(Robot.drive);
Robot.drive.setDrivePower(0.25, -0.25);
context.waitForSeconds(0.90);
Robot.drive.setDrivePower(0, 0);

}

}
public void run(Context context) {
context.takeOwnership(Robot.drive);
Robot.drive.setDrivePower(0.25, -0.25);
context.waitForSeconds(0.90);
Robot.drive.setDrivePower(0, 0);
}
}

0 comments on commit 371977d

Please sign in to comment.