Skip to content

Commit

Permalink
Added encoders
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Brar committed Dec 28, 2015
1 parent 7c865ca commit d33b09a
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/Commands/DriveDistance.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* DriveDistance.cpp
*
* Created on: Dec 28, 2015
* Author: tony
*/

#include <Commands/DriveDistance.h>

16 changes: 16 additions & 0 deletions src/Commands/DriveDistance.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* DriveDistance.h
*
* Created on: Dec 28, 2015
* Author: tony
*/

#ifndef SRC_COMMANDS_DRIVEDISTANCE_H_
#define SRC_COMMANDS_DRIVEDISTANCE_H_

#include <CommandBase.h>

class DriveDistance: public CommandBase {
};

#endif /* SRC_COMMANDS_DRIVEDISTANCE_H_ */
22 changes: 21 additions & 1 deletion src/Subsystems/Drive.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "Drive.h"
#include <Victor.h>
#include <DoubleSolenoid.h>
#include <Encoder.h>

Drive::Drive() :
Subsystem("Drive") {
Expand All @@ -11,6 +12,12 @@ Drive::Drive() :
right2 = new Victor(4);
right3 = new Victor(5);
gearSolenoid = new DoubleSolenoid(0, 1);
leftEncoder = new Encoder(0, 1);
rightEncoder = new Encoder(2, 3);
leftEncoder->SetDistancePerPulse(1.0 / 360.0);
rightEncoder->SetDistancePerPulse(1.0 / 360.0);
leftEncoder->SetReverseDirection(true);
rightEncoder->SetReverseDirection(false);
}

Drive::~Drive() {
Expand All @@ -21,6 +28,8 @@ Drive::~Drive() {
delete right2;
delete right3;
delete gearSolenoid;
delete leftEncoder;
delete rightEncoder;
}

void Drive::SetSpeeds(float leftSpeed, float rightSpeed) {
Expand All @@ -39,6 +48,17 @@ void Drive::SetHighGear() {
gearSolenoid->Set(DoubleSolenoid::kForward);

}
void Drive::SetLowGear(){
void Drive::SetLowGear() {
gearSolenoid->Set(DoubleSolenoid::kReverse);
}

double Drive::GetDistanceTraveled() {
double leftDistance = leftEncoder->GetDistance() * 19.867432;
double rightDistance = rightEncoder->GetDistance() * 19.867432;
return (leftDistance + rightDistance) / 2;
}

void Drive::ResetEncoders() {
leftEncoder->Reset();
rightEncoder->Reset();
}
5 changes: 5 additions & 0 deletions src/Subsystems/Drive.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

class Victor;
class DoubleSolenoid;
class Encoder;

class Drive: public Subsystem {
public:
Expand All @@ -15,6 +16,8 @@ class Drive: public Subsystem {
void ResetSpeeds();
void SetHighGear();
void SetLowGear();
double GetDistanceTraveled();
void ResetEncoders();

private:
Victor* left1;
Expand All @@ -24,6 +27,8 @@ class Drive: public Subsystem {
Victor* right2;
Victor* right3;
DoubleSolenoid* gearSolenoid;
Encoder* leftEncoder;
Encoder* rightEncoder;
};

#endif /* SRC_SUBSYSTEMS_DRIVE_H_ */

0 comments on commit d33b09a

Please sign in to comment.