use of com.robo4j.core.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.core.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);
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.core.ConfigurationException in project robo4j by Robo4J.
the class PCA9685ServoUnit method onInitialization.
/**
*
* @param configuration
* - unit configuration
* @throws ConfigurationException
*/
@Override
protected void onInitialization(Configuration configuration) throws ConfigurationException {
super.onInitialization(configuration);
Object pwmDevice = I2CRegistry.getI2CDeviceByEndPoint(new I2CEndPoint(getBus(), getAddress()));
PWMPCA9685Device pcaDevice = null;
try {
if (pwmDevice == null) {
pcaDevice = new PWMPCA9685Device(getBus(), getAddress());
I2CRegistry.registerI2CDevice(pcaDevice, new I2CEndPoint(getBus(), getAddress()));
pcaDevice.setPWMFrequency(50);
} else {
pcaDevice = (PWMPCA9685Device) pwmDevice;
}
} catch (IOException e) {
throw new ConfigurationException("Could not initialize hardware", e);
}
channel = configuration.getInteger(CONFIGURATION_KEY_CHANNEL, -1);
if (channel == -1) {
throw ConfigurationException.createMissingConfigNameException(CONFIGURATION_KEY_CHANNEL);
}
servo = new Servo(pcaDevice.getChannel(channel));
servo.setTrim(configuration.getFloat(CONFIGURATION_KEY_TRIM, 0f));
servo.setInverted(configuration.getBoolean(CONFIGURATION_KEY_INVERTED, false));
servo.setDualRate(configuration.getFloat(CONFIGURATION_KEY_DUAL_RATE, 1.0f));
servo.setExpo(configuration.getFloat(CONFIGURATION_KEY_EXPO, 0.0f));
}
Aggregations