2
0
mirror of https://github.com/team2059/Dent synced 2025-01-07 22:14:14 -05:00

Added BinIn, BinOut commands, BinCollector subsystem for collecting bins, mapped left button 3 and 4 to move BinCollector elevator. Works 100%

This commit is contained in:
Austen Adler 2015-04-06 20:36:35 -04:00
parent 6fd89b1a84
commit fb51f39da7
11 changed files with 209 additions and 4 deletions

View File

@ -0,0 +1,26 @@
#include "BinIn.h"
#include "../../DentRobot.h"
#include "../../OI.h"
BinIn::BinIn(float timeout): Command("BinIn"){
SetTimeout(timeout);
}
void BinIn::Initialize(){
}
void BinIn::Execute(){
DentRobot::binCollector->Set(0.75);
End();
}
bool BinIn::IsFinished(){
if(IsTimedOut()){
printf("Robot stoped collecting bin.\n");
return true;
}else{
return false;
}
}
void BinIn::End(){
}
void BinIn::Interrupted(){
End();
}
// vim: ts=2:sw=2:et

View File

@ -0,0 +1,42 @@
#ifndef BinIn_H
#define BinIn_H
#include "Commands/Command.h"
#include "WPILib.h"
/**
* @brief Lowers the bin collector until a timeout is reached
*/
class BinIn: public Command{
public:
/**
* @brief Constructs BinIn
*
* @param timeout Timeout in seconds
*/
BinIn(float timeout);
/**
* @brief Initializes the class
*/
void Initialize();
/**
* @brief Lowers the bin collector at -1.0 power
*/
void Execute();
/**
* @brief Checks if the command is finished
*
* @return True only if the timeout was reached
*/
bool IsFinished();
/**
* @brief Sets the bin collector to stop
*/
void End();
/**
* @brief Calls End()
*/
void Interrupted();
};
#endif
// vim: ts=2:sw=2:et

View File

@ -0,0 +1,26 @@
#include "BinOut.h"
#include "../../DentRobot.h"
#include "../../OI.h"
BinOut::BinOut(double timeout): Command("BinOut"){
SetTimeout(timeout);
}
void BinOut::Initialize(){
}
void BinOut::Execute(){
DentRobot::binCollector->Set(0.1);
End();
}
bool BinOut::IsFinished(){
if(IsTimedOut()){
printf("Robot stoped ejecting bin.\n");
return true;
}else{
return false;
}
}
void BinOut::End(){
}
void BinOut::Interrupted(){
End();
}
// vim: ts=2:sw=2:et

View File

@ -0,0 +1,42 @@
#ifndef BinOut_H
#define BinOut_H
#include "Commands/Command.h"
#include "WPILib.h"
/**
* @brief Raises the bin collector until a timeout is reached
*/
class BinOut: public Command{
public:
/**
* @brief Constructs BinOut
*
* @param timeout Timeout in seconds
*/
BinOut(double timeout);
/**
* @brief Initializes the class
*/
void Initialize();
/**
* @brief Raises the bin colector at 1.0 power
*/
void Execute();
/**
* @brief Checks if the command is finished
*
* @return True only if the timeout was reached
*/
bool IsFinished();
/**
* @brief Sets the bin colector to stop
*/
void End();
/**
* @brief Calls End()
*/
void Interrupted();
};
#endif
// vim: ts=2:sw=2:et

View File

@ -9,6 +9,7 @@ Elevator* DentRobot::elevator = NULL;
BinElevator* DentRobot::binElevator = NULL; BinElevator* DentRobot::binElevator = NULL;
CommandGroup* DentRobot::aut = NULL; CommandGroup* DentRobot::aut = NULL;
Pneumatics* DentRobot::pneumatics = NULL; Pneumatics* DentRobot::pneumatics = NULL;
BinCollector* DentRobot::binCollector = NULL;
DentRobot::DentRobot(){ DentRobot::DentRobot(){
oi = new OI(); oi = new OI();
collector = new Collector(); collector = new Collector();
@ -16,6 +17,7 @@ DentRobot::DentRobot(){
elevator = new Elevator(); elevator = new Elevator();
binElevator = new BinElevator(); binElevator = new BinElevator();
pneumatics = new Pneumatics(); pneumatics = new Pneumatics();
binCollector = new BinCollector();
//CameraServer::GetInstance()->SetQuality(25); //CameraServer::GetInstance()->SetQuality(25);
//CameraServer::GetInstance()->StartAutomaticCapture("cam0"); //CameraServer::GetInstance()->StartAutomaticCapture("cam0");
printf("The robot is on\n"); printf("The robot is on\n");

View File

@ -7,6 +7,7 @@
#include "Subsystems/Drivetrain.h" #include "Subsystems/Drivetrain.h"
#include "Subsystems/Collector.h" #include "Subsystems/Collector.h"
#include "Subsystems/Pneumatics.h" #include "Subsystems/Pneumatics.h"
#include "Subsystems/BinCollector.h"
#include "Commands/Autonomous/Autonomous.h" #include "Commands/Autonomous/Autonomous.h"
/** /**
* @brief The Hitchhikers 2015 robot, Dent * @brief The Hitchhikers 2015 robot, Dent
@ -48,6 +49,10 @@ class DentRobot: public IterativeRobot{
* @brief The Pneumatics system (unused) * @brief The Pneumatics system (unused)
*/ */
static Pneumatics* pneumatics; static Pneumatics* pneumatics;
/**
* @brief The BinCollector for collecting bins
*/
static BinCollector* binCollector;
/** /**
* @brief The Autonomous command * @brief The Autonomous command
*/ */

12
OI.cpp
View File

@ -9,6 +9,8 @@
#include "Commands/BinElevator/BinRaise.h" #include "Commands/BinElevator/BinRaise.h"
#include "Commands/BinElevator/BinCloseArms.h" #include "Commands/BinElevator/BinCloseArms.h"
#include "Commands/BinElevator/BinOpenArms.h" #include "Commands/BinElevator/BinOpenArms.h"
#include "Commands/BinCollector/BinIn.h"
#include "Commands/BinCollector/BinOut.h"
#include "Commands/Autonomous/CollectTote.h" #include "Commands/Autonomous/CollectTote.h"
#include "Commands/Autonomous/ReleaseTote.h" #include "Commands/Autonomous/ReleaseTote.h"
OI::OI(){ OI::OI(){
@ -47,16 +49,18 @@ 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);
//right7->WhenPressed(new BinOpenArms());
//right8->WhenPressed(new BinCloseArms());
binRaise = new BinRaise(3.0); binRaise = new BinRaise(3.0);
binLower = new BinLower(2.0); binLower = new BinLower(2.0);
right3->WhileHeld(binLower); right3->WhileHeld(binLower);
right3->CancelWhenPressed(binRaise); right3->CancelWhenPressed(binRaise);
right5->WhileHeld(binRaise); right5->WhileHeld(binRaise);
right5->CancelWhenPressed(binLower); right5->CancelWhenPressed(binLower);
// BinCollector
JoystickButton *left3 = new JoystickButton(leftStick, 3);
JoystickButton *left4 = new JoystickButton(leftStick, 4);
left3->WhileHeld(new BinIn(2.0));
left4->WhileHeld(new BinOut(2.0));
} }
Joystick* OI::GetRightStick(){ Joystick* OI::GetRightStick(){
return rightStick; return rightStick;

View File

@ -37,5 +37,8 @@
#define COLLECTOR_RIGHT_CAN 9 #define COLLECTOR_RIGHT_CAN 9
#define COLLECTOR_SONAR_ANALOG 3 #define COLLECTOR_SONAR_ANALOG 3
// BinCollector
#define BINCOLLECTOR 0
#endif #endif
// vim: ts=2:sw=2:et // vim: ts=2:sw=2:et

View File

@ -0,0 +1,16 @@
#include "BinCollector.h"
#include "../RobotMap.h"
BinCollector::BinCollector(): Subsystem("BinCollector"){
binCollectorMotor = new Servo(BINCOLLECTOR);
}
void BinCollector::InitDefaultCommand(){
}
void BinCollector::Set(double pos){
binCollectorMotor->Set(pos);
printf("BinCollector angle: %f\n", pos);
}
double BinCollector::Get(){
return binCollectorMotor->Get();
}
// vim: ts=2:sw=2:et

36
Subsystems/BinCollector.h Normal file
View File

@ -0,0 +1,36 @@
#ifndef BinCollector_H
#define BinCollector_H
#include "WPILib.h"
/**
* @brief Collects bins
*
* Collects bins with a servo
*/
class BinCollector: public Subsystem{
private:
Servo *binCollectorMotor; //<! BinCollector motor
public:
/**
* @brief Constructs BinCollector
*/
BinCollector();
/**
* @brief No action
*/
void InitDefaultCommand();
/**
* @brief Sets the servo angle
*
* @param pos The angle of the servo (0.0 to 1.0)
*/
void Set(double pos);
/**
* @brief Gets the servo angle
*
* @return The servo angle (0.0 to 1.0)
*/
double Get();
};
#endif
// vim: ts=2:sw=2:et

View File

@ -5,6 +5,7 @@
* @section Subsystems * @section Subsystems
* -# @ref Drivetrain * -# @ref Drivetrain
* -# @ref BinElevator * -# @ref BinElevator
* -# @ref BinCollector
* -# @ref Elevator * -# @ref Elevator
* -# @ref Collector * -# @ref Collector
* -# @ref Pneumatics (unused) * -# @ref Pneumatics (unused)
@ -15,6 +16,8 @@
* -# @ref BinLower * -# @ref BinLower
* -# @ref BinOpenArms * -# @ref BinOpenArms
* -# @ref BinRaise * -# @ref BinRaise
* -# @ref BinIn
* -# @ref BinOut
* -# @ref RollIn * -# @ref RollIn
* -# @ref RollOut * -# @ref RollOut
* -# @ref Drive * -# @ref Drive