mirror of
https://github.com/team2059/Dent
synced 2025-01-07 22:14:14 -05:00
Made auto more modular
This commit is contained in:
parent
d515a11cd6
commit
d9c010aed8
@ -1,27 +1,17 @@
|
|||||||
#include "AutoDrive.h"
|
#include "AutoDrive.h"
|
||||||
#include "../../DentRobot.h"
|
#include "../../DentRobot.h"
|
||||||
// Drive for a short while then stop. Just for testing
|
// Drive for a short while then stop. Just for testing
|
||||||
AutoDrive::AutoDrive(double wait) : Command("AutoDrive"){
|
AutoDrive::AutoDrive(double duration, double p=-0.75) : Command("AutoDrive"){
|
||||||
Requires(DentRobot::drivetrain);
|
Requires(DentRobot::drivetrain);
|
||||||
SetTimeout(wait);
|
SetTimeout(duration);
|
||||||
power=5;
|
|
||||||
}
|
|
||||||
AutoDrive::AutoDrive(double wait, double p) : Command("AutoDrive"){
|
|
||||||
Requires(DentRobot::drivetrain);
|
|
||||||
SetTimeout(wait);
|
|
||||||
power=p;
|
power=p;
|
||||||
}
|
}
|
||||||
void AutoDrive::Initialize(){
|
void AutoDrive::Initialize(){
|
||||||
}
|
}
|
||||||
void AutoDrive::Execute(){
|
void AutoDrive::Execute(){
|
||||||
//X axis, Y axis, Z axis, sensitivity, speed threshold (usually throttle), gyro
|
//X axis, Y axis, Z axis, sensitivity, speed threshold (usually throttle), gyro
|
||||||
//if(power==NULL){
|
|
||||||
if(power==5){
|
|
||||||
DentRobot::drivetrain->DriveMecanum(0.0,-.75,0.0,0.9,0.0);
|
|
||||||
}else{
|
|
||||||
DentRobot::drivetrain->DriveMecanum(0.0,power,0.0,0.9,0.0);
|
DentRobot::drivetrain->DriveMecanum(0.0,power,0.0,0.9,0.0);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
bool AutoDrive::IsFinished(){
|
bool AutoDrive::IsFinished(){
|
||||||
return IsTimedOut();
|
return IsTimedOut();
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ Autonomous::Autonomous(int seq){
|
|||||||
case 0:
|
case 0:
|
||||||
// Just for testing
|
// Just for testing
|
||||||
AddSequential(new CollectTote());
|
AddSequential(new CollectTote());
|
||||||
AddSequential(new Turn());
|
AddSequential(new Turn(90));
|
||||||
//AddSequential(new Raise());
|
//AddSequential(new Raise());
|
||||||
//AddSequential(new Lower());
|
//AddSequential(new Lower());
|
||||||
//AddSequential(new Turn());
|
//AddSequential(new Turn());
|
||||||
@ -23,21 +23,18 @@ Autonomous::Autonomous(int seq){
|
|||||||
case 1:
|
case 1:
|
||||||
// Drive forward a bit, turn around, collect tote then bin
|
// Drive forward a bit, turn around, collect tote then bin
|
||||||
AddSequential(new AutoDrive(0.5));
|
AddSequential(new AutoDrive(0.5));
|
||||||
AddSequential(new Turn());
|
AddSequential(new Turn(180));
|
||||||
AddSequential(new Turn());
|
AddSequential(new RollIn(1.0));
|
||||||
AddSequential(new RollIn());
|
|
||||||
AddSequential(new Raise());
|
AddSequential(new Raise());
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
// Drive forward a bit, turn around, collect tote then bin
|
// Drive forward a bit, turn around, collect tote then bin
|
||||||
AddParallel(new Raise());
|
AddParallel(new Raise());
|
||||||
AddParallel(new AutoDrive(0.5));
|
AddParallel(new AutoDrive(0.5));
|
||||||
AddSequential(new Turn());
|
AddSequential(new Turn(180));
|
||||||
AddSequential(new Turn());
|
AddSequential(new RollIn(1.0));
|
||||||
AddSequential(new RollIn());
|
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
// Wait a desigated value, drive to Auto Zone (TM)
|
|
||||||
//Wait(SmartDashboard::GetNumber("Auto Wait Time"));
|
//Wait(SmartDashboard::GetNumber("Auto Wait Time"));
|
||||||
AddSequential(new AutoDrive(2.0));
|
AddSequential(new AutoDrive(2.0));
|
||||||
break;
|
break;
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
#include "Turn.h"
|
#include "Turn.h"
|
||||||
#include "../../DentRobot.h"
|
#include "../../DentRobot.h"
|
||||||
// Drive for a short while then stop. Just for testing
|
// Drive for a short while then stop. Just for testing
|
||||||
Turn::Turn() : Command("Turn"){
|
Turn::Turn(int k) : Command("Turn"){
|
||||||
Requires(DentRobot::drivetrain);
|
Requires(DentRobot::drivetrain);
|
||||||
|
degrees=k;
|
||||||
SetTimeout(0.85);
|
SetTimeout(0.85);
|
||||||
}
|
}
|
||||||
void Turn::Initialize(){
|
void Turn::Initialize(){
|
||||||
|
@ -7,8 +7,10 @@
|
|||||||
#include "WPILib.h"
|
#include "WPILib.h"
|
||||||
|
|
||||||
class Turn: public Command{
|
class Turn: public Command{
|
||||||
|
private:
|
||||||
|
int degrees;
|
||||||
public:
|
public:
|
||||||
Turn();
|
Turn(int);
|
||||||
void Initialize();
|
void Initialize();
|
||||||
void Execute();
|
void Execute();
|
||||||
bool IsFinished();
|
bool IsFinished();
|
||||||
|
@ -4,6 +4,6 @@
|
|||||||
#include "RollIn.h"
|
#include "RollIn.h"
|
||||||
CollectTote::CollectTote(){
|
CollectTote::CollectTote(){
|
||||||
AddParallel(new AutoDrive(1.0, -0.75));
|
AddParallel(new AutoDrive(1.0, -0.75));
|
||||||
AddSequential(new RollIn());
|
AddSequential(new RollIn(1.0));
|
||||||
}
|
}
|
||||||
// vim: ts=2:sw=2:et
|
// vim: ts=2:sw=2:et
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
#include "RollIn.h"
|
#include "RollIn.h"
|
||||||
RollIn::RollIn() : Command("RollIn"){
|
RollIn::RollIn(double k) : Command("RollIn"){
|
||||||
|
rawSpeed=k;
|
||||||
}
|
}
|
||||||
void RollIn::Initialize(){
|
void RollIn::Initialize(){
|
||||||
printf("Initialized RollIn\n");
|
printf("Initialized RollIn\n");
|
||||||
SetTimeout(2.0);
|
SetTimeout(2.0);
|
||||||
}
|
}
|
||||||
void RollIn::Execute(){
|
void RollIn::Execute(){
|
||||||
double throttle=DentRobot::oi->GetLeftThrottle();
|
double cvt=(rawSpeed)*DentRobot::collector->GetSonarDistance()/0.4;
|
||||||
double cvt=throttle*DentRobot::collector->GetSonarDistance()/0.4;
|
|
||||||
if(cvt>=1.0){
|
if(cvt>=1.0){
|
||||||
DentRobot::collector->MoveRollers(1.0);
|
DentRobot::collector->MoveRollers(1.0);
|
||||||
}else{
|
}else{
|
||||||
|
@ -7,8 +7,10 @@
|
|||||||
#include "WPILib.h"
|
#include "WPILib.h"
|
||||||
|
|
||||||
class RollIn: public Command{
|
class RollIn: public Command{
|
||||||
|
private:
|
||||||
|
double rawSpeed;
|
||||||
public:
|
public:
|
||||||
RollIn();
|
RollIn(double);
|
||||||
void Initialize();
|
void Initialize();
|
||||||
void Execute();
|
void Execute();
|
||||||
bool IsFinished();
|
bool IsFinished();
|
||||||
|
8
OI.cpp
8
OI.cpp
@ -5,6 +5,8 @@
|
|||||||
#include "Commands/Collector/RollOut.h"
|
#include "Commands/Collector/RollOut.h"
|
||||||
#include "Commands/BinElevator/BinLower.h"
|
#include "Commands/BinElevator/BinLower.h"
|
||||||
#include "Commands/BinElevator/BinRaise.h"
|
#include "Commands/BinElevator/BinRaise.h"
|
||||||
|
#include "Commands/BinElevator/BinCloseArms.h"
|
||||||
|
#include "Commands/BinElevator/BinOpenArms.h"
|
||||||
|
|
||||||
OI::OI() {
|
OI::OI() {
|
||||||
// Joysticks
|
// Joysticks
|
||||||
@ -13,7 +15,7 @@ OI::OI() {
|
|||||||
// Collector
|
// Collector
|
||||||
JoystickButton *left1=new JoystickButton(leftStick, 1);
|
JoystickButton *left1=new JoystickButton(leftStick, 1);
|
||||||
JoystickButton *left2=new JoystickButton(leftStick, 2);
|
JoystickButton *left2=new JoystickButton(leftStick, 2);
|
||||||
left1->WhileHeld(new RollIn());
|
left1->WhileHeld(new RollIn(GetLeftThrottle()));
|
||||||
left2->WhileHeld(new RollOut());
|
left2->WhileHeld(new RollOut());
|
||||||
// Elevator
|
// Elevator
|
||||||
raise=new Raise();
|
raise=new Raise();
|
||||||
@ -27,12 +29,16 @@ OI::OI() {
|
|||||||
// BinElevator
|
// BinElevator
|
||||||
JoystickButton *right3=new JoystickButton(rightStick, 3);
|
JoystickButton *right3=new JoystickButton(rightStick, 3);
|
||||||
JoystickButton *right5=new JoystickButton(rightStick, 5);
|
JoystickButton *right5=new JoystickButton(rightStick, 5);
|
||||||
|
JoystickButton *right7=new JoystickButton(rightStick, 7);
|
||||||
|
JoystickButton *right8=new JoystickButton(rightStick, 8);
|
||||||
binRaise=new BinRaise();
|
binRaise=new BinRaise();
|
||||||
binLower=new BinLower();
|
binLower=new BinLower();
|
||||||
right3->WhenPressed(binLower);
|
right3->WhenPressed(binLower);
|
||||||
right3->CancelWhenPressed(binRaise);
|
right3->CancelWhenPressed(binRaise);
|
||||||
right5->WhenPressed(binRaise);
|
right5->WhenPressed(binRaise);
|
||||||
right5->CancelWhenPressed(binLower);
|
right5->CancelWhenPressed(binLower);
|
||||||
|
right7->WhenPressed(new BinOpenArms());
|
||||||
|
right8->WhenPressed(new BinCloseArms());
|
||||||
// Cancel
|
// Cancel
|
||||||
JoystickButton *right12=new JoystickButton(rightStick, 12);
|
JoystickButton *right12=new JoystickButton(rightStick, 12);
|
||||||
right12->CancelWhenPressed(raise);
|
right12->CancelWhenPressed(raise);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user