Search in sources :

Example 11 with ConfigurationException

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

Example 12 with ConfigurationException

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);
}
Also used : SensorProvider(com.robo4j.hw.lego.provider.SensorProvider) ConfigurationException(com.robo4j.ConfigurationException) DigitalPortEnum(com.robo4j.hw.lego.enums.DigitalPortEnum)

Example 13 with ConfigurationException

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;
}
Also used : SensorProvider(com.robo4j.hw.lego.provider.SensorProvider) ConfigurationException(com.robo4j.ConfigurationException)

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