Search in sources :

Example 1 with ConfigurationException

use of com.robo4j.core.ConfigurationException in project robo4j by Robo4J.

the class GyroL3GD20Unit method onInitialization.

@Override
protected void onInitialization(Configuration configuration) throws ConfigurationException {
    super.onInitialization(configuration);
    sensitivity = Sensitivity.valueOf(configuration.getString(PROPERTY_KEY_SENSITIVITY, "DPS_245"));
    period = configuration.getInteger(PROPERTY_KEY_PERIOD, 10);
    highPassFilter = configuration.getBoolean(PROPERTY_KEY_HIGH_PASS_FILTER, true);
    try {
        gyro = new CalibratedGyro(new GyroL3GD20Device(getBus(), getAddress(), sensitivity, highPassFilter));
    } 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 : CalibratedGyro(com.robo4j.hw.rpi.i2c.gyro.CalibratedGyro) ConfigurationException(com.robo4j.core.ConfigurationException) IOException(java.io.IOException) GyroL3GD20Device(com.robo4j.hw.rpi.i2c.gyro.GyroL3GD20Device)

Example 2 with ConfigurationException

use of com.robo4j.core.ConfigurationException in project robo4j by Robo4J.

the class RaspistillUnit method onInitialization.

@Override
protected void onInitialization(Configuration configuration) throws ConfigurationException {
    Map<String, String> parameters = new HashMap<>();
    parameters.put(KEY_WIDTH, configuration.getString(KEY_WIDTH, "320"));
    parameters.put(KEY_HEIGHT, configuration.getString(KEY_HEIGHT, "240"));
    parameters.put(KEY_EXPOSURE, configuration.getString(KEY_EXPOSURE, "sport"));
    parameters.put(KEY_BRIGHTNESS, configuration.getString(KEY_BRIGHTNESS, null));
    parameters.put(KEY_SHARPNESS, configuration.getString(KEY_SHARPNESS, null));
    parameters.put(KEY_CONTRAST, configuration.getString(KEY_CONTRAST, null));
    parameters.put(KEY_TIMEOUT, configuration.getString(KEY_TIMEOUT, "1"));
    parameters.put(KEY_TIMELAPSE, configuration.getString(KEY_TIMELAPSE, "100"));
    parameters.put(KEY_ROTATION, configuration.getString(KEY_ROTATION, null));
    //@formatter:off
    cameraCommand = new StringBuilder().append(RaspistillUtils.RASPISTILL_COMMAND).append(Constants.UTF8_SPACE).append(parameters.entrySet().stream().filter(p -> Objects.nonNull(p.getValue())).map(e -> {
        StringBuilder c = new StringBuilder();
        if (RaspistillUtils.isOption(e.getKey())) {
            return c.append(RaspistillUtils.getOption(e.getKey())).append(Constants.UTF8_SPACE).append(e.getValue()).toString();
        }
        return null;
    }).filter(Objects::nonNull).collect(Collectors.joining(Constants.UTF8_SPACE))).append(Constants.UTF8_SPACE).append(DEFAULT_IMAGE_SETUP).toString();
    SimpleLoggingUtil.print(getClass(), "cameraCommand:" + cameraCommand);
    //@formatter:on
    targetOut = configuration.getString("targetOut", null);
    String tmpClient = configuration.getString("client", null);
    if (tmpClient == null || targetOut == null) {
        throw ConfigurationException.createMissingConfigNameException("targetOut, client");
    }
    storeTarget = configuration.getString("storeTarget", null);
    try {
        InetAddress inetAddress = InetAddress.getByName(tmpClient);
        String clientPort = configuration.getString("clientPort", null);
        client = clientPort == null ? inetAddress.getHostAddress() : inetAddress.getHostAddress().concat(":").concat(clientPort);
        clientUri = configuration.getString("clientUri", Constants.EMPTY_STRING);
    } catch (UnknownHostException e) {
        SimpleLoggingUtil.error(getClass(), "unknown ip address", e);
        throw ConfigurationException.createMissingConfigNameException("unknown ip address");
    }
}
Also used : KEY_SHARPNESS(com.robo4j.units.rpi.camera.RaspistillUtils.KEY_SHARPNESS) CameraMessageCodec(com.robo4j.core.httpunit.codec.CameraMessageCodec) FORMAT_IMAGE(com.robo4j.units.rpi.camera.RaspistillUtils.FORMAT_IMAGE) KEY_TIMEOUT(com.robo4j.units.rpi.camera.RaspistillUtils.KEY_TIMEOUT) KEY_TIMELAPSE(com.robo4j.units.rpi.camera.RaspistillUtils.KEY_TIMELAPSE) HashMap(java.util.HashMap) RoboUnit(com.robo4j.core.RoboUnit) InetAddress(java.net.InetAddress) KEY_CONTRAST(com.robo4j.units.rpi.camera.RaspistillUtils.KEY_CONTRAST) CameraMessage(com.robo4j.core.httpunit.codec.CameraMessage) KEY_HEIGHT(com.robo4j.units.rpi.camera.RaspistillUtils.KEY_HEIGHT) SimpleLoggingUtil(com.robo4j.core.logging.SimpleLoggingUtil) Map(java.util.Map) RoboContext(com.robo4j.core.RoboContext) KEY_WIDTH(com.robo4j.units.rpi.camera.RaspistillUtils.KEY_WIDTH) Configuration(com.robo4j.core.configuration.Configuration) DEFAULT(com.robo4j.units.rpi.camera.RaspistillUtils.DEFAULT) Constants(com.robo4j.core.httpunit.Constants) LifecycleState(com.robo4j.core.LifecycleState) CameraClientException(com.robo4j.hw.rpi.camera.CameraClientException) KEY_ROTATION(com.robo4j.units.rpi.camera.RaspistillUtils.KEY_ROTATION) KEY_EXPOSURE(com.robo4j.units.rpi.camera.RaspistillUtils.KEY_EXPOSURE) ConfigurationException(com.robo4j.core.ConfigurationException) UnknownHostException(java.net.UnknownHostException) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Base64(java.util.Base64) RaspistilDevice(com.robo4j.hw.rpi.camera.RaspistilDevice) KEY_BRIGHTNESS(com.robo4j.units.rpi.camera.RaspistillUtils.KEY_BRIGHTNESS) RoboHttpUtils(com.robo4j.core.client.util.RoboHttpUtils) UnsupportedEncodingException(java.io.UnsupportedEncodingException) UnknownHostException(java.net.UnknownHostException) HashMap(java.util.HashMap) Objects(java.util.Objects) InetAddress(java.net.InetAddress)

Example 3 with ConfigurationException

use of com.robo4j.core.ConfigurationException in project robo4j by Robo4J.

the class TestClientImageController method onInitialization.

@Override
protected void onInitialization(Configuration configuration) throws ConfigurationException {
    SimpleLoggingUtil.print(getClass(), "camera client init");
    Map<String, String> parameters = new HashMap<>();
    //64
    parameters.put(KEY_WIDTH, configuration.getString(KEY_WIDTH, "320"));
    //45
    parameters.put(KEY_HEIGHT, configuration.getString(KEY_HEIGHT, "240"));
    StringBuilder sb = new StringBuilder(RASPI_CAMERA).append(SPACE).append(parameters.entrySet().stream().map(e -> {
        StringBuilder c = new StringBuilder();
        if (raspistillProperties.containsKey(e.getKey())) {
            return c.append(raspistillProperties.get(e.getKey())).append(SPACE).append(e.getValue()).toString();
        }
        return null;
    }).filter(Objects::nonNull).collect(Collectors.joining(SPACE))).append(SPACE).append(DEFAULT_SETUP);
    cameraCommand = sb.toString();
    SimpleLoggingUtil.print(getClass(), "camera cameraCommand: " + cameraCommand);
    targetOut = configuration.getString("targetOut", null);
    String tmpClient = configuration.getString("client", null);
    if (tmpClient == null || targetOut == null) {
        throw ConfigurationException.createMissingConfigNameException("targetOut, client");
    }
    try {
        InetAddress inetAddress = InetAddress.getByName(tmpClient);
        String clientPort = configuration.getString("clientPort", null);
        client = clientPort == null ? inetAddress.getHostAddress() : inetAddress.getHostAddress().concat(":").concat(clientPort);
        clientUri = configuration.getString("clientUri", Constants.EMPTY_STRING);
    } catch (UnknownHostException e) {
        SimpleLoggingUtil.error(getClass(), "unknown ip address", e);
        throw ConfigurationException.createMissingConfigNameException("unknown ip address");
    }
}
Also used : LifecycleState(com.robo4j.core.LifecycleState) CameraMessageCodec(com.robo4j.core.httpunit.codec.CameraMessageCodec) IOException(java.io.IOException) HashMap(java.util.HashMap) ConfigurationException(com.robo4j.core.ConfigurationException) UnknownHostException(java.net.UnknownHostException) Collectors(java.util.stream.Collectors) RoboUnit(com.robo4j.core.RoboUnit) InetAddress(java.net.InetAddress) Objects(java.util.Objects) Base64(java.util.Base64) RoboHttpUtils(com.robo4j.core.client.util.RoboHttpUtils) CameraMessage(com.robo4j.core.httpunit.codec.CameraMessage) PropertyMapBuilder(com.robo4j.core.httpunit.test.util.PropertyMapBuilder) RoboClassLoader(com.robo4j.core.client.util.RoboClassLoader) SimpleLoggingUtil(com.robo4j.core.logging.SimpleLoggingUtil) Map(java.util.Map) RoboContext(com.robo4j.core.RoboContext) Configuration(com.robo4j.core.configuration.Configuration) Constants(com.robo4j.core.httpunit.Constants) InputStream(java.io.InputStream) UnknownHostException(java.net.UnknownHostException) HashMap(java.util.HashMap) Objects(java.util.Objects) InetAddress(java.net.InetAddress)

Example 4 with ConfigurationException

use of com.robo4j.core.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);
    Float3D offsets = readFloat3D(configuration.getChildConfiguration("offsets"));
    Float3D 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) Float3D(com.robo4j.math.geometry.Float3D) ConfigurationException(com.robo4j.core.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 5 with ConfigurationException

use of com.robo4j.core.ConfigurationException in project robo4j by Robo4J.

the class GPSUnit method onInitialization.

@Override
protected void onInitialization(Configuration configuration) throws ConfigurationException {
    readInterval = configuration.getInteger("readInterval", DEFAULT_READ_INTERVAL);
    String scheduler = configuration.getString("scheduler", PROPERTY_VALUE_PLATFORM_SCHEDULER);
    boolean usePlatformScheduler = PROPERTY_VALUE_PLATFORM_SCHEDULER.equals(scheduler) ? true : false;
    try {
        gps = new GPS(readInterval);
    } catch (IOException e) {
        throw new ConfigurationException("Could not instantiate GPS!", e);
    }
    if (usePlatformScheduler) {
        scheduledFuture = getContext().getScheduler().scheduleAtFixedRate(new Runnable() {

            @Override
            public void run() {
                gps.update();
            }
        }, 10, readInterval, TimeUnit.MILLISECONDS);
    } else {
        gps.startAutoUpdate();
    }
}
Also used : ConfigurationException(com.robo4j.core.ConfigurationException) GPS(com.robo4j.hw.rpi.serial.gps.GPS) 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