public void read() { long timestamp = RealtimeThread.getCurrentMonotonicClockTime(); sensorReader.read(timestamp); sensorReader.run(); // Magic jitter fix // monotonicTime.set(0, timestamp + 500000); // RealtimeThread.getCurrentRealtimeThread().waitUntil(monotonicTime); sensorReader.write(RealtimeThread.getCurrentMonotonicClockTime()); }
@Override public void read() { long timestamp = RealtimeThread.getCurrentMonotonicClockTime(); sensorReader.read(timestamp); sensorReader.run(); // Magic jitter fix // monotonicTime.set(0, timestamp + 500000); // RealtimeThread.getCurrentRealtimeThread().waitUntil(monotonicTime); sensorReader.write(RealtimeThread.getCurrentMonotonicClockTime()); }
/** * Receive data from steppr * @return Current time or -1 if invalid * @throws IOException */ public long receive() throws IOException { receiveBuffer.clear(); try { receiveChannel.receive(receiveBuffer); } catch (SocketTimeoutException e) { throw new RuntimeException(e); } receiveBuffer.flip(); if (receiveBuffer.remaining() != 1048) { throw new IOException("RegistryReceiveBuffer is not the correct size"); } long currentTime = RealtimeThread.getCurrentMonotonicClockTime(); state.update(receiveBuffer, currentTime); return currentTime; }
data.setFilterType(MicrostrainFilterType.COMPLIMENTARY_FILTER); long time = RealtimeThread.getCurrentMonotonicClockTime(); data.setReceiveTime(time);
data.setFilterType(MicrostrainFilterType.ADAPTIVE_EKF); long time = RealtimeThread.getCurrentMonotonicClockTime(); data.setReceiveTime(time);
@Override public void run() { while(true) { controller.read(RealtimeThread.getCurrentMonotonicClockTime()); controller.run(); controller.write(RealtimeThread.getCurrentMonotonicClockTime()); if(controller.nextWakeupTime() != Long.MIN_VALUE) { triggerTime.set(0, controller.nextWakeupTime()); waitUntil(triggerTime); } } }
@Override public void run() { while(true) { controller.read(RealtimeThread.getCurrentMonotonicClockTime()); controller.run(); long currentTime = RealtimeThread.getCurrentMonotonicClockTime(); controller.write(currentTime); // Checks if there is a non-zero sleep duration. If not, sleep for 0.1ms. This avoids busy waits and preempting kernel tasks. if(controller.nextWakeupTime() != Long.MIN_VALUE && controller.nextWakeupTime() >= currentTime) { triggerTime.set(0, controller.nextWakeupTime()); } else { triggerTime.setToCurrentTime(); triggerTime.add(defaultTriggerTime); } waitUntil(triggerTime); } } }