Skip to content

Commit

Permalink
Added DriveForward Code, with working rate parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
bit-101010 committed Dec 7, 2017
1 parent 035f4d9 commit 1a1b448
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
10 changes: 7 additions & 3 deletions src/Commands/DriveForward.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTOR

DriveForward::DriveForward(): Command() {
DriveForward::DriveForward(double rate): Command() {
m_rate = rate;
// Use requires() here to declare subsystem dependencies
// eg. requires(Robot::chassis.get());
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=REQUIRES
Expand All @@ -29,7 +30,8 @@ void DriveForward::Initialize() {

// Called repeatedly when this Command is scheduled to run
void DriveForward::Execute() {

Robot::driveMotor->SetLeftMotor(m_rate);
Robot::driveMotor->SetLeftMotor(m_rate);
}

// Make this return true when this Command no longer needs to run execute()
Expand All @@ -39,11 +41,13 @@ bool DriveForward::IsFinished() {

// Called once after isFinished returns true
void DriveForward::End() {
Robot::driveMotor->StopLeftMotor();
Robot::driveMotor->StopRightMotor();

}

// Called when another command which requires one or more of the same
// subsystems is scheduled to run
void DriveForward::Interrupted() {

DriveForward::End(); //Nothing to clean up, so end the command if interrupted.
}
3 changes: 2 additions & 1 deletion src/Commands/DriveForward.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
class DriveForward: public Command {
public:
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTOR
DriveForward();
DriveForward(double rate);
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTOR

virtual void Initialize();
Expand All @@ -35,6 +35,7 @@ class DriveForward: public Command {
virtual void Interrupted();

private:
double m_rate;
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=VARIABLES

// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=VARIABLES
Expand Down
18 changes: 16 additions & 2 deletions src/Subsystems/DriveMotor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

DriveMotor::DriveMotor() : Subsystem("DriveMotor") {
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DECLARATIONS
speedController1 = RobotMap::driveMotorSpeedController1;
speedController2 = RobotMap::driveMotorSpeedController2;
leftMotor = RobotMap::driveMotorSpeedController1;
rightMotor = RobotMap::driveMotorSpeedController2;
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DECLARATIONS
}

Expand All @@ -39,3 +39,17 @@ void DriveMotor::InitDefaultCommand() {
// Put methods for controlling this subsystem
// here. Call these from Commands.

void DriveMotor::SetLeftMotor(double rate){
DriveMotor::leftMotor->Set(rate);
}
void DriveMotor::SetRightMotor(double rate){
DriveMotor::rightMotor->Set(rate);
}

void DriveMotor::StopLeftMotor(){
DriveMotor::leftMotor->StopMotor();
}

void DriveMotor::StopRightMotor(){
DriveMotor::rightMotor->StopMotor();
}
8 changes: 6 additions & 2 deletions src/Subsystems/DriveMotor.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ class DriveMotor: public Subsystem {
// It's desirable that everything possible is private except
// for methods that implement subsystem capabilities
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DECLARATIONS
std::shared_ptr<SpeedController> speedController1;
std::shared_ptr<SpeedController> speedController2;
std::shared_ptr<SpeedController> leftMotor;
std::shared_ptr<SpeedController> rightMotor;
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DECLARATIONS
public:
DriveMotor();
void InitDefaultCommand();
void SetLeftMotor(double rate); //these are split, beacuse the methods that goes in the subsystem should be fairly multipurpose.
void SetRightMotor(double rate);
void StopLeftMotor();
void StopRightMotor();
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTANTS
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTANTS
};
Expand Down

0 comments on commit 1a1b448

Please sign in to comment.