Search in sources :

Example 1 with AccelerometerLSM303Device

use of com.robo4j.hw.rpi.i2c.accelerometer.AccelerometerLSM303Device 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)

Aggregations

ConfigurationException (com.robo4j.core.ConfigurationException)1 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 Float3D (com.robo4j.math.geometry.Float3D)1 IOException (java.io.IOException)1