34 pthread_mutex_t clock_mutex;
37 pthread_mutex_lock(&clock_mutex);
40 host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
41 clock_get_time(cclock, &mts);
42 mach_port_deallocate(mach_task_self(), cclock);
43 ts->tv_sec = mts.tv_sec;
44 ts->tv_nsec = mts.tv_nsec;
45 pthread_mutex_unlock(&clock_mutex);
53 signal(SIGTSTP, SIG_DFL);
65 printf(
"Press <enter> to continue.\n");
71 return ((
double)t->tv_sec + (
double)(t->tv_usec * 1e-6));
76 return ((
double)t->tv_sec + (
double)(t->tv_nsec * 1e-9));
96 gettimeofday(&t, NULL);
103 printf(
"Simulating with dt of %f\n",
SIM_DT);
108 printf(
"host_time_factor,host_time_elapsed,host_time_now,scaled_initial_time,sim_time_before,display_time_before,sim_time_after,display_time_after\n");
121 if (time_factor < 0.0 || time_factor > 100.0) {
128 struct timeval tv_now;
129 double t_now, t_elapsed;
131 gettimeofday(&tv_now, NULL);
162 static const char *usage =
163 "Usage: %s [options]\n"
165 " -h Display this help\n"
166 " --fg_host <flight gear host> e.g. 127.0.0.1\n"
167 " --fg_port <flight gear port> e.g. 5501\n"
168 " --fg_port_in <flight gear in port> e.g. 5502\n"
169 " --fg_time_offset <offset in seconds> e.g. 21600 for 6h\n"
170 " -j --js_dev <optional joystick index> e.g. 1 (default 0)\n"
171 " --spektrum_dev <spektrum device> e.g. /dev/ttyUSB0\n"
172 " --rc_script <number> e.g. 0\n"
173 " --norc e.g. disable RC\n"
174 " --ivy_bus <ivy bus> e.g. 127.255.255.255\n"
175 " --time_factor <factor> e.g. 2.5\n"
181 static struct option long_options[] = {
182 {
"fg_host", 1, NULL, 0},
183 {
"fg_port", 1, NULL, 0},
184 {
"fg_time_offset", 1, NULL, 0},
185 {
"js_dev", 2, NULL, 0},
186 {
"spektrum_dev", 1, NULL, 0},
187 {
"rc_script", 1, NULL, 0},
188 {
"norc", 0, NULL, 0},
189 {
"ivy_bus", 1, NULL, 0},
190 {
"time_factor", 1, NULL, 0},
191 {
"fg_fdm", 0, NULL, 0},
192 {
"fg_port_in", 1, NULL, 0},
195 int option_index = 0;
196 int c = getopt_long(argc, argv,
"jh",
197 long_options, &option_index);
204 switch (option_index) {
238 fprintf(stderr, usage, argv[0]);
242 printf(
"?? getopt returned character code 0%o ??\n", c);
243 fprintf(stderr, usage, argv[0]);
253 struct timespec requestStart;
254 struct timespec requestEnd;
255 struct timespec waitFor;
256 long int period_ns =
DISPLAY_DT * 1000000000L;
257 long int task_ns = 0;
278 task_ns = (requestEnd.tv_sec - requestStart.tv_sec) * 1000000000L + (requestEnd.tv_nsec - requestStart.tv_nsec);
281 if (task_ns < period_ns) {
283 waitFor.tv_nsec = period_ns - task_ns;
284 nanosleep(&waitFor, NULL);
288 printf(
"FG THREAD: task took longer than one period, exactly %f [ms], but the period is %f [ms]\n",
289 (
double)task_ns / 1E6, (
double)period_ns / 1E6);
301 struct timespec requestStart;
302 struct timespec requestEnd;
303 struct timespec waitFor;
304 long int period_ns = 3 *
DISPLAY_DT * 1000000000L;
305 long int task_ns = 0;
316 memcpy(&fdm_ivy, &
fdm,
sizeof(
fdm));
325 task_ns = (requestEnd.tv_sec - requestStart.tv_sec) * 1000000000L + (requestEnd.tv_nsec - requestStart.tv_nsec);
328 if (task_ns < period_ns) {
330 waitFor.tv_nsec = period_ns - task_ns;
331 nanosleep(&waitFor, NULL);
335 printf(
"IVY DISPLAY THREAD: task took longer than one period, exactly %f [ms], but the period is %f [ms]\n",
336 (
double)task_ns / 1E6, (
double)period_ns / 1E6);
void nps_flightgear_send_fdm()
Send FlightGear FDM packet For visualization with moving surfaces (elevator, propeller etc)...
pthread_mutex_t fdm_mutex
struct NpsFdm fdm
Holds all necessary NPS FDM state information.
void nps_ivy_init(char *ivy_bus)
int nps_main_init(int argc, char **argv)
bool nps_main_parse_options(int argc, char **argv)
#define clock_get_current_time(_x)
double ntime_to_double(struct timespec *t)
double scaled_initial_time
unsigned int fg_time_offset
void nps_ivy_display(struct NpsFdm *fdm_data, struct NpsSensors *sensors_data)
void nps_flightgear_init(const char *host, unsigned int port, unsigned int port_in, unsigned int time_offset)
struct NpsSensors sensors
void nps_fdm_init(double dt)
Set JSBsim specific fields that are not used for Gazebo.
void nps_flightgear_send()
Send FlightGear GUI packet For visualization of airplane position and attitude only start fgfs with â€...
void * nps_main_display(void *data)
void nps_radio_and_autopilot_init(void)
void nps_set_time_factor(float time_factor)
double time_to_double(struct timeval *t)
void * nps_flight_gear_loop(void *data)
void nps_atmosphere_init(void)
void nps_sensors_init(double time)