Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
LakshBhambhani committed Nov 12, 2019
2 parents 575883d + e0cf13a commit bd20f72
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 142 deletions.
Binary file modified .DS_Store
Binary file not shown.
134 changes: 0 additions & 134 deletions MiniLib/src/frc/team670/pi/UltrasonicSensor.java

This file was deleted.

12 changes: 10 additions & 2 deletions MiniLib/src/frc/team670/pi/sensors/Encoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class Encoder {

private int leftPinState;
private int rightPinState;

private boolean reversed;

public int count;

Expand Down Expand Up @@ -61,8 +63,9 @@ public void update() {
* @param rightP Pin for the right sensor on the encoder
* @throws PigpioException
*/
public Encoder(int leftP, int rightP) throws PigpioException {
public Encoder(int leftP, int rightP, boolean reversed) throws PigpioException {
count = 0;
this.reversed = reversed;

// leftPin = gpio.provisionDigitalInputPin(leftP);
// leftPin.setShutdownOptions(true);
Expand Down Expand Up @@ -97,7 +100,12 @@ public Encoder(int leftP, int rightP) throws PigpioException {
* @return int Ticks - the number of ticks
*/
public int getTicks() {
return this.count;
if(reversed) {
return -1 * this.count;
}
else {
return this.count;
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions MiniLib/src/frc/team670/pi/tests/EncoderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public static void main(String args[]) throws InterruptedException, PigpioExcept
Motor left = new Motor(MOTOR_1_PIN_A, MOTOR_1_PIN_B, RaspiPin.GPIO_06);
Motor right = new Motor(MOTOR_2_PIN_A, MOTOR_2_PIN_B, RaspiPin.GPIO_03);

Encoder lEncoder = new Encoder(5, 6);//RaspiPin.GPIO_07
Encoder rEncoder = new Encoder(4, 18);//RaspiPin.GPIO_21
Encoder lEncoder = new Encoder(5, 6, false);//RaspiPin.GPIO_07
Encoder rEncoder = new Encoder(4, 18, false);//RaspiPin.GPIO_21

// left.set(0.4);
// right.set(0.4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public CurveStraightDrive(double dist, double lspeed, double rspeed, double secs
this.speedR = rspeed;
this.time = dist;
this.dist = secs;
lEncoder = new Encoder(7, 1);
rEncoder = new Encoder(22, 21);
lEncoder = Robot.driveBase.getLeftEncoder();
rEncoder = Robot.driveBase.getRightEncoder();
requires(drivebase);
}

Expand Down
4 changes: 2 additions & 2 deletions MiniLib/src/frc/team670/robot/subsystems/DriveBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ public DriveBase() {
left = new Motor(MOTOR_1_PIN_A, MOTOR_1_PIN_B, RaspiPin.GPIO_06);
right = new Motor(MOTOR_2_PIN_A, MOTOR_2_PIN_B, RaspiPin.GPIO_03);
try {
le = new Encoder(5, 6);
le = new Encoder(5, 6, false); //TODO modify this based on motor direction
} catch (PigpioException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
re = new Encoder(4, 18);
re = new Encoder(4, 18, false); //TODO modify this based on motor direction
} catch (PigpioException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Expand Down

0 comments on commit bd20f72

Please sign in to comment.