33import  edu .wpi .first .wpilibj .Compressor ;
44import  edu .wpi .first .wpilibj .IterativeRobot ;
55import  edu .wpi .first .wpilibj .command .Scheduler ;
6+ import  edu .wpi .first .wpilibj .smartdashboard .SmartDashboard ;
67import  maps .org .usfirst .frc .team449 .robot .Robot2017Map ;
78import  org .usfirst .frc .team449 .robot .drive .talonCluster .TalonClusterDrive ;
9+ import  org .usfirst .frc .team449 .robot .drive .talonCluster .commands .DefaultArcadeDrive ;
10+ import  org .usfirst .frc .team449 .robot .drive .talonCluster .commands .ExecuteProfile ;
811import  org .usfirst .frc .team449 .robot .drive .talonCluster .commands .PIDTest ;
912import  org .usfirst .frc .team449 .robot .drive .talonCluster .commands .SwitchToLowGear ;
1013import  org .usfirst .frc .team449 .robot .mechanism .climber .ClimberSubsystem ;
1114import  org .usfirst .frc .team449 .robot .mechanism .feeder .FeederSubsystem ;
1215import  org .usfirst .frc .team449 .robot .mechanism .intake .Intake2017 .Intake2017 ;
16+ import  org .usfirst .frc .team449 .robot .mechanism .intake .Intake2017 .commands .updown .IntakeUp ;
17+ import  org .usfirst .frc .team449 .robot .mechanism .intake .IntakeSubsystem ;
1318import  org .usfirst .frc .team449 .robot .mechanism .pneumatics .PneumaticsSubsystem ;
1419import  org .usfirst .frc .team449 .robot .mechanism .singleflywheelshooter .SingleFlywheelShooter ;
1520import  org .usfirst .frc .team449 .robot .oi .OI2017ArcadeGamepad ;
1823import  java .io .IOException ;
1924
2025/** 
21-  * Created by BlairRobot on 2017-01-08 . 
26+  * The main class of the robot, constructs all the subsystems and initializes default commands . 
2227 */ 
2328public  class  Robot  extends  IterativeRobot  {
2429
30+ 	/** 
31+ 	 * The shooter subsystem (flywheel only) 
32+ 	 */ 
2533	public  static  SingleFlywheelShooter  singleFlywheelShooterSubsystem ;
2634
35+ 	/** 
36+ 	 * The intake subsystem (intake motors and pistons) 
37+ 	 */ 
2738	public  static  Intake2017  intakeSubsystem ;
2839
40+ 	/** 
41+ 	 *The climber 
42+ 	 */ 
2943	public  static  ClimberSubsystem  climberSubsystem ;
3044
45+ 	/** 
46+ 	 *The pneumatics (maybe doesn't work?) 
47+ 	 */ 
3148	public  static  PneumaticsSubsystem  pneumaticsSubsystem ;
3249
50+ 	/** 
51+ 	 *The drive 
52+ 	 */ 
3353	public  static  TalonClusterDrive  driveSubsystem ;
3454
55+ 	/** 
56+ 	 * OI, using an Xbox-style controller and arcade drive. 
57+ 	 */ 
3558	public  static  OI2017ArcadeGamepad  oiSubsystem ;
3659
60+ 	/** 
61+ 	 * The cameras on the robot and the code to stream them to SmartDashboard (NOT computer vision!) 
62+ 	 */ 
3763	public  static  CameraSubsystem  cameraSubsystem ;
3864
65+ 	/** 
66+ 	 * The auger used to feed balls into the shooter. 
67+ 	 */ 
3968	public  static  FeederSubsystem  feederSubsystem ;
4069
41- 	private  static  maps .org .usfirst .frc .team449 .robot .Robot2017Map .Robot2017  cfg ;
70+ 	/** 
71+ 	 * The object constructed directly from map.cfg. 
72+ 	 * */ 
73+ 	private  static  Robot2017Map .Robot2017  cfg ;
4274
75+ 	/** 
76+ 	 * The method that runs when the robot is turned on. Initializes all subsystems from the map. 
77+ 	 */ 
4378	public  void  robotInit () {
44- 		System .out .println ("Started robotInit" );
79+ 		System .out .println ("Started robotInit." );
80+ 
4581		try  {
82+ 			//Try to construct map from the cfg file 
4683			//cfg = (Robot2017Map.Robot2017) MappedSubsystem.readConfig("/home/lvuser/449_resources/balbasaur_map.cfg", 
47- 			cfg  = (Robot2017Map .Robot2017 ) MappedSubsystem .readConfig ("/home/lvuser/449_resources/final_map.cfg" ,
48- 			// cfg = (Robot2017Map.Robot2017) MappedSubsystem.readConfig("/home/lvuser/449_resources/final_map_only_drive .cfg",
84+ 			// cfg = (Robot2017Map.Robot2017) MappedSubsystem.readConfig("/home/lvuser/449_resources/final_map.cfg",
85+ 			cfg  = (Robot2017Map .Robot2017 ) MappedSubsystem .readConfig ("/home/lvuser/449_resources/fancy_map .cfg" ,
4986					Robot2017Map .Robot2017 .newBuilder ());
5087		} catch  (IOException  e ) {
88+ 			//This is either the map file not being in the file system OR it being improperly formatted. 
5189			System .out .println ("Config file is bad/nonexistent!" );
5290			e .printStackTrace ();
5391		}
5492
93+ 		//Construct the OI (has to be done first because other subsystems take the OI as an argument.) 
5594		oiSubsystem  = new  OI2017ArcadeGamepad (cfg .getArcadeOi ());
5695		System .out .println ("Constructed OI" );
5796
97+ 		//Construct the drive (not in a if block because you kind of need it.) 
5898		driveSubsystem  = new  TalonClusterDrive (cfg .getDrive (), oiSubsystem );
5999		System .out .println ("Constructed Drive" );
60100
101+ 		//Construct camera if it's in the map. 
61102		if  (cfg .hasCamera ()) {
62103			cameraSubsystem  = new  CameraSubsystem (cfg .getCamera ());
63104		}
64105
106+ 		//Construct climber if it's in the map. 
65107		if  (cfg .hasClimber ()) {
66108			climberSubsystem  = new  ClimberSubsystem (cfg .getClimber ());
67109		}
68110
111+ 		//Construct shooter if it's in the map. 
69112		if  (cfg .hasShooter ()) {
70113			singleFlywheelShooterSubsystem  = new  SingleFlywheelShooter (cfg .getShooter ());
71114			System .out .println ("Constructed SingleFlywheelShooter" );
72115		}
73116
74- //		pneumaticsSubsystem = new PneumaticsSubsystem(cfg.getPneumatics()); 
75- // 		System.out.println("Constructed PneumaticsSubsystem"); 
76- 
117+ 		//Construct pneumatics if it's in the map. 
77118		if  (cfg .hasPneumatics ()) {
78119			pneumaticsSubsystem  = new  PneumaticsSubsystem (cfg .getPneumatics ());
79120			System .out .println ("Constructed PneumaticsSubsystem" );
80121		}
81122
123+ 		//Construct intake if it's in the map. 
82124		if  (cfg .hasIntake ()) {
83125			intakeSubsystem  = new  Intake2017 (cfg .getIntake ());
84126		}
85127
86- 		if  (cfg .hasFeeder ()){
128+ 		//Construct feeder if it's in the map. 
129+ 		if  (cfg .hasFeeder ()) {
87130			feederSubsystem  = new  FeederSubsystem (cfg .getFeeder ());
88131		}
89132
133+ 		//Map the buttons (has to be done last because all the subsystems need to have been instantiated.) 
90134		oiSubsystem .mapButtons ();
91135		System .out .println ("Mapped buttons" );
92136
137+ 		//Activate the compressor if its module number is in the map. 
93138		if  (cfg .hasModule ()) {
94139			Compressor  compressor  = new  Compressor (cfg .getModule ());
95140			compressor .setClosedLoopControl (true );
96141			compressor .start ();
97142		}
98143	}
99144
145+ 	/** 
146+ 	 * Run when we first enable in teleop. 
147+ 	 */ 
100148	@ Override 
101149	public  void  teleopInit () {
102- //		if (driveSubsystem.shifter != null) { 
103- //			Scheduler.getInstance().add(new SwitchToHighGear(driveSubsystem)); 
104- //		} 
150+ 		//Stop the drive for safety reasons 
151+ 		driveSubsystem .setVBusThrottle (0 , 0 );
105152
106- 		driveSubsystem .setDefaultThrottle (0 , 0 );
153+ 		driveSubsystem .leftMaster .canTalon .enable ();
154+ 		driveSubsystem .rightMaster .canTalon .enable ();
107155
108- 		if  (driveSubsystem .shifter  != null ){
156+ 		//Switch to low gear if we have gears 
157+ 		if  (driveSubsystem .shifter  != null ) {
109158			Scheduler .getInstance ().add (new  SwitchToLowGear (driveSubsystem ));
110159		}
160+ 
161+ 		if  (intakeSubsystem  != null ) {
162+ 			Scheduler .getInstance ().add (new  IntakeUp (intakeSubsystem ));
163+ 		}
164+ 
165+ //		Scheduler.getInstance().add(new DefaultArcadeDrive(driveSubsystem.straightPID, driveSubsystem, oiSubsystem)); 
111166	}
112167
168+ 	/** 
169+ 	 * Run every tick in teleop. 
170+ 	 */ 
113171	@ Override 
114172	public  void  teleopPeriodic () {
173+ 		//Run all commands. This is a WPILib thing you don't really have to worry about. 
115174		Scheduler .getInstance ().run ();
116175	}
117176
177+ 	/** 
178+ 	 * Run when we first enable in autonomous 
179+ 	 */ 
118180	@ Override 
119181	public  void  autonomousInit () {
120- 		driveSubsystem .setDefaultThrottle (0 , 0 );
182+ 		//Set throttle to 0 for safety reasons 
183+ 		if  (driveSubsystem .shifter  != null ) {
184+ 			Scheduler .getInstance ().add (new  SwitchToLowGear (driveSubsystem ));
185+ 		}
186+ 		driveSubsystem .leftMaster .canTalon .enable ();
187+ 		driveSubsystem .rightMaster .canTalon .enable ();
188+ 		driveSubsystem .setVBusThrottle (0 , 0 );
121189		Scheduler .getInstance ().add (new  PIDTest (driveSubsystem ));
190+ //		Scheduler.getInstance().add(new ExecuteProfile(driveSubsystem)); 
122191	}
123192
193+ 	/** 
194+ 	 * Runs every tick in autonomous. 
195+ 	 */ 
124196	@ Override 
125197	public  void  autonomousPeriodic () {
198+ 		//Run all commands. This is a WPILib thing you don't really have to worry about. 
126199		Scheduler .getInstance ().run ();
200+ 		SmartDashboard .putNumber ("Heading" , driveSubsystem .getGyroOutput ());
127201	}
128202}
0 commit comments