2016-02-09 16:23:45 -05:00
|
|
|
/*
|
|
|
|
* Shooter.h
|
|
|
|
*
|
|
|
|
* Created on: Feb 2, 2016
|
|
|
|
* Author: Jason
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SRC_SHOOTER_H_
|
|
|
|
#define SRC_SHOOTER_H_
|
|
|
|
|
2016-02-20 18:15:28 -05:00
|
|
|
#define PICKUP_POWER 0.75
|
2016-02-13 16:40:07 -05:00
|
|
|
#define LAUNCH_POWER 1
|
2016-02-11 22:26:11 -05:00
|
|
|
#define SPINUP_TIME 1.5 // seconds.
|
2016-02-13 16:40:07 -05:00
|
|
|
#define LAUNCH_TIME 0.5
|
2016-02-09 16:23:45 -05:00
|
|
|
|
2016-02-11 21:24:32 -05:00
|
|
|
class Shooter
|
|
|
|
{
|
2016-02-09 16:23:45 -05:00
|
|
|
public:
|
2016-02-11 21:24:32 -05:00
|
|
|
|
2016-02-09 16:23:45 -05:00
|
|
|
/**
|
2016-02-11 16:51:13 -05:00
|
|
|
* Shooter talons and launch-spinny talon.
|
2016-02-09 16:23:45 -05:00
|
|
|
* s2 is also for the pickup-mechanism and can be controlled independently.
|
|
|
|
*
|
|
|
|
*/
|
2016-02-13 16:40:07 -05:00
|
|
|
enum ShooterState
|
|
|
|
{
|
|
|
|
READY,
|
|
|
|
ON_FIRE,
|
|
|
|
SPINNINGUP,
|
|
|
|
LAUNCH,
|
|
|
|
LAUNCHING,
|
|
|
|
RESETTING
|
|
|
|
};
|
|
|
|
|
|
|
|
Shooter(CANTalon *s1, CANTalon *s2, CANTalon *r)
|
2016-02-11 21:24:32 -05:00
|
|
|
{
|
2016-02-10 15:23:07 -05:00
|
|
|
// shooterDrive = new RobotDrive(s1, s2);
|
|
|
|
launcher = s1;
|
2016-02-09 16:23:45 -05:00
|
|
|
pickup = s2;
|
2016-02-20 15:14:51 -05:00
|
|
|
ramp = r;
|
2016-02-11 21:24:32 -05:00
|
|
|
ready = true;
|
2016-02-13 16:40:07 -05:00
|
|
|
state = READY;
|
2016-02-09 16:23:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Call this method on TeleopInit so that the ramp is properly
|
|
|
|
* set at the beginning of the match.
|
|
|
|
*/
|
|
|
|
|
2016-02-11 21:24:32 -05:00
|
|
|
virtual ~Shooter()
|
|
|
|
{
|
2016-02-10 15:23:07 -05:00
|
|
|
delete launcher;
|
2016-02-09 16:23:45 -05:00
|
|
|
delete pickup;
|
2016-02-20 15:14:51 -05:00
|
|
|
delete ramp;
|
2016-02-09 16:23:45 -05:00
|
|
|
}
|
2016-02-11 21:24:32 -05:00
|
|
|
|
|
|
|
void StopShooter()
|
|
|
|
{
|
|
|
|
ready = true;
|
2016-02-20 15:14:51 -05:00
|
|
|
ramp->Set(0);
|
2016-02-12 19:37:36 -05:00
|
|
|
launcher->Set(0);
|
|
|
|
pickup->Set(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LowerRamp()
|
|
|
|
{
|
2016-02-20 17:01:51 -05:00
|
|
|
ramp->Set(-0.5);
|
|
|
|
if(ramp->Limits::kReverseLimit){
|
2016-02-20 14:27:43 -05:00
|
|
|
SmartDashboard::PutNumber("ramp", 2); //going to put a circlar dial to show where the ramp could be
|
|
|
|
} else {
|
|
|
|
SmartDashboard::PutNumber("ramp", 1);
|
|
|
|
}
|
2016-02-12 19:37:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void RaiseRamp()
|
|
|
|
{
|
2016-02-20 17:01:51 -05:00
|
|
|
ramp->Set(0.5);
|
|
|
|
if(ramp->Limits::kForwardLimit){
|
2016-02-20 14:27:43 -05:00
|
|
|
SmartDashboard::PutNumber("ramp", 0); //going to put a circlar dial to show where the ramp could be
|
|
|
|
} else {
|
|
|
|
SmartDashboard::PutNumber("ramp", 1);
|
|
|
|
}
|
2016-02-13 11:12:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void StopRamp()
|
|
|
|
{
|
2016-02-20 15:14:51 -05:00
|
|
|
ramp->Set(0);
|
2016-02-12 19:37:36 -05:00
|
|
|
}
|
2016-02-11 21:24:32 -05:00
|
|
|
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.
|
|
|
|
*/
|
2016-02-13 16:40:07 -05:00
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case READY:
|
|
|
|
{
|
|
|
|
state = SPINNINGUP;
|
2016-02-20 15:14:51 -05:00
|
|
|
ramp->Set(-1);
|
2016-02-13 16:40:07 -05:00
|
|
|
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:
|
|
|
|
{
|
2016-02-20 15:14:51 -05:00
|
|
|
ramp->Set(1);
|
2016-02-13 16:40:07 -05:00
|
|
|
state = LAUNCHING;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LAUNCHING:
|
|
|
|
{
|
|
|
|
if (shotClock.Get() > LAUNCH_TIME)
|
|
|
|
{
|
|
|
|
|
|
|
|
state = RESETTING;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2016-02-15 15:14:20 -05:00
|
|
|
case RESETTING:
|
|
|
|
{
|
2016-02-20 17:01:51 -05:00
|
|
|
ramp->Set(0);
|
2016-02-15 15:14:20 -05:00
|
|
|
launcher->Set(0);
|
|
|
|
pickup->Set(0);
|
|
|
|
state = READY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ON_FIRE:
|
|
|
|
{
|
|
|
|
std::cout << "Something is wrong with the launch sequence.\n";
|
|
|
|
break;
|
|
|
|
}
|
2016-02-13 16:40:07 -05:00
|
|
|
}
|
2016-02-11 21:24:32 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void PickUp(bool state = true)
|
|
|
|
{
|
2016-02-09 16:23:45 -05:00
|
|
|
pickup->Set((float) (state * PICKUP_POWER));
|
2016-02-20 18:15:28 -05:00
|
|
|
launcher->Set((float) (state * PICKUP_POWER * -0.75));
|
2016-02-20 15:14:51 -05:00
|
|
|
//ramp->Set(-1.0*PICKUP_POWER);
|
2016-02-13 12:09:08 -05:00
|
|
|
//std::cout << "picking up!\n";
|
2016-02-09 16:23:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Call this to run the pickup backwards if the ball gets jammed somehow...
|
|
|
|
*/
|
|
|
|
void Unjam()
|
|
|
|
{
|
2016-02-20 18:32:40 -05:00
|
|
|
pickup->Set(PICKUP_POWER * -0.75);
|
2016-02-09 16:23:45 -05:00
|
|
|
}
|
|
|
|
|
2016-02-20 18:15:28 -05:00
|
|
|
void ShootLow()
|
|
|
|
{
|
|
|
|
pickup->Set(-1);
|
|
|
|
}
|
|
|
|
|
2016-02-11 21:24:32 -05:00
|
|
|
void SetPower(float power)
|
|
|
|
{
|
2016-02-10 15:23:07 -05:00
|
|
|
pickup->Set(power);
|
|
|
|
launcher->Set(power);
|
2016-02-13 12:09:08 -05:00
|
|
|
//std::cout << "setting shooter power" << std::endl;
|
2016-02-09 16:23:45 -05:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
|
2016-02-11 21:24:32 -05:00
|
|
|
//RobotDrive *shooterDrive;
|
2016-02-10 15:23:07 -05:00
|
|
|
CANTalon *launcher;
|
2016-02-09 16:23:45 -05:00
|
|
|
CANTalon *pickup;
|
2016-02-20 15:14:51 -05:00
|
|
|
CANTalon *ramp;
|
2016-02-13 16:40:07 -05:00
|
|
|
ShooterState state;
|
2016-02-11 21:24:32 -05:00
|
|
|
|
2016-02-11 22:26:11 -05:00
|
|
|
Timer shotClock;
|
2016-02-11 21:24:32 -05:00
|
|
|
bool ready;
|
2016-02-20 14:27:43 -05:00
|
|
|
int fake_position;
|
2016-02-09 16:23:45 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* SRC_SHOOTER_H_ */
|