This repository has been archived on 2020-09-21. You can view files and clone it, but cannot push or open issues or pull requests.
FRC2016/src/Shooter.h
2016-02-20 18:32:40 -05:00

196 lines
3.3 KiB
C++

/*
* Shooter.h
*
* Created on: Feb 2, 2016
* Author: Jason
*/
#ifndef SRC_SHOOTER_H_
#define SRC_SHOOTER_H_
#define PICKUP_POWER 0.75
#define LAUNCH_POWER 1
#define SPINUP_TIME 1.5 // seconds.
#define LAUNCH_TIME 0.5
class Shooter
{
public:
/**
* Shooter talons and launch-spinny talon.
* s2 is also for the pickup-mechanism and can be controlled independently.
*
*/
enum ShooterState
{
READY,
ON_FIRE,
SPINNINGUP,
LAUNCH,
LAUNCHING,
RESETTING
};
Shooter(CANTalon *s1, CANTalon *s2, CANTalon *r)
{
// shooterDrive = new RobotDrive(s1, s2);
launcher = s1;
pickup = s2;
ramp = r;
ready = true;
state = READY;
}
/**
* Call this method on TeleopInit so that the ramp is properly
* set at the beginning of the match.
*/
virtual ~Shooter()
{
delete launcher;
delete pickup;
delete ramp;
}
void StopShooter()
{
ready = true;
ramp->Set(0);
launcher->Set(0);
pickup->Set(0);
}
void LowerRamp()
{
ramp->Set(-0.5);
if(ramp->Limits::kReverseLimit){
SmartDashboard::PutNumber("ramp", 2); //going to put a circlar dial to show where the ramp could be
} else {
SmartDashboard::PutNumber("ramp", 1);
}
}
void RaiseRamp()
{
ramp->Set(0.5);
if(ramp->Limits::kForwardLimit){
SmartDashboard::PutNumber("ramp", 0); //going to put a circlar dial to show where the ramp could be
} else {
SmartDashboard::PutNumber("ramp", 1);
}
}
void StopRamp()
{
ramp->Set(0);
}
void Shoot()
{
// TODO: Shooter Logic should go as follows:
/*
Assuming a ball is held in the shooter. When the trigger is pulled,
the launch-spinny should be STOPPED. Start a Timer object counting
When... too hard to write.. I emailed you a flow chart.
*/
switch (state)
{
case READY:
{
state = SPINNINGUP;
ramp->Set(-1);
launcher->Set(PICKUP_POWER);
pickup->Set(PICKUP_POWER);
shotClock.Reset();
shotClock.Start();
break;
}
case SPINNINGUP:
{
if (shotClock.Get() > SPINUP_TIME)
{
state = LAUNCH;
shotClock.Reset();
shotClock.Start();
} else
{
std::cout << "*Goku noises*\n";
}
break;
}
case LAUNCH:
{
ramp->Set(1);
state = LAUNCHING;
break;
}
case LAUNCHING:
{
if (shotClock.Get() > LAUNCH_TIME)
{
state = RESETTING;
}
break;
}
case RESETTING:
{
ramp->Set(0);
launcher->Set(0);
pickup->Set(0);
state = READY;
break;
}
case ON_FIRE:
{
std::cout << "Something is wrong with the launch sequence.\n";
break;
}
}
}
void PickUp(bool state = true)
{
pickup->Set((float) (state * PICKUP_POWER));
launcher->Set((float) (state * PICKUP_POWER * -0.75));
//ramp->Set(-1.0*PICKUP_POWER);
//std::cout << "picking up!\n";
}
/**
* Call this to run the pickup backwards if the ball gets jammed somehow...
*/
void Unjam()
{
pickup->Set(PICKUP_POWER * -0.75);
}
void ShootLow()
{
pickup->Set(-1);
}
void SetPower(float power)
{
pickup->Set(power);
launcher->Set(power);
//std::cout << "setting shooter power" << std::endl;
}
private:
//RobotDrive *shooterDrive;
CANTalon *launcher;
CANTalon *pickup;
CANTalon *ramp;
ShooterState state;
Timer shotClock;
bool ready;
int fake_position;
};
#endif /* SRC_SHOOTER_H_ */