use of com.robo4j.ConfigurationException in project robo4j by Robo4J.
the class RoboClawRCTankUnit method onInitialization.
@Override
protected void onInitialization(Configuration configuration) throws ConfigurationException {
super.onInitialization(configuration);
PWMPCA9685Device pcaDevice = I2CRegistry.createAndRegisterIfAbsent(getBus(), getAddress(), () -> PWMPCA9685Device.createDevice(getBus(), getAddress()));
int leftChannel = configuration.getInteger(CONFIGURATION_KEY_LEFT_CHANNEL, -1);
if (leftChannel == -1) {
throw ConfigurationException.createMissingConfigNameException(CONFIGURATION_KEY_LEFT_CHANNEL);
}
int rightChannel = configuration.getInteger(CONFIGURATION_KEY_RIGHT_CHANNEL, -1);
if (rightChannel == -1) {
throw ConfigurationException.createMissingConfigNameException(CONFIGURATION_KEY_RIGHT_CHANNEL);
}
boolean leftInvert = configuration.getBoolean(CONFIGURATION_KEY_LEFT_INVERTED, false);
boolean rightInvert = configuration.getBoolean(CONFIGURATION_KEY_RIGHT_INVERTED, false);
PCA9685Servo leftServo = new PCA9685Servo(pcaDevice.getChannel(leftChannel));
leftServo.setInverted(leftInvert);
PCA9685Servo rightServo = new PCA9685Servo(pcaDevice.getChannel(rightChannel));
rightServo.setInverted(rightInvert);
try {
tank = new RoboClawRCTank(leftServo, rightServo);
} catch (IOException e) {
throw new ConfigurationException("Could not initiate device!", e);
}
}
use of com.robo4j.ConfigurationException in project robo4j by Robo4J.
the class MtkGPSUnit method onInitialization.
@Override
protected void onInitialization(Configuration configuration) throws ConfigurationException {
serialPort = configuration.getString("serialPort", DEFAULT_SERIAL_PORT);
readInterval = configuration.getInteger("readInterval", DEFAULT_READ_INTERVAL);
String scheduler = configuration.getString("scheduler", PROPERTY_VALUE_PLATFORM_SCHEDULER);
boolean usePlatformScheduler = PROPERTY_VALUE_PLATFORM_SCHEDULER.equals(scheduler);
try {
mtk3339gps = new MTK3339GPS(serialPort, readInterval);
} catch (IOException e) {
throw new ConfigurationException("Could not instantiate GPS!", e);
}
if (usePlatformScheduler) {
scheduledFuture = getContext().getScheduler().scheduleAtFixedRate(() -> mtk3339gps.update(), 10, readInterval, TimeUnit.MILLISECONDS);
} else {
mtk3339gps.start();
}
}
use of com.robo4j.ConfigurationException in project robo4j by Robo4J.
the class AdafruitButtonUnit method onInitialization.
@Override
protected void onInitialization(Configuration configuration) throws ConfigurationException {
super.onInitialization(configuration);
target = configuration.getString("target", null);
if (target == null) {
throw ConfigurationException.createMissingConfigNameException("target");
}
try {
lcd = AdafruitLcdUnit.getLCD(getBus(), getAddress());
} catch (IOException e) {
throw new ConfigurationException("Could not initialize LCD shield", e);
}
setState(LifecycleState.INITIALIZED);
}
use of com.robo4j.ConfigurationException in project robo4j by Robo4J.
the class AccelerometerLSM303Unit method onInitialization.
@Override
protected void onInitialization(Configuration configuration) throws ConfigurationException {
super.onInitialization(configuration);
PowerMode powerMode = PowerMode.valueOf(configuration.getString(PROPERTY_KEY_POWER_MODE, PowerMode.NORMAL.name()));
DataRate rate = DataRate.valueOf(configuration.getString(PROPERTY_KEY_RATE, DataRate.HZ_10.name()));
Integer axisEnable = configuration.getInteger(PROPERTY_KEY_AXIS_ENABLE, AccelerometerLSM303Device.AXIS_ENABLE_ALL);
FullScale fullScale = FullScale.valueOf(configuration.getString(PROPERTY_KEY_FULL_SCALE, FullScale.G_2.name()));
Boolean enableHighRes = configuration.getBoolean(PROPERTY_KEY_ENABLE_HIGH_RES, false);
Tuple3f offsets = readFloat3D(configuration.getChildConfiguration("offsets"));
Tuple3f multipliers = readFloat3D(configuration.getChildConfiguration("multipliers"));
period = configuration.getInteger(PROPERTY_KEY_PERIOD, 200);
try {
AccelerometerLSM303Device device = new AccelerometerLSM303Device(getBus(), getAddress(), powerMode, rate, axisEnable, fullScale, enableHighRes);
accelerometer = new CalibratedAccelerometer(device, offsets, multipliers);
} 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 Adafruit24BargraphUnit method onInitialization.
@Override
protected void onInitialization(Configuration configuration) throws ConfigurationException {
super.onInitialization(configuration);
int brightness = configuration.getInteger(ATTRIBUTE_BRIGHTNESS, AbstractBackpack.DEFAULT_BRIGHTNESS);
try {
device = new BiColor24BarDevice(getBus(), getAddress(), brightness);
} catch (IOException e) {
throw new ConfigurationException("Failed to instantiate device", e);
}
}
Aggregations