-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from Welpyfish/auto-dev
Ball 2
- Loading branch information
Showing
15 changed files
with
200 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
|
||
// Copyright (c) FIRST and other WPILib contributors. | ||
// Open Source Software; you can modify and/or share it under the terms of | ||
// the WPILib BSD license file in the root directory of this project. | ||
|
||
/* | ||
test 1: moved about 0.2 speed 212 cm 5 rotations -> 42cm per rotation | ||
conversion factor around 2.3 | ||
*/ | ||
|
||
#include "commands/TankMoveGyro.h" | ||
|
||
|
||
TankMoveGyro::TankMoveGyro(Drivetrain& drivetrain, double distance, double speed): | ||
m_distance(distance), | ||
m_drivetrain(&drivetrain), | ||
m_speed(speed) { | ||
|
||
SetName("TankMove"); | ||
AddRequirements({m_drivetrain}); | ||
} | ||
|
||
// Called just before this Command runs the first time | ||
void TankMoveGyro::Initialize() { | ||
m_drivetrain->m_leftLeadEncoder.SetPosition(0); | ||
m_drivetrain->m_rightLeadEncoder.SetPosition(0); | ||
m_drivetrain->m_navX.Reset(); | ||
distanceCounter = 0; | ||
m_drivetrain->Drive(0, 0); | ||
} | ||
|
||
|
||
// Called repeatedly when this Command is scheduled to run | ||
void TankMoveGyro::Execute() { | ||
distanceCounter = (-m_drivetrain->m_leftLeadEncoder.GetPosition() + m_drivetrain->m_rightLeadEncoder.GetPosition())/2; | ||
double correction = m_drivetrain->m_pid.Calculate(m_drivetrain->m_navX.GetAngle()); | ||
if (m_distance >= 0 && distanceCounter < m_distance){ | ||
m_drivetrain->Drive(m_speed-correction, m_speed+correction); | ||
} | ||
else if(m_distance < 0 && distanceCounter > m_distance){ | ||
m_drivetrain->Drive(-m_speed-correction, -m_speed+correction); | ||
} | ||
} | ||
|
||
// Make this return true when this Command no longer needs to run execute() | ||
bool TankMoveGyro::IsFinished() { | ||
distanceCounter = (-m_drivetrain->m_leftLeadEncoder.GetPosition() + m_drivetrain->m_rightLeadEncoder.GetPosition())/2; | ||
if (m_distance >= 0){ | ||
return(distanceCounter >= m_distance); | ||
} | ||
else{ | ||
return(distanceCounter <= m_distance); | ||
} | ||
} | ||
|
||
// Called once after isFinished returns true | ||
void TankMoveGyro::End(bool) { | ||
m_drivetrain->Drive(0, 0); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include "commands/TankStop.h" | ||
|
||
TankStop::TankStop( | ||
Drivetrain& drivetrain, double duration): | ||
m_drivetrain(&drivetrain), | ||
m_duration(duration){ | ||
|
||
SetName("TankStop"); | ||
AddRequirements({m_drivetrain}); | ||
|
||
} | ||
|
||
void TankStop::Initialize(){ | ||
|
||
periods = 0; | ||
period_target = m_duration * 50; | ||
|
||
m_drivetrain->Drive(0, 0); | ||
|
||
} | ||
|
||
void TankStop::Execute(){ | ||
|
||
m_drivetrain->Drive(0, 0); | ||
periods++; | ||
|
||
} | ||
|
||
bool TankStop::IsFinished(){ | ||
|
||
return (periods >= period_target); | ||
|
||
} | ||
|
||
void TankStop::End(bool){ | ||
|
||
m_drivetrain->Drive(0, 0); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#pragma once | ||
|
||
#include <frc2/command/CommandBase.h> | ||
#include <frc2/command/CommandHelper.h> | ||
|
||
#include "subsystems/Drivetrain.h" | ||
|
||
/** | ||
* Drive the given distance straight (negative values go backwards). | ||
* Uses a local PID controller to run a simple PID loop that is only | ||
* enabled while this command is running. The input is the averaged | ||
* values of the left and right encoders. | ||
*/ | ||
class TankMoveGyro: public frc2::CommandHelper<frc2::CommandBase, TankMoveGyro> { | ||
|
||
public: | ||
|
||
TankMoveGyro(Drivetrain& drivetrain, double distance, double speed); | ||
void Initialize() override; | ||
void Execute() override; | ||
bool IsFinished() override; | ||
void End(bool interrupted) override; | ||
|
||
private: | ||
|
||
Drivetrain* m_drivetrain; | ||
double m_distance; | ||
double m_speed; | ||
double distanceCounter; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#pragma once | ||
|
||
#include <frc2/command/CommandBase.h> | ||
#include <frc2/command/CommandHelper.h> | ||
|
||
#include "subsystems/Drivetrain.h" | ||
|
||
|
||
class TankStop: public frc2::CommandHelper<frc2::CommandBase, TankStop> { | ||
|
||
public: | ||
|
||
TankStop(Drivetrain& drivetrain, double duration); | ||
|
||
void Initialize() override; | ||
void Execute() override; | ||
bool IsFinished() override; | ||
void End(bool interrupted) override; | ||
|
||
private: | ||
|
||
Drivetrain* m_drivetrain; | ||
double m_duration; | ||
|
||
int period_target; | ||
int periods; | ||
|
||
}; |
Oops, something went wrong.