DeepSpace  2019
Slider.cpp
Go to the documentation of this file.
1 #include "Subsystems/Slider.h"
2 #include <iostream>
3 
4 Slider::Slider() : frc::Subsystem("Slider") {
5  // Initialize the motors
6  this->pSliderMotor = new can::WPI_TalonSRX(SLIDER_MOTOR);
7  this->pSliderMotor->SetInverted(false);
8  this->pSliderMotor->SetSafetyEnabled(false);
9 
10  this->pLeftHall = new frc::DigitalInput(3);
11  this->pRightHall = new frc::DigitalInput(0);
12  this->pCenterHall = new frc::DigitalInput(8);
13 
14  /*
15  * If sliderSide is 1 it is on the left side.
16  * If sliderSide is -1 it is on the right side.
17  */
18  this->sliderSide = 0;
19 
20  this->ntTelemetry = NetworkTable::GetTable("SmartDashboard/Telemetry/Slider");
21 }
22 
24  SetDefaultCommand(new ControlSlider());
25 }
26 
27 void Slider::Slide(double speed) {
28  // Make sure the slider is not doing anything bad
29  if(speed < 0 && this->pLeftHall->Get()==0) {
30  this->pSliderMotor->Set(0);
31  }else if(speed > 0 && this->pRightHall->Get()==0) {
32  this->pSliderMotor->Set(0);
33  }else{
34  this->pSliderMotor->Set(speed);
35  }
36 //std::cout << this->pCenterHall->Get() << std::endl;
37  if(speed > 0 && this->pCenterHall->Get()==0) {
38  this->sliderSide = 1;
39  }
40 
41  if (speed < 0 && this->pCenterHall->Get()==0) {
42  this->sliderSide = -1;
43  }
44 
45  // Report slider data to NetworkTables
46  this->ntTelemetry->PutBoolean("centre", !this->pCenterHall->Get()); // is centred
47  this->ntTelemetry->PutBoolean("left", this->sliderSide == -1); // is left
48  this->ntTelemetry->PutBoolean("right", this->sliderSide == 1); // is right
49 
50  return;
51 }
52 
54  // If the Hall effect is not tripped off, the slider will move to the center
55  if(this->pCenterHall->Get()==1) {
56  //If the slider are on the right it will move to the left otherwise it will continue right
57  if(this->sliderSide==1) {
58  this->pSliderMotor->Set(-1);
59  } else {
60  this->pSliderMotor->Set(1);
61  }
62  } else {
63  this->pSliderMotor->Set(0);
64  }
65 
66  return;
67 }
frc::DigitalInput * pLeftHall
Definition: Slider.h:29
std::shared_ptr< NetworkTable > ntTelemetry
A pointer to the /SmartDashboard/Telemetry table.
Definition: Slider.h:32
Slider()
Class constructor.
Definition: Slider.cpp:4
void Center()
Definition: Slider.cpp:53
frc::DigitalInput * pRightHall
Definition: Slider.h:30
void InitDefaultCommand() override
Initalizes the default command for this subsystem (ControlSlider)
Definition: Slider.cpp:23
frc::DigitalInput * pCenterHall
Definition: Slider.h:31
void Slide(double speed)
Definition: Slider.cpp:27
double sliderSide
Definition: Slider.h:27
can::WPI_TalonSRX * pSliderMotor
Pointer for the slider motor.
Definition: Slider.h:28
An interface command for driving the robot with an xbox controller.
Definition: ControlSlider.h:12
#define SLIDER_MOTOR
Definition: RobotMap.h:84