From 9cb4e7e7b614d2accd7c5911197152de5ee3bd45 Mon Sep 17 00:00:00 2001 From: anidev Date: Wed, 23 Apr 2014 13:09:17 -0500 Subject: [PATCH] Added commented code for pot angle in case we ever use it --- Shooter.cpp | 32 ++++++++++++++++++++------------ Shooter.h | 3 +++ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/Shooter.cpp b/Shooter.cpp index e956540..d62354b 100644 --- a/Shooter.cpp +++ b/Shooter.cpp @@ -29,6 +29,7 @@ Shooter::Shooter(main_robot* r,uint8_t axisCan, wormGear = new CANJaguar(wormCan); puncher = new DoubleSolenoid(punchMod,punchFChan,punchRChan); bobTheAccelerometer = new ADXL345_I2C_612(bobMod); +// bobThePot = new AnalogChannel(1,5); isPickingUp = false; shooterJoy = robot -> gunnerJoy; shooterJoy -> addJoyFunctions(&buttonHelper,(void*)this,CLAMP); @@ -223,6 +224,24 @@ void Shooter::buttonHelper(void* objPtr, uint32_t button) } } +double Shooter::getAngle() { + double bobX = bobTheAccelerometer->GetAcceleration(ADXL345_I2C_612::kAxis_X); + double bobY = bobTheAccelerometer->GetAcceleration(ADXL345_I2C_612::kAxis_Y); + double bobZ = bobTheAccelerometer->GetAcceleration(ADXL345_I2C_612::kAxis_Z); + accelWorking = !(doubleEqual(bobX,0.0) && doubleEqual(bobY,0.0) && doubleEqual(bobZ,0.0)); + if(!accelWorking) + { + isPitchingUp = false; + isPitchingDown = false; + } + double newPitch = (atan2(bobX, sqrt(bobY*bobY + bobZ*bobZ))*180.0)/PI; + // if(fabs(newPitch-currentPitch) < 10) + currentPitch = newPitch; +/* double volts = bobThePot->GetVoltage(); + currentPitch = bobThePot; // TODO get pot conversion */ + return currentPitch; +} + /* * * The following code is a shortcut of sorts for Ben so that he can press one button to do a bunch of stuff @@ -246,18 +265,7 @@ void Shooter::setPickupHelper(void* instName, uint32_t button) { void Shooter::update() { - double bobX = bobTheAccelerometer->GetAcceleration(ADXL345_I2C_612::kAxis_X); - double bobY = bobTheAccelerometer->GetAcceleration(ADXL345_I2C_612::kAxis_Y); - double bobZ = bobTheAccelerometer->GetAcceleration(ADXL345_I2C_612::kAxis_Z); - accelWorking = !(doubleEqual(bobX,0.0) && doubleEqual(bobY,0.0) && doubleEqual(bobZ,0.0)); - if(!accelWorking) - { - isPitchingUp = false; - isPitchingDown = false; - } - double newPitch = (atan2(bobX, sqrt(bobY*bobY + bobZ*bobZ))*180.0)/PI; -// if(fabs(newPitch-currentPitch) < 10) - currentPitch = newPitch; + getAngle(); static int output = 0; if(output%20 == 0) diff --git a/Shooter.h b/Shooter.h index afe6d31..8627971 100644 --- a/Shooter.h +++ b/Shooter.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "ADXL345_I2C_612.h" #include #include "controls.h" @@ -43,6 +44,7 @@ class Shooter void punch(); void smartFire(); bool doubleEqual(double a,double b); + double getAngle(); void setPickup(); static void setPickupHelper(void*, uint32_t); @@ -54,6 +56,7 @@ class Shooter CANJaguar* wormGear; DoubleSolenoid* puncher; ADXL345_I2C_612* bobTheAccelerometer; +// AnalogChannel* bobThePot; main_robot* robot; bool isPickingUp;