Search in sources :

Example 1 with VectorEvent

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

the class Bno080SPIDevice method createVectorEvent.

private DataEvent3f createVectorEvent(DataEventType type, long timeStamp, int... data) {
    if (data == null || data.length < 6) {
        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 int qReal = data[4] & 0xFFFF;
    // Only available on
    final int qRadianAccuracy = data[5] & 0xFFFF;
    // rotation vector, not
    // game rot vector
    final Tuple3f tuple3f = ShtpUtils.createTupleFromFixed(type.getQ(), x, y, z);
    return new VectorEvent(type, status, tuple3f, timeStamp, intToFloat(qReal, type.getQ()), intToFloat(qRadianAccuracy, type.getQ()));
}
Also used : Tuple3f(com.robo4j.math.geometry.Tuple3f) VectorEvent(com.robo4j.hw.rpi.imu.bno.VectorEvent)

Example 2 with VectorEvent

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

the class VectorEventListenerUnit method onMessage.

@Override
public void onMessage(VectorEvent message) {
    SimpleLoggingUtil.info(getClass(), "received:" + message);
    RoboContext remoteContext = LookupServiceProvider.getDefaultLookupService().getContext(targetContext);
    if (remoteContext != null) {
        RoboReference<VectorEvent> roboReference = remoteContext.getReference(remoteUnit);
        if (roboReference != null) {
            roboReference.sendMessage(message);
        }
    } else {
        SimpleLoggingUtil.info(getClass(), String.format("context not found: %s", targetContext));
    }
}
Also used : RoboContext(com.robo4j.RoboContext) VectorEvent(com.robo4j.hw.rpi.imu.bno.VectorEvent)

Aggregations

VectorEvent (com.robo4j.hw.rpi.imu.bno.VectorEvent)2 RoboContext (com.robo4j.RoboContext)1 Tuple3f (com.robo4j.math.geometry.Tuple3f)1