Search in sources :

Example 1 with Float3D

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

the class ContinuousGyroNotificationEntry method addDelta.

@Override
public void addDelta(Float3D data) {
    getDelta().add(data);
    Float3D diff = getDelta().diff(lastReported);
    if (Math.abs(diff.x) > deltaToNotify.x || Math.abs(diff.y) > deltaToNotify.y || Math.abs(diff.z) > deltaToNotify.z) {
        Float3D reportedInstance = getDelta().copy();
        lastReported.set(reportedInstance);
        report(reportedInstance);
    }
}
Also used : Float3D(com.robo4j.math.geometry.Float3D)

Example 2 with Float3D

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

the class GyroExample method main.

public static void main(String[] args) throws RoboBuilderException, IOException {
    RoboBuilder builder = new RoboBuilder();
    InputStream settings = GyroExample.class.getClassLoader().getResourceAsStream("gyroexample.xml");
    if (settings == null) {
        System.out.println("Could not find the settings for the GyroExample!");
        System.exit(2);
    }
    builder.add(settings);
    builder.add(GyroProcessor.class, ID_PROCESSOR);
    RoboContext ctx = builder.build();
    System.out.println("State before start:");
    System.out.println(SystemUtil.printStateReport(ctx));
    ctx.start();
    System.out.println("State after start:");
    System.out.println(SystemUtil.printStateReport(ctx));
    RoboReference<GyroRequest> gyro = ctx.getReference("gyro");
    RoboReference<GyroEvent> processor = ctx.getReference(ID_PROCESSOR);
    System.out.println("Let the gyro unit be absolutely still, then press enter to calibrate and start!");
    System.in.read();
    gyro.sendMessage(new GyroRequest(processor, true, true, new Float3D(1.0f, 1.0f, 1.0f)));
    System.out.println("Will report angular changes indefinitely.\nPress enter to quit!");
    System.in.read();
}
Also used : Float3D(com.robo4j.math.geometry.Float3D) InputStream(java.io.InputStream) RoboBuilder(com.robo4j.core.RoboBuilder) RoboContext(com.robo4j.core.RoboContext)

Example 3 with Float3D

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

the class MagnetometerLSM303Device method read.

public synchronized Float3D read() throws IOException {
    Float3D rawData = new Float3D();
    byte[] data = new byte[6];
    int n = i2cDevice.read(OUT_X_H_M, data, 0, 6);
    if (n != 6) {
        getLogger().warning("Failed to read all data from accelerometer. Should have read 6, could only read " + n);
    }
    rawData.x = read16bitSigned(data, 0) / gain.getXY();
    rawData.y = read16bitSigned(data, 2) / gain.getXY();
    rawData.z = read16bitSigned(data, 4) / gain.getZ();
    return rawData;
}
Also used : Float3D(com.robo4j.math.geometry.Float3D)

Example 4 with Float3D

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

the class AccelerometerLSM303Test method readValues.

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

Example 5 with Float3D

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

the class CalibratedFloat3DDevice method read.

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

Aggregations

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