Create methods for lidar to work
[3501/stronghold-2016] / src / org / usfirst / frc / team3501 / robot / Robot.java
CommitLineData
38a404b3
KZ
1package org.usfirst.frc.team3501.robot;
2
53d61b3e 3import org.usfirst.frc.team3501.robot.Constants.Defense;
047383c3 4import org.usfirst.frc.team3501.robot.subsystems.DriveTrain;
02cb494e 5import org.usfirst.frc.team3501.robot.subsystems.Scaler;
40348cab
E
6import org.usfirst.frc.team3501.robot.subsystems.Shooter;
7
dd71da2a 8import edu.wpi.first.wpilibj.I2C;
38a404b3
KZ
9import edu.wpi.first.wpilibj.IterativeRobot;
10import edu.wpi.first.wpilibj.command.Scheduler;
3366a59a
ME
11import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
12import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
38a404b3
KZ
13
14public class Robot extends IterativeRobot {
15 public static OI oi;
16 public static DriveTrain driveTrain;
40348cab 17 public static Shooter shooter;
02cb494e 18 public static Scaler scaler;
38a404b3 19
88e66b4e 20 // Sendable Choosers send a drop down menu to the Smart Dashboard.
3366a59a 21 SendableChooser positionChooser;
6947c8a4
ME
22 SendableChooser positionOneDefense, positionTwoDefense, positionThreeDefense,
23 positionFourDefense, positionFiveDefense;
3366a59a 24
dd71da2a
E
25 public static Lidar lidar;
26
38a404b3
KZ
27 @Override
28 public void robotInit() {
29 driveTrain = new DriveTrain();
30 oi = new OI();
40348cab 31 shooter = new Shooter();
02cb494e 32 scaler = new Scaler();
dd71da2a 33 lidar = new Lidar(I2C.Port.kOnboard);
3366a59a 34
88e66b4e
ME
35 // Sendable Choosers allows the driver to select the position of the robot
36 // and the positions of the defenses from a drop-down menu on the Smart
37 // Dashboard
29d59f48
ME
38 // make the Sendable Choosers
39 initializeSendableChoosers();
40 addPositionChooserOptions();
41 addDefensesToAllDefenseSendableChooosers();
42 sendSendableChoosersToSmartDashboard();
43
3366a59a
ME
44 }
45
6947c8a4
ME
46 private void initializeSendableChoosers() {
47 positionChooser = new SendableChooser();
48 positionOneDefense = new SendableChooser();
49 positionTwoDefense = new SendableChooser();
50 positionThreeDefense = new SendableChooser();
51 positionFourDefense = new SendableChooser();
52 positionFiveDefense = new SendableChooser();
53 }
54
29d59f48
ME
55 private void addPositionChooserOptions() {
56 positionChooser.addDefault("Position 1", 1);
57 positionChooser.addObject("Position 2", 2);
58 positionChooser.addObject("Position 3", 3);
59 positionChooser.addObject("Position 4", 4);
60 positionChooser.addObject("Position 5", 5);
61 }
62
63 private void addDefensesToAllDefenseSendableChooosers() {
64 addDefenseOptions(positionOneDefense);
65 addDefenseOptions(positionTwoDefense);
66 addDefenseOptions(positionThreeDefense);
67 addDefenseOptions(positionFourDefense);
68 addDefenseOptions(positionFiveDefense);
69 }
70
71 private void addDefenseOptions(SendableChooser chooser) {
3366a59a
ME
72 chooser.addDefault("Portcullis", Defense.PORTCULLIS);
73 chooser.addObject("Sally Port", Defense.SALLY_PORT);
74 chooser.addObject("Rough Terrain", Defense.ROUGH_TERRAIN);
75 chooser.addObject("Low Bar", Defense.LOW_BAR);
76 chooser.addObject("Cheval De Frise", Defense.CHEVAL_DE_FRISE);
77 chooser.addObject("Drawbridge", Defense.DRAWBRIDGE);
78 chooser.addObject("Moat", Defense.MOAT);
79 chooser.addObject("Rock Wall", Defense.ROCK_WALL);
38a404b3
KZ
80 }
81
29d59f48
ME
82 private void sendSendableChoosersToSmartDashboard() {
83 SmartDashboard.putData("PositionChooser", positionChooser);
84 SmartDashboard.putData("Position One Defense Chooser", positionOneDefense);
85 SmartDashboard.putData("Position Two Defense Chooser", positionTwoDefense);
86 SmartDashboard.putData("Position Three Defense Chooser",
87 positionThreeDefense);
88 SmartDashboard.putData("Position Four Defense Chooser",
89 positionFourDefense);
90 SmartDashboard.putData("Position Five Defense Chooser",
91 positionFiveDefense);
92 }
93
38a404b3
KZ
94 @Override
95 public void autonomousInit() {
3366a59a
ME
96 Scheduler.getInstance().run();
97
98 // get options chosen from drop down menu
99 Integer chosenPosition = (Integer) positionChooser.getSelected();
e13d2293 100 Integer chosenDefense = 0;
3366a59a 101
33981335
ME
102 switch (chosenPosition) {
103 case 1:
3366a59a 104 chosenDefense = (Integer) positionOneDefense.getSelected();
33981335 105 case 2:
3366a59a 106 chosenDefense = (Integer) positionTwoDefense.getSelected();
33981335 107 case 3:
3366a59a 108 chosenDefense = (Integer) positionThreeDefense.getSelected();
33981335 109 case 4:
3366a59a 110 chosenDefense = (Integer) positionFourDefense.getSelected();
33981335 111 case 5:
3366a59a 112 chosenDefense = (Integer) positionFiveDefense.getSelected();
33981335 113 }
3366a59a
ME
114
115 System.out.println("Chosen Position: " + chosenPosition);
116 System.out.println("Chosen Defense: " + chosenDefense);
38a404b3
KZ
117 }
118
119 @Override
120 public void autonomousPeriodic() {
121 Scheduler.getInstance().run();
38a404b3
KZ
122 }
123
124 @Override
125 public void teleopInit() {
dd71da2a 126 lidar.start();
38a404b3
KZ
127 }
128
129 @Override
130 public void teleopPeriodic() {
dd71da2a 131 printLidarValues();
38a404b3
KZ
132 Scheduler.getInstance().run();
133
134 }
dd71da2a
E
135
136 public void printLidarValues() {
137
138 System.out.println(lidar.pidGet());
139 }
38a404b3 140}