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:
parent
6fd89b1a84
commit
fb51f39da7
26
Commands/BinCollector/BinIn.cpp
Normal file
26
Commands/BinCollector/BinIn.cpp
Normal 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
|
42
Commands/BinCollector/BinIn.h
Normal file
42
Commands/BinCollector/BinIn.h
Normal 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
|
26
Commands/BinCollector/BinOut.cpp
Normal file
26
Commands/BinCollector/BinOut.cpp
Normal 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
|
42
Commands/BinCollector/BinOut.h
Normal file
42
Commands/BinCollector/BinOut.h
Normal 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
|
@ -9,6 +9,7 @@ Elevator* DentRobot::elevator = NULL;
|
||||
BinElevator* DentRobot::binElevator = NULL;
|
||||
CommandGroup* DentRobot::aut = NULL;
|
||||
Pneumatics* DentRobot::pneumatics = NULL;
|
||||
BinCollector* DentRobot::binCollector = NULL;
|
||||
DentRobot::DentRobot(){
|
||||
oi = new OI();
|
||||
collector = new Collector();
|
||||
@ -16,6 +17,7 @@ DentRobot::DentRobot(){
|
||||
elevator = new Elevator();
|
||||
binElevator = new BinElevator();
|
||||
pneumatics = new Pneumatics();
|
||||
binCollector = new BinCollector();
|
||||
//CameraServer::GetInstance()->SetQuality(25);
|
||||
//CameraServer::GetInstance()->StartAutomaticCapture("cam0");
|
||||
printf("The robot is on\n");
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "Subsystems/Drivetrain.h"
|
||||
#include "Subsystems/Collector.h"
|
||||
#include "Subsystems/Pneumatics.h"
|
||||
#include "Subsystems/BinCollector.h"
|
||||
#include "Commands/Autonomous/Autonomous.h"
|
||||
/**
|
||||
* @brief The Hitchhikers 2015 robot, Dent
|
||||
@ -48,6 +49,10 @@ class DentRobot: public IterativeRobot{
|
||||
* @brief The Pneumatics system (unused)
|
||||
*/
|
||||
static Pneumatics* pneumatics;
|
||||
/**
|
||||
* @brief The BinCollector for collecting bins
|
||||
*/
|
||||
static BinCollector* binCollector;
|
||||
/**
|
||||
* @brief The Autonomous command
|
||||
*/
|
||||
|
12
OI.cpp
12
OI.cpp
@ -9,6 +9,8 @@
|
||||
#include "Commands/BinElevator/BinRaise.h"
|
||||
#include "Commands/BinElevator/BinCloseArms.h"
|
||||
#include "Commands/BinElevator/BinOpenArms.h"
|
||||
#include "Commands/BinCollector/BinIn.h"
|
||||
#include "Commands/BinCollector/BinOut.h"
|
||||
#include "Commands/Autonomous/CollectTote.h"
|
||||
#include "Commands/Autonomous/ReleaseTote.h"
|
||||
OI::OI(){
|
||||
@ -47,16 +49,18 @@ OI::OI(){
|
||||
// BinElevator
|
||||
JoystickButton *right3 = new JoystickButton(rightStick, 3);
|
||||
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);
|
||||
binLower = new BinLower(2.0);
|
||||
right3->WhileHeld(binLower);
|
||||
right3->CancelWhenPressed(binRaise);
|
||||
right5->WhileHeld(binRaise);
|
||||
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(){
|
||||
return rightStick;
|
||||
|
@ -37,5 +37,8 @@
|
||||
#define COLLECTOR_RIGHT_CAN 9
|
||||
#define COLLECTOR_SONAR_ANALOG 3
|
||||
|
||||
// BinCollector
|
||||
#define BINCOLLECTOR 0
|
||||
|
||||
#endif
|
||||
// vim: ts=2:sw=2:et
|
||||
|
16
Subsystems/BinCollector.cpp
Normal file
16
Subsystems/BinCollector.cpp
Normal 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
36
Subsystems/BinCollector.h
Normal 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
|
@ -5,6 +5,7 @@
|
||||
* @section Subsystems
|
||||
* -# @ref Drivetrain
|
||||
* -# @ref BinElevator
|
||||
* -# @ref BinCollector
|
||||
* -# @ref Elevator
|
||||
* -# @ref Collector
|
||||
* -# @ref Pneumatics (unused)
|
||||
@ -15,6 +16,8 @@
|
||||
* -# @ref BinLower
|
||||
* -# @ref BinOpenArms
|
||||
* -# @ref BinRaise
|
||||
* -# @ref BinIn
|
||||
* -# @ref BinOut
|
||||
* -# @ref RollIn
|
||||
* -# @ref RollOut
|
||||
* -# @ref Drive
|
||||
|
Loading…
x
Reference in New Issue
Block a user