2
0
mirror of https://github.com/team2059/Zaphod synced 2024-12-18 20:12:28 -05:00

Made the controller more versitile (and actually work)

This commit is contained in:
Adam Long 2014-11-20 23:55:29 +00:00
parent 64e5a3a6b1
commit c31dfcf26d
3 changed files with 36 additions and 35 deletions

View File

@ -15,8 +15,8 @@ HHRobot::HHRobot():
left1 = new Talon(DRIVE_LEFT_MOTOR_ONE, DRIVE_LEFT_SIDECAR); left1 = new Talon(DRIVE_LEFT_MOTOR_ONE, DRIVE_LEFT_SIDECAR);
left2 = new Talon(DRIVE_LEFT_MOTOR_TWO, DRIVE_LEFT_SIDECAR); left2 = new Talon(DRIVE_LEFT_MOTOR_TWO, DRIVE_LEFT_SIDECAR);
left3 = new Talon(DRIVE_LEFT_MOTOR_THREE, DRIVE_LEFT_SIDECAR); left3 = new Talon(DRIVE_LEFT_MOTOR_THREE, DRIVE_LEFT_SIDECAR);
rightStick = new Joystick(JOYSTICK_RIGHT); rightStick = new Joystick(3);
leftStick = new Joystick(JOYSTICK_LEFT); leftStick = new Joystick(4);
} }
void HHRobot::Init(){ void HHRobot::Init(){
@ -40,9 +40,8 @@ void HHRobot::DriveRobot(float x,float y){
}else if(y!=0.0f&&y<-1.0f){ }else if(y!=0.0f&&y<-1.0f){
y=-1.0f; y=-1.0f;
} }
float leftPower=((y+x)/2+1)*127+1; //float leftPower=((y+x)/2+1)*127+1;
float rightPower=((y-x)/2+1)*127+1; //float rightPower=((y-x)/2+1)*127+1;
printf("Driving and stuff\n");
//printf("Left: %f\n", leftPower); //printf("Left: %f\n", leftPower);
//printf("Right: %f\n", rightPower); //printf("Right: %f\n", rightPower);
//right1->SetRaw(int(rightPower)); //right1->SetRaw(int(rightPower));
@ -51,6 +50,7 @@ void HHRobot::DriveRobot(float x,float y){
//left1->SetRaw(int(leftPower)); //left1->SetRaw(int(leftPower));
//left2->SetRaw(int(leftPower)); //left2->SetRaw(int(leftPower));
//left3->SetRaw(int(leftPower)); //left3->SetRaw(int(leftPower));
printf("Driving and stuff\n");
printf("Left: %f\n",y+x); printf("Left: %f\n",y+x);
printf("Right: %f\n",y-x); printf("Right: %f\n",y-x);
right1->Set(y+x); right1->Set(y+x);
@ -102,16 +102,17 @@ void HHRobot::Handler(){
//TODO Need to implement a timing system to not break the spike (this function doesn't run the compressor at the moment) //TODO Need to implement a timing system to not break the spike (this function doesn't run the compressor at the moment)
compressorSystem->CompressorSystemPeriodic(allowCompressing); compressorSystem->CompressorSystemPeriodic(allowCompressing);
collector->UpdateCollector(shooter->isShooting,shooter->GetAngle()); collector->UpdateCollector(shooter->isShooting,shooter->GetAngle());
DriveRobot(rightStick->GetRawAxis(1),rightStick->GetRawAxis(2)); //TODO Fix whatever the heck is wrong with this
//DriveRobot(rightStick->GetRawAxis(1),rightStick->GetRawAxis(2));
UpdateDashboard(); UpdateDashboard();
//Shooting button //Shooting button
if(ControlSystem->leftJoystickValues[SHOOTER_FIRE]) { if(ControlSystem->leftJoystickValues[SHOOTER_FIRE]) {
shooter->StartShootingSequence(ControlSystem->throttle); shooter->StartShootingSequence(ControlSystem->throttle);
} }
//Collector button assignments //Collector button assignments
if(rightStick->GetRawButton(COLLECTOR_INTAKE)) { if(ControlSystem->GetJoystickButton(2,COLLECTOR_INTAKE)) {
collector->CollectBall(); collector->CollectBall();
}else if(rightStick->GetRawButton(COLLECTOR_OUTTAKE)) { }else if(ControlSystem->GetJoystickButton(2,COLLECTOR_OUTTAKE)) {
collector->ReleaseBall(); collector->ReleaseBall();
}else{ }else{
collector->CollectorStop(); collector->CollectorStop();

View File

@ -1,33 +1,35 @@
#include "Controller.h" #include "Controller.h"
JoystickController::JoystickController(){ JoystickController::JoystickController(){
rightJoystick=new Joystick(3); driveJoystick=new Joystick(JOYSTICK_RIGHT);
leftJoystick=new Joystick(4); shootJoystick=new Joystick(JOYSTICK_LEFT);
} }
void JoystickController::UpdateJoysticks(){ void JoystickController::UpdateJoysticks(){
GetRightJoystick();
GetLeftJoystick();
GetRightJoystickAxis();
GetLeftJoystickAxis();
throttle=(-leftJoystickAxisValues[4]+1)/2; throttle=(-leftJoystickAxisValues[4]+1)/2;
} }
void JoystickController::GetRightJoystick(){ int JoystickController::GetJoystickButton(int joystick, int button){
for(int i=1;i<13;i++){ switch (joystick){
rightJoystickValues[i]=rightJoystick->GetRawButton(i); case 1:
return driveJoystick->GetRawButton(button);
break;
case 2:
return shootJoystick->GetRawButton(button);
break;
default:
return -1;
break;
} }
} }
void JoystickController::GetLeftJoystick(){ float JoystickController::GetJoystickAxis(int joystick, int axis){
for(int i=1;i<13;i++){ switch (joystick){
leftJoystickValues[i]=leftJoystick->GetRawButton(i); case 1:
} return driveJoystick->GetRawAxis(axis);
} break;
void JoystickController::GetRightJoystickAxis(){ case 2:
for(int i=1;i<7;i++){ return shootJoystick->GetRawAxis(axis);
rightJoystickAxisValues[i]=rightJoystick->GetRawAxis(i); break;
} default:
} return 999;
void JoystickController::GetLeftJoystickAxis(){ break;
for(int i=1;i<7;i++){
leftJoystickAxisValues[i]=leftJoystick->GetRawAxis(i);
} }
} }
// vim: ts=2:sw=2:et // vim: ts=2:sw=2:et

View File

@ -3,7 +3,7 @@
class JoystickController class JoystickController
{ {
private: private:
Joystick *rightJoystick, *leftJoystick; Joystick *driveJoystick, *shootJoystick;
public: public:
int leftJoystickValues[]; int leftJoystickValues[];
int rightJoystickValues[]; int rightJoystickValues[];
@ -12,9 +12,7 @@ class JoystickController
float throttle; float throttle;
JoystickController(); JoystickController();
void UpdateJoysticks(); void UpdateJoysticks();
void GetRightJoystick(); int GetJoystickButton(int,int);
void GetLeftJoystick(); float GetJoystickAxis(int,int);
void GetLeftJoystickAxis();
void GetRightJoystickAxis();
}; };
// vim: ts=2:sw=2:et // vim: ts=2:sw=2:et