This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
read RobotConfigurator from config file
- Loading branch information
Showing
4 changed files
with
74 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,38 @@ | ||
package com.team766.hal; | ||
|
||
import com.team766.config.ConfigFileReader; | ||
import com.team766.library.ValueProvider; | ||
import com.team766.logging.Category; | ||
import com.team766.logging.Logger; | ||
import com.team766.logging.LoggerExceptionUtils; | ||
import com.team766.logging.Severity; | ||
import com.team766.robot.example.ExampleConfigurator; | ||
|
||
public final class RobotSelector { | ||
|
||
private static final String ROBOT_CONFIGURATOR_KEY = "robotConfigurator"; | ||
private static final String DEFAULT_CONFIGURATOR = ExampleConfigurator.class.getName(); | ||
|
||
private RobotSelector() {} | ||
|
||
public static RobotConfigurator createConfigurator(String configurator) throws Exception { | ||
Class<RobotConfigurator> clazz = (Class<RobotConfigurator>) Class.forName(configurator); | ||
return clazz.getDeclaredConstructor().newInstance(); | ||
public static RobotConfigurator createConfigurator() { | ||
ValueProvider<String> configuratorProvider = | ||
ConfigFileReader.instance.getString(ROBOT_CONFIGURATOR_KEY); | ||
String robotConfigurator = | ||
configuratorProvider.hasValue() ? configuratorProvider.get() : DEFAULT_CONFIGURATOR; | ||
|
||
try { | ||
Class<RobotConfigurator> clazz = | ||
(Class<RobotConfigurator>) Class.forName(robotConfigurator); | ||
return clazz.getDeclaredConstructor().newInstance(); | ||
} catch (Exception e) { | ||
Logger.get(Category.FRAMEWORK) | ||
.logData( | ||
Severity.ERROR, | ||
"Unable to create RobotConfigurator {0}. Using default.", | ||
robotConfigurator); | ||
LoggerExceptionUtils.logException(e); | ||
return new ExampleConfigurator(); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/team766/robot/example/ExampleConfigurator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.team766.robot.example; | ||
|
||
import com.team766.framework.AutonomousMode; | ||
import com.team766.framework.Procedure; | ||
import com.team766.hal.RobotConfigurator; | ||
|
||
public class ExampleConfigurator implements RobotConfigurator { | ||
public ExampleConfigurator() {} | ||
|
||
public void initializeMechanisms() { | ||
Robot.robotInit(); | ||
} | ||
|
||
public Procedure createOI() { | ||
return new OI(); | ||
} | ||
|
||
public AutonomousMode[] getAutonomousModes() { | ||
return AutonomousModes.AUTONOMOUS_MODES; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/team766/robot/gatorade/GatoradeConfigurator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.team766.robot.gatorade; | ||
|
||
import com.team766.framework.AutonomousMode; | ||
import com.team766.framework.Procedure; | ||
import com.team766.hal.RobotConfigurator; | ||
|
||
public class GatoradeConfigurator implements RobotConfigurator { | ||
public GatoradeConfigurator() {} | ||
|
||
public void initializeMechanisms() { | ||
Robot.robotInit(); | ||
} | ||
|
||
public Procedure createOI() { | ||
return new OI(); | ||
} | ||
|
||
public AutonomousMode[] getAutonomousModes() { | ||
return AutonomousModes.AUTONOMOUS_MODES; | ||
} | ||
} |