2015-05-02 05:09:30 -03:00
|
|
|
/*
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
/*
|
2015-05-03 04:47:58 -03:00
|
|
|
multicopter simulator class
|
2015-05-02 05:09:30 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SIM_Multicopter.h"
|
2016-02-07 19:58:56 -04:00
|
|
|
#include <AP_Motors/AP_Motors.h>
|
2015-10-22 10:58:33 -03:00
|
|
|
|
2015-05-02 05:09:30 -03:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2015-12-31 23:15:06 -04:00
|
|
|
using namespace SITL;
|
2015-05-02 05:09:30 -03:00
|
|
|
|
2016-02-01 20:34:29 -04:00
|
|
|
MultiCopter::MultiCopter(const char *home_str, const char *frame_str) :
|
|
|
|
Aircraft(home_str, frame_str),
|
2016-10-30 02:24:21 -03:00
|
|
|
frame(nullptr)
|
2016-02-01 20:34:29 -04:00
|
|
|
{
|
2016-10-27 03:12:09 -03:00
|
|
|
mass = 1.5f;
|
|
|
|
|
2016-02-01 20:34:29 -04:00
|
|
|
frame = Frame::find_frame(frame_str);
|
2016-10-30 02:24:21 -03:00
|
|
|
if (frame == nullptr) {
|
2015-05-02 05:09:30 -03:00
|
|
|
printf("Frame '%s' not found", frame_str);
|
|
|
|
exit(1);
|
|
|
|
}
|
2016-10-27 03:12:09 -03:00
|
|
|
// initial mass is passed through to Frame for it to calculate a
|
|
|
|
// hover thrust requirement.
|
2016-04-27 21:05:04 -03:00
|
|
|
if (strstr(frame_str, "-fast")) {
|
2016-10-27 03:12:09 -03:00
|
|
|
frame->init(gross_mass(), 0.5, 85, 4*radians(360));
|
2016-04-27 21:05:04 -03:00
|
|
|
} else {
|
2016-10-27 03:12:09 -03:00
|
|
|
frame->init(gross_mass(), 0.51, 15, 4*radians(360));
|
2016-04-27 21:05:04 -03:00
|
|
|
}
|
2015-05-02 05:09:30 -03:00
|
|
|
frame_height = 0.1;
|
2016-07-19 01:42:31 -03:00
|
|
|
ground_behavior = GROUND_BEHAVIOR_NO_MOVEMENT;
|
2015-05-02 05:09:30 -03:00
|
|
|
}
|
|
|
|
|
2015-12-31 23:15:06 -04:00
|
|
|
// calculate rotational and linear accelerations
|
|
|
|
void MultiCopter::calculate_forces(const struct sitl_input &input, Vector3f &rot_accel, Vector3f &body_accel)
|
|
|
|
{
|
|
|
|
frame->calculate_forces(*this, input, rot_accel, body_accel);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
update the multicopter simulation by one time step
|
|
|
|
*/
|
|
|
|
void MultiCopter::update(const struct sitl_input &input)
|
|
|
|
{
|
2016-04-19 22:48:37 -03:00
|
|
|
// get wind vector setup
|
|
|
|
update_wind(input);
|
|
|
|
|
2015-12-31 23:15:06 -04:00
|
|
|
Vector3f rot_accel;
|
|
|
|
|
|
|
|
calculate_forces(input, rot_accel, accel_body);
|
2015-05-02 05:09:30 -03:00
|
|
|
|
2016-01-01 00:11:55 -04:00
|
|
|
update_dynamics(rot_accel);
|
2018-07-31 09:33:23 -03:00
|
|
|
update_external_payload(input);
|
2015-05-02 05:09:30 -03:00
|
|
|
|
|
|
|
// update lat/lon/altitude
|
|
|
|
update_position();
|
2017-03-03 06:23:40 -04:00
|
|
|
time_advance();
|
2016-06-17 00:46:12 -03:00
|
|
|
|
|
|
|
// update magnetic field
|
|
|
|
update_mag_field_bf();
|
2016-10-27 03:12:09 -03:00
|
|
|
}
|