Search in sources :

Example 6 with ConfigurationException

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);
    }
}
Also used : ConfigurationException(com.robo4j.ConfigurationException) PWMPCA9685Device(com.robo4j.hw.rpi.i2c.pwm.PWMPCA9685Device) IOException(java.io.IOException) RoboClawRCTank(com.robo4j.hw.rpi.pwm.roboclaw.RoboClawRCTank) PCA9685Servo(com.robo4j.hw.rpi.i2c.pwm.PCA9685Servo)

Example 7 with ConfigurationException

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();
    }
}
Also used : MTK3339GPS(com.robo4j.hw.rpi.serial.gps.MTK3339GPS) ConfigurationException(com.robo4j.ConfigurationException) IOException(java.io.IOException)

Example 8 with ConfigurationException

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

Example 9 with ConfigurationException

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);
    }
}
Also used : CalibratedAccelerometer(com.robo4j.hw.rpi.i2c.accelerometer.CalibratedAccelerometer) Tuple3f(com.robo4j.math.geometry.Tuple3f) ConfigurationException(com.robo4j.ConfigurationException) DataRate(com.robo4j.hw.rpi.i2c.accelerometer.AccelerometerLSM303Device.DataRate) PowerMode(com.robo4j.hw.rpi.i2c.accelerometer.AccelerometerLSM303Device.PowerMode) FullScale(com.robo4j.hw.rpi.i2c.accelerometer.AccelerometerLSM303Device.FullScale) IOException(java.io.IOException) AccelerometerLSM303Device(com.robo4j.hw.rpi.i2c.accelerometer.AccelerometerLSM303Device)

Example 10 with ConfigurationException

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

Aggregations

ConfigurationException (com.robo4j.ConfigurationException)13 IOException (java.io.IOException)10 SensorProvider (com.robo4j.hw.lego.provider.SensorProvider)3 DigitalPortEnum (com.robo4j.hw.lego.enums.DigitalPortEnum)2 AccelerometerLSM303Device (com.robo4j.hw.rpi.i2c.accelerometer.AccelerometerLSM303Device)1 DataRate (com.robo4j.hw.rpi.i2c.accelerometer.AccelerometerLSM303Device.DataRate)1 FullScale (com.robo4j.hw.rpi.i2c.accelerometer.AccelerometerLSM303Device.FullScale)1 PowerMode (com.robo4j.hw.rpi.i2c.accelerometer.AccelerometerLSM303Device.PowerMode)1 CalibratedAccelerometer (com.robo4j.hw.rpi.i2c.accelerometer.CalibratedAccelerometer)1 AlphanumericDevice (com.robo4j.hw.rpi.i2c.adafruitbackpack.AlphanumericDevice)1 BiColor24BarDevice (com.robo4j.hw.rpi.i2c.adafruitbackpack.BiColor24BarDevice)1 BiColor8x8MatrixDevice (com.robo4j.hw.rpi.i2c.adafruitbackpack.BiColor8x8MatrixDevice)1 MatrixRotation (com.robo4j.hw.rpi.i2c.adafruitbackpack.MatrixRotation)1 CalibratedGyro (com.robo4j.hw.rpi.i2c.gyro.CalibratedGyro)1 GyroL3GD20Device (com.robo4j.hw.rpi.i2c.gyro.GyroL3GD20Device)1 LidarLiteDevice (com.robo4j.hw.rpi.i2c.lidar.LidarLiteDevice)1 PCA9685Servo (com.robo4j.hw.rpi.i2c.pwm.PCA9685Servo)1 PWMPCA9685Device (com.robo4j.hw.rpi.i2c.pwm.PWMPCA9685Device)1 RoboClawRCTank (com.robo4j.hw.rpi.pwm.roboclaw.RoboClawRCTank)1 MTK3339GPS (com.robo4j.hw.rpi.serial.gps.MTK3339GPS)1