Ravens Robotics FRC 2015
Robot.cpp
Go to the documentation of this file.
1 
10 #include "WPILib.h"
11 #include <RobotComponent.h>
12 #include <Camera.h>
13 #include <MecanumDrive.h>
14 
18 class Robot: public IterativeRobot
19 {
20 //private:
23 
24  Encoder encoder;
25  Ultrasonic Sonic;
26  DigitalInput bottomSwitch;
27  DigitalInput topSwitch;
28  DigitalInput frontSwitch;
29  LiveWindow *lw;
31 
32 public:
38  Robot() :
39  encoder(4, 5, true),
40  Sonic(2,3, Ultrasonic::kMilliMeters),
41  bottomSwitch(0),
42  topSwitch(1),
43  frontSwitch(6),
44  lw(NULL),
45  autoLoopCounter(0)
46  {
47  }
48 
49 private:
53  void RobotInit()
54  {
55  lw = LiveWindow::GetInstance();
56  m_Camera.ComponentInit();
57  m_Drive.ComponentInit();
58  }
59 
63  void DisabledInit()
64  {
65  }
66 
71  {
72  }
73 
74 
79  {
80  autoLoopCounter = 0;
81  }
82 
94  {
95  if(autoLoopCounter < 100) //Check if we've completed 100 loops (approximately 2 seconds)
96  {
97 
98  autoLoopCounter++;
99  } else {
100 
101  }
102  }
103 
107  void TeleopInit()
108  {
109  }
110 
115  {
116  if (IsEnabled())
117  {
118  /*
119  * Sense() block for all RobotComponents
120  */
121  m_Camera.Sense();
122  m_Drive.Sense();
123 
124  /*
125  * DoWork() block for all RobotComponents
126  */
127  m_Camera.DoWork();
128  m_Drive.DoWork();
129 
130  /***** Old-fashioned code follows *****/
131 
132  //Encoder stuff
133  SmartDashboard::PutNumber("Motor Count", double ((encoder.Get()/71.164)/7));
134 
135  //Front Limit Switch
136  if(frontSwitch.Get() == 1)
137  {
138  SmartDashboard::PutString("Front Switch", "Activated");
139  }else
140  {
141  SmartDashboard::PutString("Front Switch", "_________");
142  }
143 
144  //Bottom Switch
145  if(bottomSwitch.Get() == 1)
146  {
147  SmartDashboard::PutString("Bottom Switch", "Activated");
148  }else
149  {
150  SmartDashboard::PutString("Bottom Switch", "_________");
151  }
152 
153  //Top Switch
154  if(topSwitch.Get() == 1)
155  {
156  SmartDashboard::PutString("Top Switch", "Activated");
157  }else
158  {
159  SmartDashboard::PutString("Top Switch", "_________");
160  }
161 
162  //Ultrasonic Code
163  Sonic.SetAutomaticMode(true);
164  Sonic.SetEnabled(true);
165  //Gets distance in mm, then changes into cm
166  double myDistance = (Sonic.GetRangeMM()/10);
167  //Outputs to SmartDashboard
168  SmartDashboard::PutNumber("Ultrasonic Measurement", myDistance);
169  }
170  else //Do when disabled
171  {
172  //Resets encoder when robot is disabled
173  if (encoder.Get() != 0){
174  encoder.Reset();
175  }
176  //Turns off ultrasonic when disabled, it would keep runing otherwise
177  Sonic.SetAutomaticMode(false);
178  }
179  }
180 
184  void TestInit()
185  {
186  }
187 
192  {
193  lw->Run(); // This method is called periodically to cause the sensors to send new values to the SmartDashboard.
194  }
195 };
196 
197 
void TeleopPeriodic()
Definition: Robot.cpp:114
void TestPeriodic()
Definition: Robot.cpp:191
void AutonomousInit()
Definition: Robot.cpp:78
void TestInit()
Definition: Robot.cpp:184
DigitalInput frontSwitch
Definition: Robot.cpp:28
DigitalInput topSwitch
Definition: Robot.cpp:27
Definition: Camera.h:29
Definition: Robot.cpp:18
Camera m_Camera
Camera RobotComponent.
Definition: Robot.cpp:21
void AutonomousPeriodic()
Definition: Robot.cpp:93
LiveWindow * lw
Definition: Robot.cpp:29
void DisabledPeriodic()
Definition: Robot.cpp:70
Encoder encoder
Definition: Robot.cpp:24
Header file for MecanumDrive component.
START_ROBOT_CLASS(Robot)
virtual void ComponentInit()
Definition: Camera.cpp:30
virtual void DoWork()
Definition: Camera.cpp:57
Header file for Robot Component base class.
virtual void ComponentInit()
MecanumDrive m_Drive
MecanumDrive RobotComponent.
Definition: Robot.cpp:22
Robot()
Definition: Robot.cpp:38
virtual void Sense()
void RobotInit()
Definition: Robot.cpp:53
DigitalInput bottomSwitch
Definition: Robot.cpp:26
virtual void Sense()
Definition: Camera.cpp:44
Header file for Camera component.
Ultrasonic Sonic
Definition: Robot.cpp:25
virtual void DoWork()
void TeleopInit()
Definition: Robot.cpp:107
int autoLoopCounter
Definition: Robot.cpp:30
void DisabledInit()
Definition: Robot.cpp:63