Completed
Push — master ( 0672dd...74c8db )
by John
33s
created

org.usfirst.frc.team3695.robot.Robot.robotInit()   B

Complexity

Conditions 4

Size

Total Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 40
rs 8.92
cc 4
1
2
package org.usfirst.frc.team3695.robot;
3
4
import edu.wpi.first.wpilibj.DriverStation;
5
import edu.wpi.first.wpilibj.I2C;
6
import edu.wpi.first.wpilibj.IterativeRobot;
7
import edu.wpi.first.wpilibj.command.Scheduler;
8
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
9
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
10
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
11
12
import org.usfirst.frc.team3695.robot.auto.CommandGroupAuto;
13
import org.usfirst.frc.team3695.robot.enumeration.Autonomous;
14
import org.usfirst.frc.team3695.robot.enumeration.Position;
15
import org.usfirst.frc.team3695.robot.enumeration.Drivetrain;
16
import org.usfirst.frc.team3695.robot.enumeration.Goal;
17
import org.usfirst.frc.team3695.robot.subsystems.*;
18
19
/** the magic place where everything happens (where the sequence of events is controlled, top of the hierarchy) */
20
public class Robot extends IterativeRobot {
21
22
	/// choosers
23
		SendableChooser<Goal> goalChooser;
24
		SendableChooser<Drivetrain> driveChooser;
25
		SendableChooser<Position>  positionChooser;
26
		// add choosers as needed, these put drop down options in the smart dash
27
		
28
		
29
	/// subsystems
30
//		public static SubsystemArduino SUB_ARDUINO;
31
		public static SubsystemClamp SUB_CLAMP;
0 ignored issues
show
Security introduced by
public static fields should always be marked final to prevent them being overwritten in unexpected ways. Consider making SUB_CLAMP final.

See this CWE advisory on why this is a security issue.

Loading history...
32
		public static SubsystemCompressor SUB_COMPRESSOR;
0 ignored issues
show
Security introduced by
public static fields should always be marked final to prevent them being overwritten in unexpected ways. Consider making SUB_COMPRESSOR final.

See this CWE advisory on why this is a security issue.

Loading history...
33
		public static SubsystemDrive SUB_DRIVE;
0 ignored issues
show
Security introduced by
public static fields should always be marked final to prevent them being overwritten in unexpected ways. Consider making SUB_DRIVE final.

See this CWE advisory on why this is a security issue.

Loading history...
34
		public static SubsystemHook SUB_HOOK;
0 ignored issues
show
Security introduced by
public static fields should always be marked final to prevent them being overwritten in unexpected ways. Consider making SUB_HOOK final.

See this CWE advisory on why this is a security issue.

Loading history...
35
		public static SubsystemManipulator SUB_MANIPULATOR;
0 ignored issues
show
Security introduced by
public static fields should always be marked final to prevent them being overwritten in unexpected ways. Consider making SUB_MANIPULATOR final.

See this CWE advisory on why this is a security issue.

Loading history...
36
		public static SubsystemMast SUB_MAST;
0 ignored issues
show
Security introduced by
public static fields should always be marked final to prevent them being overwritten in unexpected ways. Consider making SUB_MAST final.

See this CWE advisory on why this is a security issue.

Loading history...
37
38
		public static OI oi;
0 ignored issues
show
Security introduced by
public static fields should always be marked final to prevent them being overwritten in unexpected ways. Consider making oi final.

See this CWE advisory on why this is a security issue.

Loading history...
39
		public static Vision vision;
0 ignored issues
show
Security introduced by
public static fields should always be marked final to prevent them being overwritten in unexpected ways. Consider making vision final.

See this CWE advisory on why this is a security issue.

Loading history...
40
41
		
42
	/// autonomous
43
		private CommandGroupAuto auto;
44
		
45
		
46
		
47
		
48
	/** runs when robot is turned on */
49
	public void robotInit() {
50
			DriverStation.reportWarning("ROBOT STARTED; GOOD LUCK", false);
51
		/// instantiate subsystems
52
//			SUB_ARDUINO = new SubsystemArduino();
53
			SUB_MANIPULATOR = new SubsystemManipulator();
0 ignored issues
show
Bug Multi Threading introduced by
Instance methods writing to static fields may lead to concurrency problems. Consider making the enclosing method static or removing this assignment to a static field.

If you really need to set this static field, consider writing a thread-safe setter and atomic getter.

Loading history...
Bug Multi Threading introduced by
Lazy initializations of static fields like SUB_MANIPULATOR should be synchronized.
Loading history...
54
			SUB_CLAMP = new SubsystemClamp();
0 ignored issues
show
Bug Multi Threading introduced by
Lazy initializations of static fields like SUB_CLAMP should be synchronized.
Loading history...
Bug Multi Threading introduced by
Instance methods writing to static fields may lead to concurrency problems. Consider making the enclosing method static or removing this assignment to a static field.

If you really need to set this static field, consider writing a thread-safe setter and atomic getter.

Loading history...
55
			SUB_COMPRESSOR = new SubsystemCompressor();
0 ignored issues
show
Bug Multi Threading introduced by
Instance methods writing to static fields may lead to concurrency problems. Consider making the enclosing method static or removing this assignment to a static field.

If you really need to set this static field, consider writing a thread-safe setter and atomic getter.

Loading history...
Bug Multi Threading introduced by
Lazy initializations of static fields like SUB_COMPRESSOR should be synchronized.
Loading history...
56
			SUB_DRIVE = new SubsystemDrive();
0 ignored issues
show
Bug Multi Threading introduced by
Instance methods writing to static fields may lead to concurrency problems. Consider making the enclosing method static or removing this assignment to a static field.

If you really need to set this static field, consider writing a thread-safe setter and atomic getter.

Loading history...
Bug Multi Threading introduced by
Lazy initializations of static fields like SUB_DRIVE should be synchronized.
Loading history...
57
			SUB_HOOK = new SubsystemHook();
0 ignored issues
show
Bug Multi Threading introduced by
Lazy initializations of static fields like SUB_HOOK should be synchronized.
Loading history...
Bug Multi Threading introduced by
Instance methods writing to static fields may lead to concurrency problems. Consider making the enclosing method static or removing this assignment to a static field.

If you really need to set this static field, consider writing a thread-safe setter and atomic getter.

Loading history...
58
			SUB_MAST = new SubsystemMast();
0 ignored issues
show
Bug Multi Threading introduced by
Lazy initializations of static fields like SUB_MAST should be synchronized.
Loading history...
Bug Multi Threading introduced by
Instance methods writing to static fields may lead to concurrency problems. Consider making the enclosing method static or removing this assignment to a static field.

If you really need to set this static field, consider writing a thread-safe setter and atomic getter.

Loading history...
59
			//vision = new Vision();
60
61
		/// instantiate operator interface
62
			oi = new OI();
0 ignored issues
show
Bug Multi Threading introduced by
Instance methods writing to static fields may lead to concurrency problems. Consider making the enclosing method static or removing this assignment to a static field.

If you really need to set this static field, consider writing a thread-safe setter and atomic getter.

Loading history...
Bug Multi Threading introduced by
Lazy initializations of static fields like oi should be synchronized.
Loading history...
63
		
64
		/// instantiate drivetrain chooser
65
			driveChooser = new SendableChooser<>();
66
			driveChooser.addDefault(Drivetrain.ROCKET_LEAGUE.toString(), Drivetrain.ROCKET_LEAGUE); // set default to RL drive
67
			for(int i = 1; i < Drivetrain.values().length; i++) { 
68
				driveChooser.addObject(Drivetrain.values()[i].toString(), Drivetrain.values()[i]); } // add each drivetrain enum value to chooser
69
			SmartDashboard.putData("Drivetrain", driveChooser); //display the chooser on the dash
70
			
71
		/// instantiate position chooser
72
			positionChooser = new SendableChooser<>();
73
			positionChooser.addDefault(Position.CENTER.toString(), Position.CENTER); // set default to nothing
74
			for(int i = 1; i < Position.values().length; i++) { 
75
				positionChooser.addObject(Position.values()[i].toString(), Position.values()[i]); } // add each autonomous enum value to chooser
76
			SmartDashboard.putData("Position", positionChooser); //display the chooser on the dash
77
78
		/// instantiate goal chooser
79
			goalChooser = new SendableChooser<>();
80
			goalChooser.addDefault(Goal.NOTHING.toString(), Goal.NOTHING); // set default to nothing
81
			for(int i = 1; i < Goal.values().length; i++) { 
82
				goalChooser.addObject(Goal.values()[i].toString(), Goal.values()[i]); } // add each autonomous enum value to chooser
83
			SmartDashboard.putData("Goal", goalChooser); //display the chooser on the dash
84
			
85
		/// instantiate cameras
86
			// vision.startCameraThread();
87
			
88
			DriverStation.reportWarning("SUBSYSTEMS, CHOOSERS INSTANTIATED", false);
89
	}
90
91
	
92
	/** runs when robot gets disabled */
93
	public void disabledInit() { 
94
		DriverStation.reportWarning("TELEOP IS DISABLED", false);
95
	}
96
97
	
98
	/** runs at 50hz when bot is disabled */
99
	public void disabledPeriodic() {
100
		Scheduler.getInstance().run(); 
101
	}
102
103
	
104
	/** runs when autonomous start */
105
	public void autonomousInit() {
106
		DriverStation.reportWarning("AUTONOMOUS IS STARTING...", false);
107
		if(goalChooser.getSelected() != null) {
108
			auto = new CommandGroupAuto(positionChooser.getSelected(), goalChooser.getSelected());
109
			auto.start(); 
110
		} 
111
	}
112
113
	/** runs at 50hz when in autonomous */
114
	public void autonomousPeriodic() {
115
		Scheduler.getInstance().run(); 
116
	}
117
118
	
119
	/** runs when teleop starts*/
120
	public void teleopInit() {
121
		DriverStation.reportWarning("TELEOP IS ENABLED", false);
122
		if (auto != null)
123
			auto.cancel(); 
124
	}
125
126
	
127
	/** runs at ~50hz when in teleop mode */
128
	public void teleopPeriodic() {
129
		Scheduler.getInstance().run();
130
		if (driveChooser.getSelected() != null) {
131
			SUB_DRIVE.setDrivetrain(driveChooser.getSelected());
132
		}
133
		SUB_MANIPULATOR.spinByJoystick(OI.OPERATOR); // THIS IS A PATCH. DO AS I SAY, NOT AS I DO
134
	}
135
136
	
137
	/** runs at ~50hz when in test mode */
138
	public void testPeriodic() {
139
		LiveWindow.run(); 
140
	}
141
}
142
143