Search in sources :

Example 1 with DataEvent3f

use of com.robo4j.hw.rpi.imu.bno.DataEvent3f in project robo4j by Robo4J.

the class Bno080AccelerometerExample method main.

public static void main(String[] args) throws Exception {
    DataListener listener = (DataEvent3f event) -> System.out.println("ShtpPacketResponse: " + event);
    System.out.println("BNO080 SPI Accelerometer Example");
    // Change here to use other modes of communication
    Bno080Device device = Bno080Factory.createDefaultSPIDevice();
    device.addListener(listener);
    device.start(SensorReportId.ACCELEROMETER, 100);
    System.out.println("Press <Enter> to quit!");
    System.in.read();
    device.shutdown();
}
Also used : Bno080Device(com.robo4j.hw.rpi.imu.bno.Bno080Device) DataEvent3f(com.robo4j.hw.rpi.imu.bno.DataEvent3f) DataListener(com.robo4j.hw.rpi.imu.bno.DataListener)

Example 2 with DataEvent3f

use of com.robo4j.hw.rpi.imu.bno.DataEvent3f in project robo4j by Robo4J.

the class Bno080SPIDevice method createDataEvent.

private DataEvent3f createDataEvent(DataEventType type, long timeStamp, int... data) {
    if (data == null || data.length < 4) {
        return EMPTY_EVENT;
    }
    final int status = data[0] & 0xFFFF;
    final int x = data[1] & 0xFFFF;
    final int y = data[2] & 0xFFFF;
    final int z = data[3] & 0xFFFF;
    final Tuple3f tuple3f = ShtpUtils.createTupleFromFixed(type.getQ(), x, y, z);
    return new DataEvent3f(type, status, tuple3f, timeStamp);
}
Also used : Tuple3f(com.robo4j.math.geometry.Tuple3f) DataEvent3f(com.robo4j.hw.rpi.imu.bno.DataEvent3f)

Example 3 with DataEvent3f

use of com.robo4j.hw.rpi.imu.bno.DataEvent3f in project robo4j by Robo4J.

the class Bno080Example method main.

public static void main(String[] args) throws Exception {
    DataListener listener = (DataEvent3f event) -> System.out.println("ShtpPacketResponse: " + event);
    System.out.println("BNO080 SPI Rotation Vector Example");
    // Change here to use other modes of communication
    Bno080Device device = Bno080Factory.createDefaultSPIDevice();
    device.addListener(listener);
    device.start(SensorReportId.ROTATION_VECTOR, 1000);
    System.out.println("Press <Enter> to quit!");
    System.in.read();
    device.shutdown();
}
Also used : Bno080Device(com.robo4j.hw.rpi.imu.bno.Bno080Device) DataEvent3f(com.robo4j.hw.rpi.imu.bno.DataEvent3f) DataListener(com.robo4j.hw.rpi.imu.bno.DataListener)

Example 4 with DataEvent3f

use of com.robo4j.hw.rpi.imu.bno.DataEvent3f in project robo4j by Robo4J.

the class VectorEventListenerExample method main.

public static void main(String[] args) throws Exception {
    final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    final InputStream systemIS;
    final InputStream contextIS;
    switch(args.length) {
        case 0:
            systemIS = classLoader.getResourceAsStream("bno080VectorSystemEmitterExample.xml");
            contextIS = classLoader.getResourceAsStream("bno080VectorExample.xml");
            System.out.println("Default configuration used");
            break;
        case 1:
            systemIS = classLoader.getResourceAsStream("bno080VectorSystemEmitterExample.xml");
            Path contextPath = Paths.get(args[0]);
            contextIS = Files.newInputStream(contextPath);
            System.out.println("Robo4j config file has been used: " + args[0]);
            break;
        case 2:
            Path systemPath2 = Paths.get(args[0]);
            Path contextPath2 = Paths.get(args[1]);
            systemIS = Files.newInputStream(systemPath2);
            contextIS = Files.newInputStream(contextPath2);
            System.out.println(String.format("Custom configuration used system: %s, context: %s", args[0], args[1]));
            break;
        default:
            System.out.println("Could not find the *.xml settings for the CameraClient!");
            System.out.println("java -jar camera.jar system.xml context.xml");
            System.exit(2);
            throw new IllegalStateException("see configuration");
    }
    if (systemIS == null && contextIS == null) {
        System.out.println("Could not find the settings for the BNO080 Example!");
        System.exit(2);
    }
    RoboBuilder builder = new RoboBuilder(systemIS);
    builder.add(contextIS);
    RoboContext ctx = builder.build();
    ctx.start();
    LookupService service = LookupServiceProvider.getDefaultLookupService();
    try {
        service.start();
    } catch (IOException e) {
        e.printStackTrace();
    }
    System.out.println("State after start:");
    System.out.println(SystemUtil.printStateReport(ctx));
    RoboReference<BnoRequest> bnoUnit = ctx.getReference("bno");
    RoboReference<DataEvent3f> bnoListenerUnit = ctx.getReference("listener");
    BnoRequest requestToRegister = new BnoRequest(bnoListenerUnit, BnoRequest.ListenerAction.REGISTER);
    bnoUnit.sendMessage(requestToRegister);
    System.out.println("Press <Enter> to start!");
    System.in.read();
    ctx.shutdown();
}
Also used : Path(java.nio.file.Path) LookupService(com.robo4j.net.LookupService) InputStream(java.io.InputStream) DataEvent3f(com.robo4j.hw.rpi.imu.bno.DataEvent3f) RoboBuilder(com.robo4j.RoboBuilder) RoboContext(com.robo4j.RoboContext) IOException(java.io.IOException) BnoRequest(com.robo4j.units.rpi.imu.BnoRequest)

Example 5 with DataEvent3f

use of com.robo4j.hw.rpi.imu.bno.DataEvent3f in project robo4j by Robo4J.

the class DataEventListenerExample method main.

public static void main(String[] args) throws Exception {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    final InputStream systemIS;
    final InputStream contextIS;
    switch(args.length) {
        case 0:
            systemIS = classLoader.getResourceAsStream("bno080DataSystemEmitterExample.xml");
            contextIS = classLoader.getResourceAsStream("bno080GyroExample.xml");
            System.out.println("Default configuration used");
            break;
        case 1:
            systemIS = classLoader.getResourceAsStream("bno080DataSystemEmitterExample.xml");
            Path contextPath = Paths.get(args[0]);
            contextIS = Files.newInputStream(contextPath);
            System.out.println("Robo4j config file has been used: " + args[0]);
            break;
        case 2:
            Path systemPath2 = Paths.get(args[0]);
            Path contextPath2 = Paths.get(args[1]);
            systemIS = Files.newInputStream(systemPath2);
            contextIS = Files.newInputStream(contextPath2);
            System.out.println(String.format("Custom configuration used system: %s, context: %s", args[0], args[1]));
            break;
        default:
            System.out.println("Could not find the *.xml settings for the CameraClient!");
            System.out.println("java -jar camera.jar system.xml context.xml");
            System.exit(2);
            throw new IllegalStateException("see configuration");
    }
    RoboBuilder builder = new RoboBuilder(systemIS);
    builder.add(contextIS);
    RoboContext ctx = builder.build();
    ctx.start();
    System.out.println("State after start:");
    System.out.println(SystemUtil.printStateReport(ctx));
    RoboReference<BnoRequest> bnoUnit = ctx.getReference("bno");
    RoboReference<DataEvent3f> bnoListenerUnit = ctx.getReference("listener");
    BnoRequest requestToRegister = new BnoRequest(bnoListenerUnit, BnoRequest.ListenerAction.REGISTER);
    bnoUnit.sendMessage(requestToRegister);
    System.out.println("Press <Enter> to start!");
    System.in.read();
    ctx.shutdown();
}
Also used : Path(java.nio.file.Path) InputStream(java.io.InputStream) DataEvent3f(com.robo4j.hw.rpi.imu.bno.DataEvent3f) RoboBuilder(com.robo4j.RoboBuilder) RoboContext(com.robo4j.RoboContext) BnoRequest(com.robo4j.units.rpi.imu.BnoRequest)

Aggregations

DataEvent3f (com.robo4j.hw.rpi.imu.bno.DataEvent3f)5 RoboBuilder (com.robo4j.RoboBuilder)2 RoboContext (com.robo4j.RoboContext)2 Bno080Device (com.robo4j.hw.rpi.imu.bno.Bno080Device)2 DataListener (com.robo4j.hw.rpi.imu.bno.DataListener)2 BnoRequest (com.robo4j.units.rpi.imu.BnoRequest)2 InputStream (java.io.InputStream)2 Path (java.nio.file.Path)2 Tuple3f (com.robo4j.math.geometry.Tuple3f)1 LookupService (com.robo4j.net.LookupService)1 IOException (java.io.IOException)1