2
0
mirror of https://github.com/team2059/Dent synced 2024-12-18 20:52:29 -05:00

Fixed sensor readings and added sonar

This commit is contained in:
Adam Long 2015-02-15 12:53:19 +00:00
parent 7665f16a9b
commit 9490b8fb9b
10 changed files with 32 additions and 7 deletions

View File

@ -10,7 +10,7 @@ void BinLower::Execute(){
DentRobot::binElevator->Run(-1.0); DentRobot::binElevator->Run(-1.0);
} }
bool BinLower::IsFinished(){ bool BinLower::IsFinished(){
if (!DentRobot::binElevator->GetElevatorBottom()||IsTimedOut()){ if (/*!DentRobot::binElevator->GetElevatorBottom()||*/IsTimedOut()){
printf("Robot stoped BinLowering. Sensor based? %d\n", !DentRobot::binElevator->GetElevatorBottom()); printf("Robot stoped BinLowering. Sensor based? %d\n", !DentRobot::binElevator->GetElevatorBottom());
return true; return true;
}else{ }else{

View File

@ -10,7 +10,7 @@ void BinRaise::Execute(){
DentRobot::binElevator->Run(1.0); DentRobot::binElevator->Run(1.0);
} }
bool BinRaise::IsFinished(){ bool BinRaise::IsFinished(){
if (!DentRobot::binElevator->GetElevatorTop()||IsTimedOut()){ if (/*!DentRobot::binElevator->GetElevatorTop()||*/IsTimedOut()){
printf("Robot stoped raising. Sensor based? %d\n", !DentRobot::binElevator->GetElevatorTop()); printf("Robot stoped raising. Sensor based? %d\n", !DentRobot::binElevator->GetElevatorTop());
return true; return true;
}else{ }else{

View File

@ -7,7 +7,7 @@ void RollIn::Initialize(){
} }
void RollIn::Execute(){ void RollIn::Execute(){
//TODO check this value to move the motors in the right direction //TODO check this value to move the motors in the right direction
DentRobot::collector->MoveRollers(-(-DentRobot::oi->GetLeftStick()->GetRawAxis(3)+1.0)/2); DentRobot::collector->MoveRollers((-DentRobot::oi->GetLeftStick()->GetRawAxis(3)+1.0)/2);
} }
bool RollIn::IsFinished(){ bool RollIn::IsFinished(){
return IsTimedOut(); return IsTimedOut();

View File

@ -8,7 +8,7 @@ void RollOut::Initialize(){
void RollOut::Execute(){ void RollOut::Execute(){
//TODO check this value to move the motors in the right direction //TODO check this value to move the motors in the right direction
// Devide by 2 twice because this speed should be half the collector speed // Devide by 2 twice because this speed should be half the collector speed
DentRobot::collector->MoveRollers((-DentRobot::oi->GetLeftStick()->GetRawAxis(3)+1.0)/2/2); DentRobot::collector->MoveRollers(-(-DentRobot::oi->GetLeftStick()->GetRawAxis(3)+1.0)/2);
} }
bool RollOut::IsFinished(){ bool RollOut::IsFinished(){
return IsTimedOut(); return IsTimedOut();

View File

@ -10,8 +10,15 @@ void Raise::Execute(){
DentRobot::elevator->Run(1.0); DentRobot::elevator->Run(1.0);
} }
bool Raise::IsFinished(){ bool Raise::IsFinished(){
if (!DentRobot::elevator->GetElevatorTop()||IsTimedOut()){ if(!DentRobot::elevator->GetElevatorMiddle()){
printf("Robot stoped raising. Sensor based? %d\n", !DentRobot::elevator->GetElevatorTop()); DentRobot::elevator->stoppedAtSensor=true;
}
if ((DentRobot::elevator->stoppedAtSensor)){
printf("Stopped at the middle sensor\n");
DentRobot::elevator->stoppedAtSensor=false;
return true;
}else if (!DentRobot::elevator->GetElevatorTop()) {
printf("Stopping at the top sensor\n");
return true; return true;
}else{ }else{
return false; return false;

View File

@ -30,6 +30,8 @@
#define COLLECTOR_LEFT_CAN 8 #define COLLECTOR_LEFT_CAN 8
#define COLLECTOR_BOTTOM_CAN 10 #define COLLECTOR_BOTTOM_CAN 10
#define COLLECTOR_RIGHT_CAN 9 #define COLLECTOR_RIGHT_CAN 9
#define COLLECTOR_SONAR_DIO 6
#define COLLECTOR_SONAR_ANALOG 3
#endif #endif
// vim: ts=2:sw=2:et // vim: ts=2:sw=2:et

View File

@ -6,6 +6,8 @@ Collector::Collector() : Subsystem("Collector"){
collectorMotorBottom=new CANTalon(COLLECTOR_BOTTOM_CAN); collectorMotorBottom=new CANTalon(COLLECTOR_BOTTOM_CAN);
collectorMotorRamp=new CANTalon(COLLECTOR_RAMP_CAN); collectorMotorRamp=new CANTalon(COLLECTOR_RAMP_CAN);
collectorMotorRight=new CANTalon(COLLECTOR_RIGHT_CAN); collectorMotorRight=new CANTalon(COLLECTOR_RIGHT_CAN);
sonarAnalog=new AnalogInput(COLLECTOR_SONAR_ANALOG);
sonarDigital=new DigitalOutput(COLLECTOR_RIGHT_CAN);
} }
void Collector::InitDefaultCommand(){ void Collector::InitDefaultCommand(){
} }
@ -14,5 +16,9 @@ void Collector::MoveRollers(double a){
collectorMotorBottom->Set(a); collectorMotorBottom->Set(a);
collectorMotorRamp->Set(a); collectorMotorRamp->Set(a);
collectorMotorRight->Set(-a); collectorMotorRight->Set(-a);
GetSonarDistance();
}
float Collector::GetSonarDistance(){
printf("Sonar Distance %f\n",sonarAnalog->GetAverageValue());
} }
// vim: ts=2:sw=2:et // vim: ts=2:sw=2:et

View File

@ -6,10 +6,13 @@ class Collector: public Subsystem
{ {
private: private:
CANTalon *collectorMotorLeft, *collectorMotorBottom, *collectorMotorRamp, *collectorMotorRight; CANTalon *collectorMotorLeft, *collectorMotorBottom, *collectorMotorRamp, *collectorMotorRight;
AnalogInput *sonarAnalog;
DigitalOutput *sonarDigital;
public: public:
Collector(); Collector();
void InitDefaultCommand(); void InitDefaultCommand();
void MoveRollers(double); void MoveRollers(double);
float GetSonarDistance();
}; };
#endif #endif
// vim: ts=2:sw=2:et // vim: ts=2:sw=2:et

View File

@ -4,9 +4,11 @@ Elevator::Elevator(){
motor=new CANTalon(ELEVATOR_CAN); motor=new CANTalon(ELEVATOR_CAN);
elevatorEncoder=new Encoder(ELEVATOR_ENCODERA,ELEVATOR_ENCODERB,false); elevatorEncoder=new Encoder(ELEVATOR_ENCODERA,ELEVATOR_ENCODERB,false);
elevatorBottom=new DigitalInput(ELEVATOR_BOTTOM_DIO); elevatorBottom=new DigitalInput(ELEVATOR_BOTTOM_DIO);
elevatorMiddle=new DigitalInput(ELEVATOR_MIDDLE_DIO);
elevatorTop=new DigitalInput(ELEVATOR_TOP_DIO); elevatorTop=new DigitalInput(ELEVATOR_TOP_DIO);
// Checks if the elevator is drifting // Checks if the elevator is drifting
useEncoder=false; useEncoder=false;
stoppedAtSensor=false;
} }
void Elevator::InitDefaultCommand(){ void Elevator::InitDefaultCommand(){
} }
@ -26,6 +28,9 @@ double Elevator::GetHeight(){
bool Elevator::GetElevatorBottom(){ bool Elevator::GetElevatorBottom(){
return elevatorBottom->Get(); return elevatorBottom->Get();
} }
bool Elevator::GetElevatorMiddle(){
return elevatorMiddle->Get();
}
bool Elevator::GetElevatorTop(){ bool Elevator::GetElevatorTop(){
return elevatorTop->Get(); return elevatorTop->Get();
} }

View File

@ -8,15 +8,17 @@ class Elevator{
CANTalon *motor; CANTalon *motor;
Encoder *elevatorEncoder; Encoder *elevatorEncoder;
static constexpr double kP_real=4, kI_real=.0f, kP_simulation=18, kI_simulation=.2; static constexpr double kP_real=4, kI_real=.0f, kP_simulation=18, kI_simulation=.2;
DigitalInput *elevatorBottom, *elevatorTop; DigitalInput *elevatorBottom, *elevatorMiddle, *elevatorTop;
bool useEncoder; bool useEncoder;
public: public:
Elevator(); Elevator();
bool stoppedAtSensor;
void InitDefaultCommand(); void InitDefaultCommand();
void Run(double); void Run(double);
void ResetEncoder(); void ResetEncoder();
double GetHeight(); double GetHeight();
bool GetElevatorTop(); bool GetElevatorTop();
bool GetElevatorMiddle();
bool GetElevatorBottom(); bool GetElevatorBottom();
void SetUseEncoder(bool); void SetUseEncoder(bool);
bool GetUseEncoder(); bool GetUseEncoder();