Search in sources :

Example 6 with ConfigurationException

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);
}
Also used : ConfigurationException(com.robo4j.core.ConfigurationException) IOException(java.io.IOException)

Example 7 with ConfigurationException

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);
    }
}
Also used : LidarLiteDevice(com.robo4j.hw.rpi.i2c.lidar.LidarLiteDevice) ConfigurationException(com.robo4j.core.ConfigurationException) IOException(java.io.IOException)

Example 8 with ConfigurationException

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));
}
Also used : ConfigurationException(com.robo4j.core.ConfigurationException) Servo(com.robo4j.hw.rpi.i2c.pwm.Servo) I2CEndPoint(com.robo4j.units.rpi.I2CEndPoint) PWMPCA9685Device(com.robo4j.hw.rpi.i2c.pwm.PWMPCA9685Device) IOException(java.io.IOException)

Aggregations

ConfigurationException (com.robo4j.core.ConfigurationException)8 IOException (java.io.IOException)7 LifecycleState (com.robo4j.core.LifecycleState)2 RoboContext (com.robo4j.core.RoboContext)2 RoboUnit (com.robo4j.core.RoboUnit)2 RoboHttpUtils (com.robo4j.core.client.util.RoboHttpUtils)2 Configuration (com.robo4j.core.configuration.Configuration)2 Constants (com.robo4j.core.httpunit.Constants)2 CameraMessage (com.robo4j.core.httpunit.codec.CameraMessage)2 CameraMessageCodec (com.robo4j.core.httpunit.codec.CameraMessageCodec)2 SimpleLoggingUtil (com.robo4j.core.logging.SimpleLoggingUtil)2 InetAddress (java.net.InetAddress)2 UnknownHostException (java.net.UnknownHostException)2 Base64 (java.util.Base64)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Collectors (java.util.stream.Collectors)2 RoboClassLoader (com.robo4j.core.client.util.RoboClassLoader)1 PropertyMapBuilder (com.robo4j.core.httpunit.test.util.PropertyMapBuilder)1