org.usfirst.frc.team3695.robot.Robot   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 151
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 151
rs 10
c 0
b 0
f 0
wmc 17

16 Methods

Rating   Name   Duplication   Size   Complexity  
testPeriodic 0 2 ?
A disabledInit() 0 3 1
A autonomousPeriodic() 0 3 2
A testPeriodic() 0 2 1
teleopInit 0 4 ?
A autonomousInit() 0 5 2
B robotInit() 0 67 5
autonomousInit 0 5 ?
A teleopPeriodic() 0 8 3
disabledInit 0 3 ?
disabledPeriodic 0 2 ?
A disabledPeriodic() 0 2 1
A teleopInit() 0 4 2
autonomousPeriodic 0 3 ?
teleopPeriodic 0 8 ?
robotInit 0 67 ?
1
2
package org.usfirst.frc.team3695.robot;
3
4
import edu.wpi.first.wpilibj.DriverStation;
5
import edu.wpi.first.wpilibj.IterativeRobot;
6
import edu.wpi.first.wpilibj.command.Scheduler;
7
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
8
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
9
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
10
import org.usfirst.frc.team3695.robot.auto.CommandGroupAuto;
11
import org.usfirst.frc.team3695.robot.enumeration.Bot;
12
import org.usfirst.frc.team3695.robot.enumeration.Drivetrain;
13
import org.usfirst.frc.team3695.robot.enumeration.Goal;
14
import org.usfirst.frc.team3695.robot.enumeration.Position;
15
import org.usfirst.frc.team3695.robot.subsystems.*;
16
import org.usfirst.frc.team3695.robot.util.Util;
17
18
//    _____   _____   ____     ______           ______                   _                                        ____             _                   
19
//   |__  /  / ___/  / __ \   / ____/          / ____/  ____    _  __   (_)   ____ ___   __  __   _____          / __ \   _____   (_)   ____ ___   ___ 
20
//    /_ <  / __ \  / /_/ /  /___ \           / /_     / __ \  | |/_/  / /   / __ `__ \ / / / /  / ___/         / /_/ /  / ___/  / /   / __ `__ \ / _ \
21
//  ___/ / / /_/ /  \__, /  ____/ /          / __/    / /_/ / _>  <   / /   / / / / / // /_/ /  (__  )         / ____/  / /     / /   / / / / / //  __/
22
// /____/  \____/  /____/  /_____/          /_/       \____/ /_/|_|  /_/   /_/ /_/ /_/ \__,_/  /____/         /_/      /_/     /_/   /_/ /_/ /_/ \___/ 
23
24
/** the magic place where everything happens (where the sequence of events is controlled, top of the hierarchy) */
25
public class Robot extends IterativeRobot {
26
27
		public static Bot bot;
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 bot final.

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

Loading history...
28
29
	/// choosers
30
		SendableChooser<Bot> botChooser;
31
		SendableChooser<Goal> goalChooser;
32
		SendableChooser<Drivetrain> driveChooser;
33
		SendableChooser<Position>  positionChooser;
34
		// add choosers as needed, these put drop down options in the smart dash
35
		
36
		
37
	/// subsystems
38
//		public static SubsystemArduino SUB_ARDUINO;
39
		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...
40
		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...
41
		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...
42
		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...
43
		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...
44
		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...
45
46
		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...
47
		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...
48
49
		
50
	/// autonomous
51
		private CommandGroupAuto auto;
52
53
	/** runs when robot is turned on */
54
	public void robotInit() {
55
		/// instantiate bot chooser
56
		botChooser = new SendableChooser<>();
57
		botChooser.addDefault(Bot.TEUFELSKIND.toString(), Bot.TEUFELSKIND);
58
		botChooser.addObject(Bot.OOF.toString(), Bot.OOF);
59
		SmartDashboard.putData("Bot", botChooser);
60
61
		if (botChooser.getSelected() != null){
62
			bot = botChooser.getSelected();
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 bot should be synchronized.
Loading history...
63
		} else {
64
			bot = Bot.OOF;
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 bot should be synchronized.
Loading history...
65
		}
66
67
			DriverStation.reportWarning("ROBOT STARTED; GOOD LUCK", false);
68
		/// instantiate subsystems
69
//			SUB_ARDUINO = new SubsystemArduino();
70
			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...
71
			SUB_CLAMP = new SubsystemClamp();
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_CLAMP should be synchronized.
Loading history...
72
			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...
73
			SUB_DRIVE = new SubsystemDrive();
0 ignored issues
show
Bug Multi Threading introduced by
Lazy initializations of static fields like SUB_DRIVE 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...
74
			
75
			SUB_DRIVE.pid.setPIDF(.5, 0, 0, 0);
0 ignored issues
show
Comprehensibility introduced by
Consider assigning this magic number .5 to a constant.

Using constants for hard-coded numbers is a best practice. A constant’s name can explain the rationale behind this magic number. It is also easier to find if you ever need to change it.

Loading history...
76
			
77
			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...
78
			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...
79
			vision = new Vision();
0 ignored issues
show
Bug Multi Threading introduced by
Lazy initializations of static fields like vision 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...
80
81
		/// instantiate operator interface
82
			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...
83
84
			
85
			
86
		/// instantiate drivetrain chooser
87
				driveChooser = new SendableChooser<>();
88
				driveChooser.addDefault(Drivetrain.ROCKET_LEAGUE.toString(), Drivetrain.ROCKET_LEAGUE); // set default to RL drive
89
				for(int i = 1; i < Drivetrain.values().length; i++) { 
90
					driveChooser.addObject(Drivetrain.values()[i].toString(), Drivetrain.values()[i]); } // add each drivetrain enum value to chooser
91
				SmartDashboard.putData("Drivetrain", driveChooser); //display the chooser on the dash
92
			
93
		/// instantiate position chooser
94
				positionChooser = new SendableChooser<>();
95
				positionChooser.addDefault(Position.CENTER.toString(), Position.CENTER); // set default to center
96
				for(int i = 1; i < Position.values().length; i++) { 
97
					positionChooser.addObject(Position.values()[i].toString(), Position.values()[i]); } // add each position enum value to chooser
98
				SmartDashboard.putData("Position", positionChooser); //display the chooser on the dash
99
100
		/// instantiate goal chooser
101
				goalChooser = new SendableChooser<>();
102
				goalChooser.addDefault(Goal.NOTHING.toString(), Goal.NOTHING); // set default to nothing
103
				for(int i = 1; i < Goal.values().length; i++) { 
104
					goalChooser.addObject(Goal.values()[i].toString(), Goal.values()[i]); } // add each autonomous goal to chooser
105
				SmartDashboard.putData("Goal", goalChooser); //display the chooser on the dash
106
			
107
		/// instantiate bot chooser
108
				botChooser = new SendableChooser<>();
109
				botChooser.addDefault(Bot.TEUFELSKIND.toString(), Bot.TEUFELSKIND);
110
					botChooser.addObject(Bot.OOF.toString(), Bot.OOF); 
111
				SmartDashboard.putData("Bot", botChooser);
112
				
113
				
114
				
115
		/// instantiate cameras
116
			vision.startScrewCameraThread();
117
			vision.startFrameCameraThread();
118
119
		SmartDashboard.putData("Sub_Drive", SUB_DRIVE);
120
		DriverStation.reportWarning("SUBSYSTEMS, CHOOSERS INSTANTIATED", false);
121
	}
122
123
	
124
	/** runs when robot gets disabled */
125
	public void disabledInit() { 
126
		DriverStation.reportWarning("TELEOP IS DISABLED", false);
127
		Scheduler.getInstance().removeAll();
128
	}
129
130
	
131
	/** runs at 50hz when bot is disabled */
132
	public void disabledPeriodic() {
133
		Scheduler.getInstance().run(); 
134
	}
135
136
	
137
	/** runs when autonomous start */
138
	public void autonomousInit() {
139
		DriverStation.reportWarning("AUTONOMOUS IS STARTING...", false);
140
		if(goalChooser.getSelected() != null) {
141
			auto = new CommandGroupAuto(positionChooser.getSelected(), goalChooser.getSelected());
142
			auto.start(); 
143
		} 
144
	}
145
146
	/** runs at 50hz when in autonomous */
147
	public void autonomousPeriodic() {
148
		Scheduler.getInstance().run(); 
149
		bot = (botChooser.getSelected() != null) ? botChooser.getSelected() : bot; // update motor inverts
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 bot should be synchronized.
Loading history...
150
	}
151
152
	
153
	/** runs when teleop starts*/
154
	public void teleopInit() {
155
		DriverStation.reportWarning("TELEOP IS ENABLED", false);
156
		if (auto != null)
157
			auto.cancel(); 
158
	}
159
160
	
161
	/** runs at ~50hz when in teleop mode */
162
	public void teleopPeriodic() {
163
		Scheduler.getInstance().run();
164
		
165
		if (driveChooser.getSelected() != null) {
166
			SUB_DRIVE.setDrivetrain(driveChooser.getSelected());
167
		}
168
		
169
		bot = (botChooser.getSelected() != null) ? botChooser.getSelected() : bot; // update motor inverts
0 ignored issues
show
Bug Multi Threading introduced by
Lazy initializations of static fields like bot 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...
170
	}
171
172
	
173
	/** runs at ~50hz when in test mode */
174
	public void testPeriodic() {
175
		LiveWindow.run(); 
176
	}
177
}
178
179