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

Added support for different shooting powers

This commit is contained in:
Adam Long 2014-05-25 14:41:10 -04:00
parent a57bee27b2
commit 4d4b3d07b1
7 changed files with 46 additions and 8 deletions

View File

@ -6,7 +6,15 @@ JoystickController::JoystickController()
leftJoystick = new Joystick(JOYSTICK_LEFT);
}
//void JoystickController::getRightJoystick(JoystickController *controller)
void JoystickController::updateJoysticks()
{
getRightJoystick();
getLeftJoystick();
getRightJoystickAxis();
getLeftJoystickAxis();
throttle = (-leftJoystickAxisValues[4]+1)/2;
}
void JoystickController::getRightJoystick()
{
for(int i=1; i<13; i++)
@ -22,3 +30,19 @@ void JoystickController::getLeftJoystick()
leftJoystickValues[i] = leftJoystick->GetRawButton(i);
}
}
void JoystickController::getRightJoystickAxis()
{
for(int i=1; i<7; i++)
{
rightJoystickAxisValues[i] = rightJoystick->GetRawAxis(i);
}
}
void JoystickController::getLeftJoystickAxis()
{
for(int i=1; i<7; i++)
{
leftJoystickAxisValues[i] = leftJoystick->GetRawAxis(i);
}
}

View File

@ -8,7 +8,13 @@ class JoystickController
public:
int leftJoystickValues[];
int rightJoystickValues[];
float leftJoystickAxisValues[];
float rightJoystickAxisValues[];
float throttle;
JoystickController();
void updateJoysticks();
void getRightJoystick();
void getLeftJoystick();
void getLeftJoystickAxis();
void getRightJoystickAxis();
};

View File

@ -11,10 +11,11 @@ ZaphodShooter::ZaphodShooter()
e_ShooterState = IDLE_PRESHOT;
}
void ZaphodShooter::startShootingSequence()
void ZaphodShooter::startShootingSequence(float throttle)
{
//Changes the enum to tell the shooter to be firing
e_ShooterState = FIRING;
shootingPower = throttle;
}
//First step in shooting process
@ -75,7 +76,7 @@ void ZaphodShooter::updateShooterPosition()
if(e_ShooterState == FIRING)
{
isShooting = true;
shootForAngle(1,110);
shootForAngle(shootingPower,110);
}
if(e_ShooterState == IDLE_POSTSHOT)
{

View File

@ -16,7 +16,8 @@ class ZaphodShooter
IDLE_POSTSHOT
}e_ShooterState;
bool isShooting;
void startShootingSequence();
float shootingPower;
void startShootingSequence(float);
void shootForAngle(float, float);
void shootRaw(float);
void lower(float);

View File

@ -1,4 +1,3 @@
#ifndef __ZAPHOD_BASE_H__
#define __ZAPHOD_BASE_H__

View File

@ -57,20 +57,26 @@ float ZaphodRobot::getRearSonar()
return (rearSonarRightV+rearSonarLeftV)/2;
}
void driveRobot(float x, float y)
{
}
//Main function used to handle periodic tasks on the robot
void ZaphodRobot::handler()
{
//Periodic tasks that should be run by every loop
ControlSystem->getRightJoystick();
ControlSystem->getLeftJoystick();
ControlSystem->updateJoysticks();
shooter->updateShooterPosition();
//TODO Need to implement a timing system to not break the spike (this function doesn't run the compressor at the moment)
compressorSystem->compressorSystemPeriodic();
collector->updateCollector(shooter->isShooting, shooter->getAngle());
//Button assignments to actions
if(ControlSystem->leftJoystickValues[SHOOTER_FIRE])
{
//TODO Needs a power input
shooter->startShootingSequence();
shooter->startShootingSequence(ControlSystem->throttle);
}
if(ControlSystem->rightJoystickValues[COLLECTOR_INTAKE])
{

View File

@ -26,6 +26,7 @@ class ZaphodRobot
float frontSonarLeftV, frontSonarRightV, rearSonarLeftV, rearSonarRightV;
float getFrontSonar();
float getRearSonar();
void driveRobot(float,float);
void handler();
};
#endif