use of com.robo4j.ConfigurationException in project robo4j by Robo4J.
the class LaserScanner method onInitialization.
@Override
protected void onInitialization(Configuration configuration) throws ConfigurationException {
super.onInitialization(configuration);
pan = configuration.getString("servo", "laserscanner.servo");
// Using degrees for convenience
servoRange = (float) configuration.getFloat("servoRange", 45.0f);
// Using angular degrees per second.
angularSpeed = configuration.getFloat("angularSpeed", 90.0f);
// Minimum acquisition time, in ms
minimumAcquisitionTime = configuration.getFloat("minAquisitionTime", 2.0f);
// Trim to align left to right and right to left scans (in degrees)
trim = configuration.getFloat("trim", 0.0f);
// Set the default minimal range to filter out
float minFilterRange = configuration.getFloat("minFilterRange", DEFAULT_FILTER_MIN_RANGE);
pointFilter = new MinRangePointFilter(minFilterRange);
try {
lidar = new LidarLiteDevice(getBus(), getAddress());
} catch (IOException e) {
throw new ConfigurationException(String.format("Failed to initialize lidar device. Make sure it is hooked up to bus: %d address: %xd", getBus(), getAddress()), e);
}
}
use of com.robo4j.ConfigurationException in project robo4j by Robo4J.
the class SonicSensorUnit method onInitialization.
@Override
protected void onInitialization(Configuration configuration) throws ConfigurationException {
setState(LifecycleState.UNINITIALIZED);
scanInitialDelay = configuration.getInteger(PROPERTY_SCAN_INIT_DELAY, VALUE_SCAN_INIT_DELAY);
scanPeriod = configuration.getInteger(PROPERTY_SCAN_PERIOD, VALUE_SCAN_PERIOD);
String port = configuration.getString(PROPERTY_SENSOR_PORT, null);
DigitalPortEnum sensorPort = DigitalPortEnum.getByType(port);
target = configuration.getString(PROPERTY_TARGET, null);
if (sensorPort == null) {
throw new ConfigurationException("sonic sensor port required: {S1,S2,S3,S4}");
}
if (target == null) {
throw new ConfigurationException("sonic sensor target required");
}
SensorProvider provider = new SensorProvider();
sensor = new SensorWrapper<>(provider, sensorPort, SensorTypeEnum.SONIC);
setState(LifecycleState.INITIALIZED);
}
use of com.robo4j.ConfigurationException in project robo4j by Robo4J.
the class TouchPlatformSpeedUnit method onInitialization.
@Override
protected void onInitialization(Configuration configuration) throws ConfigurationException {
lcdTarget = configuration.getString(PROPERTY_TARGET, null);
if (lcdTarget == null) {
throw ConfigurationException.createMissingConfigNameException(PROPERTY_TARGET);
}
platformTarget = configuration.getString(PROPERTY_PLATFORM_TARGET, null);
if (platformTarget == null) {
throw ConfigurationException.createMissingConfigNameException(PROPERTY_PLATFORM_TARGET);
}
String sensorPort = configuration.getString(PROPERTY_SENSOR_PORT, null);
if (sensorPort == null) {
throw ConfigurationException.createMissingConfigNameException(PROPERTY_SENSOR_PORT);
}
SensorProvider provider = new SensorProvider();
sensor = new SensorWrapper<>(provider, DigitalPortEnum.getByType(sensorPort), SensorTypeEnum.TOUCH);
sensorActive.set(true);
speedMin = configuration.getInteger(PROPERTY_SPEED_MIN, 150);
speedMax = configuration.getInteger(PROPERTY_SPEED_MAX, 300);
speedIncrement = configuration.getInteger(PROPERTY_SPEED_INCREMENT, 50);
if ((speedMin % speedIncrement != 0) || (speedMax % speedIncrement != 0)) {
throw new ConfigurationException(String.format("min: %d and max: %d speed needs to be divisible by increment: %d", speedMin, speedMax, speedIncrement));
}
currentSpeed = speedMin;
}
Aggregations