Search in sources :

Example 11 with Tuple3f

use of com.robo4j.math.geometry.Tuple3f in project robo4j by Robo4J.

the class CalibratedFloat3DDevice method read.

public Tuple3f read() throws IOException {
    Tuple3f value = device.read();
    value.add(centerOffsets);
    value.multiply(rangeMultipliers);
    return value;
}
Also used : Tuple3f(com.robo4j.math.geometry.Tuple3f)

Example 12 with Tuple3f

use of com.robo4j.math.geometry.Tuple3f in project robo4j by Robo4J.

the class AccelerometerLSM303Device method read.

/**
 * @return current acceleration, m/s^2
 * @throws IOException
 *             exception
 */
public synchronized Tuple3f read() throws IOException {
    Tuple3f rawData = new Tuple3f();
    byte[] data = new byte[6];
    int n = i2cDevice.read(OUT_X_L_A | 0x80, data, 0, 6);
    if (n != 6) {
        getLogger().warning("Failed to read all data from accelerometer. Should have read 6, could only read " + n);
    }
    float k = scale.getSensitivity() / 1000.0f;
    rawData.x = read12bitSigned(data, 0) * k;
    rawData.y = read12bitSigned(data, 2) * k;
    rawData.z = read12bitSigned(data, 4) * k;
    return rawData;
}
Also used : Tuple3f(com.robo4j.math.geometry.Tuple3f)

Example 13 with Tuple3f

use of com.robo4j.math.geometry.Tuple3f in project robo4j by Robo4J.

the class CalibratedGyro method calibrate.

/**
 * Does calibration.
 *
 * @throws IOException
 *             exception
 */
public void calibrate() throws IOException {
    setCalibration(new Tuple3f(), Tuple3f.createIdentity());
    float[] xvalues = new float[NUMBER_OF_CALIBRATION_READINGS];
    float[] yvalues = new float[NUMBER_OF_CALIBRATION_READINGS];
    float[] zvalues = new float[NUMBER_OF_CALIBRATION_READINGS];
    for (int i = 0; i < NUMBER_OF_CALIBRATION_READINGS; i++) {
        Tuple3f tmp = read();
        xvalues[i] = tmp.x;
        yvalues[i] = tmp.y;
        zvalues[i] = tmp.z;
        sleep(20);
    }
    Tuple3f calibration = new Tuple3f();
    calibration.x = calibrate(xvalues, NUMBER_OF_CALIBRATION_READINGS_TO_DROP);
    calibration.y = calibrate(yvalues, NUMBER_OF_CALIBRATION_READINGS_TO_DROP);
    calibration.z = calibrate(zvalues, NUMBER_OF_CALIBRATION_READINGS_TO_DROP);
    System.out.println(RANGE_MULTIPLIERS);
    setCalibration(calibration, RANGE_MULTIPLIERS);
}
Also used : Tuple3f(com.robo4j.math.geometry.Tuple3f)

Example 14 with Tuple3f

use of com.robo4j.math.geometry.Tuple3f in project robo4j by Robo4J.

the class AccelerometerLSM303Test method readValues.

private static Stats readValues(ReadableDevice<Tuple3f> device) throws IOException, InterruptedException {
    Stats stats = new Stats();
    for (int i = 0; i < 250; i++) {
        Tuple3f fl = device.read();
        stats.addValue(fl);
        Thread.sleep(20);
        if (i % 25 == 0) {
            System.out.print(".");
        }
    }
    System.out.println("");
    return stats;
}
Also used : Tuple3f(com.robo4j.math.geometry.Tuple3f)

Aggregations

Tuple3f (com.robo4j.math.geometry.Tuple3f)14 ConfigurationException (com.robo4j.ConfigurationException)1 RoboBuilder (com.robo4j.RoboBuilder)1 RoboContext (com.robo4j.RoboContext)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 DataEvent3f (com.robo4j.hw.rpi.imu.bno.DataEvent3f)1 VectorEvent (com.robo4j.hw.rpi.imu.bno.VectorEvent)1 Matrix3f (com.robo4j.math.geometry.Matrix3f)1 Tuple3i (com.robo4j.math.geometry.Tuple3i)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1