2015-05-02 05:09:30 -03:00
|
|
|
/// -*- 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
parent class for aircraft simulators
|
|
|
|
*/
|
|
|
|
|
2015-05-02 07:28:57 -03:00
|
|
|
#ifndef _SIM_AIRCRAFT_H
|
|
|
|
#define _SIM_AIRCRAFT_H
|
|
|
|
|
2015-05-02 05:09:30 -03:00
|
|
|
#include "SITL.h"
|
2015-08-11 03:28:46 -03:00
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include <AP_Math/AP_Math.h>
|
2015-05-02 05:09:30 -03:00
|
|
|
|
|
|
|
/*
|
|
|
|
parent class for all simulator types
|
|
|
|
*/
|
2015-05-04 22:49:54 -03:00
|
|
|
class Aircraft
|
2015-05-02 05:09:30 -03:00
|
|
|
{
|
|
|
|
public:
|
2015-05-03 04:47:58 -03:00
|
|
|
Aircraft(const char *home_str, const char *frame_str);
|
2015-05-02 05:09:30 -03:00
|
|
|
|
|
|
|
/*
|
|
|
|
structure passed in giving servo positions as PWM values in
|
|
|
|
microseconds
|
|
|
|
*/
|
|
|
|
struct sitl_input {
|
|
|
|
uint16_t servos[16];
|
2015-05-22 22:03:57 -03:00
|
|
|
struct {
|
|
|
|
float speed; // m/s
|
|
|
|
float direction; // degrees 0..360
|
2015-06-28 22:25:59 -03:00
|
|
|
float turbulence;
|
2015-05-22 22:03:57 -03:00
|
|
|
} wind;
|
2015-05-02 05:09:30 -03:00
|
|
|
};
|
|
|
|
|
2015-05-02 08:41:33 -03:00
|
|
|
/*
|
|
|
|
set simulation speedup
|
|
|
|
*/
|
|
|
|
void set_speedup(float speedup);
|
|
|
|
|
2015-05-10 08:01:49 -03:00
|
|
|
/*
|
|
|
|
set instance number
|
|
|
|
*/
|
|
|
|
void set_instance(uint8_t _instance) {
|
|
|
|
instance = _instance;
|
|
|
|
}
|
|
|
|
|
2015-05-25 00:04:46 -03:00
|
|
|
/*
|
|
|
|
set directory for additional files such as aircraft models
|
|
|
|
*/
|
|
|
|
void set_autotest_dir(const char *_autotest_dir) {
|
|
|
|
autotest_dir = _autotest_dir;
|
|
|
|
}
|
|
|
|
|
2015-05-02 05:09:30 -03:00
|
|
|
/*
|
|
|
|
step the FDM by one time step
|
|
|
|
*/
|
|
|
|
virtual void update(const struct sitl_input &input) = 0;
|
|
|
|
|
|
|
|
/* fill a sitl_fdm structure from the simulator state */
|
|
|
|
void fill_fdm(struct sitl_fdm &fdm) const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Location home;
|
|
|
|
Location location;
|
|
|
|
|
|
|
|
float ground_level;
|
|
|
|
float frame_height;
|
|
|
|
Matrix3f dcm; // rotation matrix, APM conventions, from body to earth
|
|
|
|
Vector3f gyro; // rad/s
|
|
|
|
Vector3f velocity_ef; // m/s, earth frame
|
|
|
|
Vector3f position; // meters, NED from origin
|
|
|
|
float mass; // kg
|
|
|
|
Vector3f accel_body; // m/s/s NED, body frame
|
2015-05-22 22:24:10 -03:00
|
|
|
float airspeed; // m/s, apparent airspeed
|
2015-05-02 05:09:30 -03:00
|
|
|
|
|
|
|
uint64_t time_now_us;
|
|
|
|
|
|
|
|
const float gyro_noise;
|
|
|
|
const float accel_noise;
|
|
|
|
float rate_hz;
|
|
|
|
float achieved_rate_hz;
|
|
|
|
float target_speedup;
|
2015-05-02 09:13:02 -03:00
|
|
|
uint64_t frame_time_us;
|
2015-05-02 05:09:30 -03:00
|
|
|
float scaled_frame_time_us;
|
|
|
|
uint64_t last_wall_time_us;
|
2015-05-10 08:01:49 -03:00
|
|
|
uint8_t instance;
|
2015-05-25 00:04:46 -03:00
|
|
|
const char *autotest_dir;
|
2015-06-01 20:08:55 -03:00
|
|
|
const char *frame;
|
2015-05-02 05:09:30 -03:00
|
|
|
|
|
|
|
bool on_ground(const Vector3f &pos) const;
|
|
|
|
|
|
|
|
/* update location from position */
|
|
|
|
void update_position(void);
|
|
|
|
|
|
|
|
/* rotate to the given yaw */
|
|
|
|
void set_yaw_degrees(float yaw_degrees);
|
2015-05-04 22:49:54 -03:00
|
|
|
|
2015-05-02 05:09:30 -03:00
|
|
|
/* advance time by deltat in seconds */
|
|
|
|
void time_advance(float deltat);
|
|
|
|
|
|
|
|
/* setup the frame step time */
|
|
|
|
void setup_frame_time(float rate, float speedup);
|
|
|
|
|
|
|
|
/* adjust frame_time calculation */
|
|
|
|
void adjust_frame_time(float rate);
|
|
|
|
|
|
|
|
/* try to synchronise simulation time with wall clock time, taking
|
|
|
|
into account desired speedup */
|
|
|
|
void sync_frame_time(void);
|
|
|
|
|
|
|
|
/* add noise based on throttle level (from 0..1) */
|
|
|
|
void add_noise(float throttle);
|
|
|
|
|
|
|
|
/* return wall clock time in microseconds since 1970 */
|
|
|
|
uint64_t get_wall_time_us(void) const;
|
|
|
|
|
|
|
|
/* return normal distribution random numbers */
|
|
|
|
double rand_normal(double mean, double stddev);
|
2015-05-05 08:28:38 -03:00
|
|
|
|
|
|
|
private:
|
2015-07-05 20:21:49 -03:00
|
|
|
uint64_t last_time_us = 0;
|
|
|
|
uint32_t frame_counter = 0;
|
2015-05-25 03:48:13 -03:00
|
|
|
const uint32_t min_sleep_time;
|
2015-05-02 05:09:30 -03:00
|
|
|
};
|
2015-05-02 07:28:57 -03:00
|
|
|
|
|
|
|
#endif // _SIM_AIRCRAFT_H
|
|
|
|
|