/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
/*
simulator connector for ardupilot version of JSBSim
*/
#include "SIM_JSBSim.h"
#include
#include
#include
#include
#include
#include
#include
extern const AP_HAL::HAL& hal;
namespace SITL {
// the asprintf() calls are not worth checking for SITL
#pragma GCC diagnostic ignored "-Wunused-result"
#define DEBUG_JSBSIM 1
#define FEET_TO_METERS 0.3048f
JSBSim::JSBSim(const char *home_str, const char *frame_str) :
Aircraft(home_str, frame_str),
sock_control(false),
sock_fgfdm(true),
initialised(false),
jsbsim_script(NULL),
jsbsim_fgout(NULL),
created_templates(false),
started_jsbsim(false),
opened_control_socket(false),
opened_fdm_socket(false),
frame(FRAME_NORMAL)
{
if (strstr(frame_str, "elevon")) {
frame = FRAME_ELEVON;
} else if (strstr(frame_str, "vtail")) {
frame = FRAME_VTAIL;
} else {
frame = FRAME_NORMAL;
}
const char *model_name = strchr(frame_str, ':');
if (model_name != NULL) {
jsbsim_model = model_name + 1;
}
}
/*
create template files
*/
bool JSBSim::create_templates(void)
{
if (created_templates) {
return true;
}
control_port = 5505 + instance*10;
fdm_port = 5504 + instance*10;
asprintf(&jsbsim_script, "%s/jsbsim_start_%u.xml", autotest_dir, instance);
asprintf(&jsbsim_fgout, "%s/jsbsim_fgout_%u.xml", autotest_dir, instance);
FILE *f = fopen(jsbsim_script, "w");
if (f == NULL) {
hal.scheduler->panic("Unable to create jsbsim script %s", jsbsim_script);
}
fprintf(f,
"\n"
"\n"
"\n"
"\n"
" \n"
" test ArduPlane using %s and JSBSim\n"
" \n"
"\n"
" \n"
"",
jsbsim_model,
jsbsim_model,
jsbsim_model,
control_port);
fclose(f);
f = fopen(jsbsim_fgout, "w");
if (f == NULL) {
hal.scheduler->panic("Unable to create jsbsim fgout script %s", jsbsim_fgout);
}
fprintf(f, "\n"
"