Skip to content

Commit

Permalink
HIL: send time from host
Browse files Browse the repository at this point in the history
Usually GPS delivers time, therefore in HITL, the host computer should
send it.
  • Loading branch information
julianoes authored and LorenzMeier committed Feb 23, 2018
1 parent aabbecd commit 2dc3ced
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/me/drton/jmavsim/MAVLinkHILSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.TimeZone;

/**
* MAVLinkHILSystem is MAVLink bridge between AbstractVehicle and autopilot connected via MAVLink.
Expand All @@ -26,6 +28,7 @@ public class MAVLinkHILSystem extends MAVLinkSystem {
false; //prefer HIL_ACTUATOR_CONTROLS in case we get both messages
private long hilStateUpdateInterval = -1; //don't publish by default
private long nextHilStatePub = 0;
private long timeThrottleCounter = 0;

/**
* Create MAVLinkHILSimulator, MAVLink system that sends simulated sensors to autopilot and passes controls from
Expand Down Expand Up @@ -245,6 +248,16 @@ public void update(long t) {
sendMessage(msg_gps);
}
}

// SYSTEM TIME from host
if (timeThrottleCounter++ % 1000 == 0) {
System.out.println("Sending time");
MAVLinkMessage msg_system_time = new MAVLinkMessage(schema, "SYSTEM_TIME", sysId, componentId, protocolVersion);
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
msg_system_time.set("time_unix_usec", cal.getTimeInMillis() * 1000);
msg_system_time.set("time_boot_ms", tu/1000);
sendMessage(msg_system_time);
}
}

}

0 comments on commit 2dc3ced

Please sign in to comment.