2016-04-21 06:56:44 -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/>.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
multicopter frame simulator class
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SIM_Frame.h"
|
|
|
|
#include <AP_Motors/AP_Motors.h>
|
2020-05-14 03:12:09 -03:00
|
|
|
#include <AP_Baro/AP_Baro.h>
|
2020-10-24 22:44:10 -03:00
|
|
|
#include <AP_Filesystem/AP_Filesystem.h>
|
2023-01-28 01:47:25 -04:00
|
|
|
#include "SIM_Aircraft.h"
|
2016-04-21 06:56:44 -03:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2020-10-20 04:19:54 -03:00
|
|
|
#include <sys/stat.h>
|
2022-04-13 18:15:57 -03:00
|
|
|
|
2016-04-21 06:56:44 -03:00
|
|
|
using namespace SITL;
|
|
|
|
|
2016-07-03 09:02:09 -03:00
|
|
|
static Motor quad_plus_motors[] =
|
2016-04-21 06:56:44 -03:00
|
|
|
{
|
|
|
|
Motor(AP_MOTORS_MOT_1, 90, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 2),
|
|
|
|
Motor(AP_MOTORS_MOT_2, -90, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 4),
|
|
|
|
Motor(AP_MOTORS_MOT_3, 0, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 1),
|
|
|
|
Motor(AP_MOTORS_MOT_4, 180, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 3),
|
|
|
|
};
|
|
|
|
|
2016-07-03 09:02:09 -03:00
|
|
|
static Motor quad_x_motors[] =
|
2016-04-21 06:56:44 -03:00
|
|
|
{
|
|
|
|
Motor(AP_MOTORS_MOT_1, 45, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 1),
|
|
|
|
Motor(AP_MOTORS_MOT_2, -135, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 3),
|
|
|
|
Motor(AP_MOTORS_MOT_3, -45, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 4),
|
|
|
|
Motor(AP_MOTORS_MOT_4, 135, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 2),
|
|
|
|
};
|
|
|
|
|
2019-01-31 23:29:52 -04:00
|
|
|
// motor order to match betaflight conventions
|
|
|
|
// See: https://fpvfrenzy.com/betaflight-motor-order/
|
|
|
|
static Motor quad_bf_x_motors[] =
|
|
|
|
{
|
|
|
|
Motor(AP_MOTORS_MOT_1, 135, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 2),
|
|
|
|
Motor(AP_MOTORS_MOT_2, 45, AP_MOTORS_MATRIX_YAW_FACTOR_CCW,1),
|
|
|
|
Motor(AP_MOTORS_MOT_3, -135, AP_MOTORS_MATRIX_YAW_FACTOR_CCW,3),
|
|
|
|
Motor(AP_MOTORS_MOT_4, -45, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 4),
|
|
|
|
};
|
|
|
|
|
2020-01-14 02:25:07 -04:00
|
|
|
// motor order to match betaflight conventions, reversed direction
|
|
|
|
static Motor quad_bf_x_rev_motors[] =
|
|
|
|
{
|
|
|
|
Motor(AP_MOTORS_MOT_1, 135, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 2),
|
|
|
|
Motor(AP_MOTORS_MOT_2, 45, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 1),
|
|
|
|
Motor(AP_MOTORS_MOT_3, -135, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 3),
|
|
|
|
Motor(AP_MOTORS_MOT_4, -45, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 4),
|
|
|
|
};
|
|
|
|
|
2019-01-31 23:29:52 -04:00
|
|
|
// motor order to match DJI conventions
|
|
|
|
// See: https://forum44.djicdn.com/data/attachment/forum/201711/26/172348bppvtt1ot1nrtp5j.jpg
|
|
|
|
static Motor quad_dji_x_motors[] =
|
|
|
|
{
|
|
|
|
Motor(AP_MOTORS_MOT_1, 45, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 1),
|
|
|
|
Motor(AP_MOTORS_MOT_2, -45, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 4),
|
|
|
|
Motor(AP_MOTORS_MOT_3, -135, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 3),
|
|
|
|
Motor(AP_MOTORS_MOT_4, 135, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 2),
|
|
|
|
};
|
|
|
|
|
|
|
|
// motor order so that test order matches motor order ("clockwise X")
|
|
|
|
static Motor quad_cw_x_motors[] =
|
|
|
|
{
|
|
|
|
Motor(AP_MOTORS_MOT_1, 45, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 1),
|
|
|
|
Motor(AP_MOTORS_MOT_2, 135, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 2),
|
|
|
|
Motor(AP_MOTORS_MOT_3, -135, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 3),
|
|
|
|
Motor(AP_MOTORS_MOT_4, -45, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 4),
|
|
|
|
};
|
|
|
|
|
2017-08-20 16:09:59 -03:00
|
|
|
static Motor tiltquad_h_vectored_motors[] =
|
|
|
|
{
|
|
|
|
Motor(AP_MOTORS_MOT_1, 45, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 1, -1, 0, 0, 7, 10, -90),
|
|
|
|
Motor(AP_MOTORS_MOT_2, -135, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 3, -1, 0, 0, 8, 10, -90),
|
|
|
|
Motor(AP_MOTORS_MOT_3, -45, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 4, -1, 0, 0, 8, 10, -90),
|
|
|
|
Motor(AP_MOTORS_MOT_4, 135, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 2, -1, 0, 0, 7, 10, -90),
|
|
|
|
};
|
|
|
|
|
2024-02-17 04:27:24 -04:00
|
|
|
static Motor tiltquad[] =
|
|
|
|
{
|
|
|
|
Motor(AP_MOTORS_MOT_1, 45, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 1, -1, 0, 0, 7, 10, -90),
|
|
|
|
Motor(AP_MOTORS_MOT_2, -135, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 3),
|
|
|
|
Motor(AP_MOTORS_MOT_3, -45, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 4, -1, 0, 0, 8, 10, -90),
|
|
|
|
Motor(AP_MOTORS_MOT_4, 135, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 2),
|
|
|
|
};
|
|
|
|
|
2016-07-03 09:02:09 -03:00
|
|
|
static Motor hexa_motors[] =
|
2016-04-21 06:56:44 -03:00
|
|
|
{
|
|
|
|
Motor(AP_MOTORS_MOT_1, 0, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 1),
|
|
|
|
Motor(AP_MOTORS_MOT_2, 180, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 4),
|
|
|
|
Motor(AP_MOTORS_MOT_3,-120, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 5),
|
|
|
|
Motor(AP_MOTORS_MOT_4, 60, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 2),
|
|
|
|
Motor(AP_MOTORS_MOT_5, -60, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 6),
|
|
|
|
Motor(AP_MOTORS_MOT_6, 120, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 3)
|
|
|
|
};
|
|
|
|
|
2016-07-03 09:02:09 -03:00
|
|
|
static Motor hexax_motors[] =
|
2016-04-21 06:56:44 -03:00
|
|
|
{
|
|
|
|
Motor(AP_MOTORS_MOT_1, 90, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 2),
|
|
|
|
Motor(AP_MOTORS_MOT_2, -90, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 5),
|
|
|
|
Motor(AP_MOTORS_MOT_3, -30, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 6),
|
|
|
|
Motor(AP_MOTORS_MOT_4, 150, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 3),
|
|
|
|
Motor(AP_MOTORS_MOT_5, 30, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 1),
|
|
|
|
Motor(AP_MOTORS_MOT_6,-150, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 4)
|
|
|
|
};
|
|
|
|
|
2020-01-28 08:01:34 -04:00
|
|
|
static Motor hexa_dji_x_motors[] =
|
|
|
|
{
|
|
|
|
Motor(AP_MOTORS_MOT_1, 30, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 1),
|
|
|
|
Motor(AP_MOTORS_MOT_2, -30, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 6),
|
|
|
|
Motor(AP_MOTORS_MOT_3, -90, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 5),
|
|
|
|
Motor(AP_MOTORS_MOT_4, -150, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 4),
|
|
|
|
Motor(AP_MOTORS_MOT_5, 150, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 3),
|
|
|
|
Motor(AP_MOTORS_MOT_6, 90, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 2)
|
|
|
|
};
|
|
|
|
|
2020-02-01 05:15:35 -04:00
|
|
|
static Motor hexa_cw_x_motors[] =
|
|
|
|
{
|
|
|
|
Motor(AP_MOTORS_MOT_1, 30, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 1),
|
|
|
|
Motor(AP_MOTORS_MOT_2, 90, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 2),
|
|
|
|
Motor(AP_MOTORS_MOT_3, 150, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 3),
|
|
|
|
Motor(AP_MOTORS_MOT_4, -150, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 4),
|
|
|
|
Motor(AP_MOTORS_MOT_5, -90, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 5),
|
|
|
|
Motor(AP_MOTORS_MOT_6, -30, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 6)
|
|
|
|
};
|
|
|
|
|
2016-07-03 09:02:09 -03:00
|
|
|
static Motor octa_motors[] =
|
2016-04-21 06:56:44 -03:00
|
|
|
{
|
|
|
|
Motor(AP_MOTORS_MOT_1, 0, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 1),
|
|
|
|
Motor(AP_MOTORS_MOT_2, 180, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 5),
|
|
|
|
Motor(AP_MOTORS_MOT_3, 45, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 2),
|
|
|
|
Motor(AP_MOTORS_MOT_4, 135, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 4),
|
|
|
|
Motor(AP_MOTORS_MOT_5, -45, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 8),
|
|
|
|
Motor(AP_MOTORS_MOT_6, -135, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 6),
|
|
|
|
Motor(AP_MOTORS_MOT_7, -90, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 7),
|
|
|
|
Motor(AP_MOTORS_MOT_8, 90, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 3)
|
|
|
|
};
|
|
|
|
|
2020-01-28 08:01:34 -04:00
|
|
|
static Motor octa_dji_x_motors[] =
|
|
|
|
{
|
|
|
|
Motor(AP_MOTORS_MOT_1, 22.5f, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 1),
|
|
|
|
Motor(AP_MOTORS_MOT_2, -22.5f, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 8),
|
|
|
|
Motor(AP_MOTORS_MOT_3, -67.5f, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 7),
|
|
|
|
Motor(AP_MOTORS_MOT_4, -112.5f, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 6),
|
|
|
|
Motor(AP_MOTORS_MOT_5, -157.5f, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 5),
|
|
|
|
Motor(AP_MOTORS_MOT_6, 157.5f, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 4),
|
|
|
|
Motor(AP_MOTORS_MOT_7, 112.5f, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 3),
|
|
|
|
Motor(AP_MOTORS_MOT_8, 67.5f, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 2)
|
|
|
|
};
|
|
|
|
|
2020-02-01 05:15:35 -04:00
|
|
|
static Motor octa_cw_x_motors[] =
|
|
|
|
{
|
|
|
|
Motor(AP_MOTORS_MOT_1, 22.5f, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 1),
|
|
|
|
Motor(AP_MOTORS_MOT_2, 67.5f, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 2),
|
|
|
|
Motor(AP_MOTORS_MOT_3, 112.5f, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 3),
|
|
|
|
Motor(AP_MOTORS_MOT_4, 157.5f, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 4),
|
|
|
|
Motor(AP_MOTORS_MOT_5, -157.5f, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 5),
|
|
|
|
Motor(AP_MOTORS_MOT_6, -112.5f, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 6),
|
|
|
|
Motor(AP_MOTORS_MOT_7, -67.5f, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 7),
|
|
|
|
Motor(AP_MOTORS_MOT_8, -22.5f, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 8)
|
|
|
|
};
|
|
|
|
|
2016-07-03 09:02:09 -03:00
|
|
|
static Motor octa_quad_motors[] =
|
2016-04-21 06:56:44 -03:00
|
|
|
{
|
|
|
|
Motor(AP_MOTORS_MOT_1, 45, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 1),
|
|
|
|
Motor(AP_MOTORS_MOT_2, -45, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 7),
|
|
|
|
Motor(AP_MOTORS_MOT_3, -135, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 5),
|
|
|
|
Motor(AP_MOTORS_MOT_4, 135, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 3),
|
|
|
|
Motor(AP_MOTORS_MOT_5, -45, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 8),
|
|
|
|
Motor(AP_MOTORS_MOT_6, 45, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 2),
|
|
|
|
Motor(AP_MOTORS_MOT_7, 135, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 4),
|
|
|
|
Motor(AP_MOTORS_MOT_8, -135, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 6)
|
|
|
|
};
|
|
|
|
|
2020-02-01 05:15:35 -04:00
|
|
|
static Motor octa_quad_cw_x_motors[] =
|
|
|
|
{
|
|
|
|
Motor(AP_MOTORS_MOT_1, 45, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 1),
|
|
|
|
Motor(AP_MOTORS_MOT_2, 45, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 2),
|
|
|
|
Motor(AP_MOTORS_MOT_3, 135, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 3),
|
|
|
|
Motor(AP_MOTORS_MOT_4, 135, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 4),
|
|
|
|
Motor(AP_MOTORS_MOT_5, -135, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 5),
|
|
|
|
Motor(AP_MOTORS_MOT_6, -135, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 6),
|
|
|
|
Motor(AP_MOTORS_MOT_7, -45, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 7),
|
|
|
|
Motor(AP_MOTORS_MOT_8, -45, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 8)
|
|
|
|
};
|
|
|
|
|
2017-05-27 01:47:55 -03:00
|
|
|
static Motor dodeca_hexa_motors[] =
|
|
|
|
{
|
|
|
|
Motor(AP_MOTORS_MOT_1, 30, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 1),
|
|
|
|
Motor(AP_MOTORS_MOT_2, 30, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 2),
|
|
|
|
Motor(AP_MOTORS_MOT_3, 90, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 3),
|
|
|
|
Motor(AP_MOTORS_MOT_4, 90, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 4),
|
|
|
|
Motor(AP_MOTORS_MOT_5, 150, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 5),
|
|
|
|
Motor(AP_MOTORS_MOT_6, 150, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 6),
|
|
|
|
Motor(AP_MOTORS_MOT_7, -150, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 7),
|
|
|
|
Motor(AP_MOTORS_MOT_8, -150, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 8),
|
|
|
|
Motor(AP_MOTORS_MOT_9, -90, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 9),
|
|
|
|
Motor(AP_MOTORS_MOT_10, -90, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 10),
|
|
|
|
Motor(AP_MOTORS_MOT_11, -30, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 11),
|
|
|
|
Motor(AP_MOTORS_MOT_12, -30, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 12)
|
|
|
|
};
|
|
|
|
|
2020-09-16 12:00:26 -03:00
|
|
|
static Motor deca_motors[] =
|
|
|
|
{
|
|
|
|
Motor(AP_MOTORS_MOT_1, 0, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 1),
|
|
|
|
Motor(AP_MOTORS_MOT_2, 36, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 2),
|
|
|
|
Motor(AP_MOTORS_MOT_3, 72, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 3),
|
|
|
|
Motor(AP_MOTORS_MOT_4, 108, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 4),
|
|
|
|
Motor(AP_MOTORS_MOT_5, 144, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 5),
|
|
|
|
Motor(AP_MOTORS_MOT_6, 180, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 6),
|
|
|
|
Motor(AP_MOTORS_MOT_7, -144, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 7),
|
|
|
|
Motor(AP_MOTORS_MOT_8, -108, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 8),
|
|
|
|
Motor(AP_MOTORS_MOT_9, -72, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 9),
|
|
|
|
Motor(AP_MOTORS_MOT_10, -36, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 10)
|
|
|
|
};
|
|
|
|
|
|
|
|
static Motor deca_cw_x_motors[] =
|
|
|
|
{
|
|
|
|
Motor(AP_MOTORS_MOT_1, 18, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 1),
|
|
|
|
Motor(AP_MOTORS_MOT_2, 54, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 2),
|
|
|
|
Motor(AP_MOTORS_MOT_3, 90, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 3),
|
|
|
|
Motor(AP_MOTORS_MOT_4, 126, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 4),
|
|
|
|
Motor(AP_MOTORS_MOT_5, 162, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 5),
|
|
|
|
Motor(AP_MOTORS_MOT_6, -162, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 6),
|
|
|
|
Motor(AP_MOTORS_MOT_7, -126, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 7),
|
|
|
|
Motor(AP_MOTORS_MOT_8, -90, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 8),
|
|
|
|
Motor(AP_MOTORS_MOT_9, -54, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 9),
|
|
|
|
Motor(AP_MOTORS_MOT_10, -18, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 10)
|
|
|
|
};
|
|
|
|
|
2016-07-03 09:02:09 -03:00
|
|
|
static Motor tri_motors[] =
|
2016-04-21 07:29:49 -03:00
|
|
|
{
|
2016-04-30 21:52:41 -03:00
|
|
|
Motor(AP_MOTORS_MOT_1, 60, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 1),
|
2021-08-27 14:55:22 -03:00
|
|
|
Motor(AP_MOTORS_MOT_2, -60, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 3),
|
2016-05-01 20:47:01 -03:00
|
|
|
Motor(AP_MOTORS_MOT_4, 180, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 2, AP_MOTORS_MOT_7, 60, -60, -1, 0, 0),
|
2016-04-21 07:29:49 -03:00
|
|
|
};
|
|
|
|
|
2016-07-03 09:02:09 -03:00
|
|
|
static Motor tilttri_motors[] =
|
2016-04-30 20:45:35 -03:00
|
|
|
{
|
2016-04-30 21:52:41 -03:00
|
|
|
Motor(AP_MOTORS_MOT_1, 60, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 1, -1, 0, 0, AP_MOTORS_MOT_8, 0, -90),
|
|
|
|
Motor(AP_MOTORS_MOT_2, -60, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 3, -1, 0, 0, AP_MOTORS_MOT_8, 0, -90),
|
2016-05-01 20:47:01 -03:00
|
|
|
Motor(AP_MOTORS_MOT_4, 180, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 2, AP_MOTORS_MOT_7, 60, -60, -1, 0, 0),
|
2016-04-30 20:45:35 -03:00
|
|
|
};
|
|
|
|
|
2017-04-22 23:43:28 -03:00
|
|
|
static Motor tilttri_vectored_motors[] =
|
|
|
|
{
|
|
|
|
Motor(AP_MOTORS_MOT_1, 60, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 1, -1, 0, 0, 7, 10, -90),
|
|
|
|
Motor(AP_MOTORS_MOT_2, -60, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 3, -1, 0, 0, 8, 10, -90),
|
|
|
|
Motor(AP_MOTORS_MOT_4, 180, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 2)
|
|
|
|
};
|
|
|
|
|
2016-07-03 09:02:09 -03:00
|
|
|
static Motor y6_motors[] =
|
2016-04-21 08:11:38 -03:00
|
|
|
{
|
2016-04-30 21:52:41 -03:00
|
|
|
Motor(AP_MOTORS_MOT_1, 60, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 2),
|
|
|
|
Motor(AP_MOTORS_MOT_2, -60, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 5),
|
|
|
|
Motor(AP_MOTORS_MOT_3, -60, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 6),
|
2016-04-21 08:11:38 -03:00
|
|
|
Motor(AP_MOTORS_MOT_4, 180, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 4),
|
2016-04-30 21:52:41 -03:00
|
|
|
Motor(AP_MOTORS_MOT_5, 60, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 1),
|
2016-04-21 08:11:38 -03:00
|
|
|
Motor(AP_MOTORS_MOT_6, 180, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 3)
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2016-05-01 22:22:44 -03:00
|
|
|
FireflyY6 is a Y6 with front motors tiltable using servo on channel 9 (output 8)
|
2016-04-21 08:11:38 -03:00
|
|
|
*/
|
2016-07-03 09:02:09 -03:00
|
|
|
static Motor firefly_motors[] =
|
2016-04-21 08:11:38 -03:00
|
|
|
{
|
2017-02-06 00:01:16 -04:00
|
|
|
Motor(AP_MOTORS_MOT_1, 180, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 3),
|
|
|
|
Motor(AP_MOTORS_MOT_2, 60, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 1, -1, 0, 0, 6, 0, -90),
|
|
|
|
Motor(AP_MOTORS_MOT_3, -60, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 5, -1, 0, 0, 6, 0, -90),
|
2016-04-21 08:11:38 -03:00
|
|
|
Motor(AP_MOTORS_MOT_4, 180, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 4),
|
2017-02-06 00:01:16 -04:00
|
|
|
Motor(AP_MOTORS_MOT_5, 60, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 2, -1, 0, 0, 6, 0, -90),
|
|
|
|
Motor(AP_MOTORS_MOT_6, -60, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 6, -1, 0, 0, 6, 0, -90)
|
2016-04-21 08:11:38 -03:00
|
|
|
};
|
|
|
|
|
2016-04-21 06:56:44 -03:00
|
|
|
/*
|
2016-04-27 21:05:04 -03:00
|
|
|
table of supported frame types. String order is important for
|
|
|
|
partial name matching
|
2016-04-21 06:56:44 -03:00
|
|
|
*/
|
|
|
|
static Frame supported_frames[] =
|
|
|
|
{
|
|
|
|
Frame("+", 4, quad_plus_motors),
|
|
|
|
Frame("quad", 4, quad_plus_motors),
|
|
|
|
Frame("copter", 4, quad_plus_motors),
|
|
|
|
Frame("x", 4, quad_x_motors),
|
2020-01-14 02:25:07 -04:00
|
|
|
Frame("bfxrev", 4, quad_bf_x_rev_motors),
|
2019-01-31 23:29:52 -04:00
|
|
|
Frame("bfx", 4, quad_bf_x_motors),
|
|
|
|
Frame("djix", 4, quad_dji_x_motors),
|
|
|
|
Frame("cwx", 4, quad_cw_x_motors),
|
2017-08-20 16:09:59 -03:00
|
|
|
Frame("tilthvec", 4, tiltquad_h_vectored_motors),
|
2016-04-21 06:56:44 -03:00
|
|
|
Frame("hexax", 6, hexax_motors),
|
2020-02-01 05:15:35 -04:00
|
|
|
Frame("hexa-cwx", 6, hexa_cw_x_motors),
|
2020-01-28 08:01:34 -04:00
|
|
|
Frame("hexa-dji", 6, hexa_dji_x_motors),
|
2016-04-27 21:05:04 -03:00
|
|
|
Frame("hexa", 6, hexa_motors),
|
2020-02-01 05:15:35 -04:00
|
|
|
Frame("octa-cwx", 8, octa_cw_x_motors),
|
2020-01-28 08:01:34 -04:00
|
|
|
Frame("octa-dji", 8, octa_dji_x_motors),
|
2020-02-01 05:15:35 -04:00
|
|
|
Frame("octa-quad-cwx",8, octa_quad_cw_x_motors),
|
2016-04-21 07:29:49 -03:00
|
|
|
Frame("octa-quad", 8, octa_quad_motors),
|
2016-04-27 21:05:04 -03:00
|
|
|
Frame("octa", 8, octa_motors),
|
2020-09-16 12:00:26 -03:00
|
|
|
Frame("deca", 10, deca_motors),
|
|
|
|
Frame("deca-cwx", 10, deca_cw_x_motors),
|
2017-05-27 01:47:55 -03:00
|
|
|
Frame("dodeca-hexa", 12, dodeca_hexa_motors),
|
2016-04-21 08:11:38 -03:00
|
|
|
Frame("tri", 3, tri_motors),
|
2017-04-22 23:43:28 -03:00
|
|
|
Frame("tilttrivec",3, tilttri_vectored_motors),
|
2016-04-30 20:45:35 -03:00
|
|
|
Frame("tilttri", 3, tilttri_motors),
|
2016-04-21 08:11:38 -03:00
|
|
|
Frame("y6", 6, y6_motors),
|
2024-02-17 04:27:24 -04:00
|
|
|
Frame("firefly", 6, firefly_motors),
|
|
|
|
Frame("tilt", 4, tiltquad),
|
2016-04-21 06:56:44 -03:00
|
|
|
};
|
|
|
|
|
2020-10-20 04:19:54 -03:00
|
|
|
// get air density in kg/m^3
|
|
|
|
float Frame::get_air_density(float alt_amsl) const
|
|
|
|
{
|
2024-04-28 04:11:56 -03:00
|
|
|
return AP_Baro::get_air_density_for_alt_amsl(alt_amsl);
|
2020-10-20 04:19:54 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
load frame specific parameters from a json file if available
|
|
|
|
*/
|
|
|
|
void Frame::load_frame_params(const char *model_json)
|
2016-04-21 06:56:44 -03:00
|
|
|
{
|
2020-10-24 22:44:10 -03:00
|
|
|
char *fname = nullptr;
|
|
|
|
struct stat st;
|
|
|
|
if (AP::FS().stat(model_json, &st) == 0) {
|
|
|
|
fname = strdup(model_json);
|
|
|
|
} else {
|
|
|
|
IGNORE_RETURN(asprintf(&fname, "@ROMFS/models/%s", model_json));
|
2021-05-05 00:02:41 -03:00
|
|
|
if (AP::FS().stat(model_json, &st) != 0) {
|
2024-12-13 05:15:45 -04:00
|
|
|
AP_HAL::panic("%s failed to load", model_json);
|
2021-05-05 00:02:41 -03:00
|
|
|
}
|
2020-10-24 22:44:10 -03:00
|
|
|
}
|
|
|
|
if (fname == nullptr) {
|
2024-12-13 05:15:45 -04:00
|
|
|
AP_HAL::panic("%s failed to load", model_json);
|
2020-10-20 04:19:54 -03:00
|
|
|
}
|
2024-01-31 18:01:48 -04:00
|
|
|
AP_JSON::value *obj = AP_JSON::load_json(model_json);
|
2023-01-28 01:47:25 -04:00
|
|
|
if (obj == nullptr) {
|
2024-12-13 05:15:45 -04:00
|
|
|
AP_HAL::panic("%s failed to load", model_json);
|
2020-10-20 04:19:54 -03:00
|
|
|
}
|
|
|
|
|
2022-04-20 14:52:31 -03:00
|
|
|
enum class VarType {
|
|
|
|
FLOAT,
|
|
|
|
VECTOR3F,
|
2022-04-13 11:51:47 -03:00
|
|
|
};
|
|
|
|
|
2022-04-13 18:15:57 -03:00
|
|
|
struct json_search {
|
2020-10-20 04:19:54 -03:00
|
|
|
const char *label;
|
2022-04-13 11:51:47 -03:00
|
|
|
void *ptr;
|
2022-04-20 14:52:31 -03:00
|
|
|
VarType t;
|
2022-04-13 18:15:57 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
json_search vars[] = {
|
2022-04-20 14:52:31 -03:00
|
|
|
#define FRAME_VAR(s) { #s, &model.s, VarType::FLOAT }
|
2020-10-20 04:19:54 -03:00
|
|
|
FRAME_VAR(mass),
|
|
|
|
FRAME_VAR(diagonal_size),
|
|
|
|
FRAME_VAR(refSpd),
|
|
|
|
FRAME_VAR(refAngle),
|
|
|
|
FRAME_VAR(refVoltage),
|
|
|
|
FRAME_VAR(refCurrent),
|
|
|
|
FRAME_VAR(refAlt),
|
|
|
|
FRAME_VAR(refTempC),
|
|
|
|
FRAME_VAR(maxVoltage),
|
2020-10-24 17:38:02 -03:00
|
|
|
FRAME_VAR(battCapacityAh),
|
2020-10-20 04:19:54 -03:00
|
|
|
FRAME_VAR(refBatRes),
|
|
|
|
FRAME_VAR(propExpo),
|
|
|
|
FRAME_VAR(refRotRate),
|
|
|
|
FRAME_VAR(hoverThrOut),
|
|
|
|
FRAME_VAR(pwmMin),
|
|
|
|
FRAME_VAR(pwmMax),
|
|
|
|
FRAME_VAR(spin_min),
|
|
|
|
FRAME_VAR(spin_max),
|
|
|
|
FRAME_VAR(slew_max),
|
2020-11-28 18:51:58 -04:00
|
|
|
FRAME_VAR(disc_area),
|
|
|
|
FRAME_VAR(mdrag_coef),
|
2022-04-20 14:52:31 -03:00
|
|
|
{"moment_inertia", &model.moment_of_inertia, VarType::VECTOR3F},
|
2022-05-01 07:52:42 -03:00
|
|
|
FRAME_VAR(num_motors),
|
2020-10-20 04:19:54 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
for (uint8_t i=0; i<ARRAY_SIZE(vars); i++) {
|
2023-01-28 01:47:25 -04:00
|
|
|
auto v = obj->get(vars[i].label);
|
2024-01-31 18:01:48 -04:00
|
|
|
if (v.is<AP_JSON::null>()) {
|
2020-10-20 04:19:54 -03:00
|
|
|
// use default value
|
|
|
|
continue;
|
|
|
|
}
|
2022-04-20 14:52:31 -03:00
|
|
|
if (vars[i].t == VarType::FLOAT) {
|
2022-04-13 18:15:57 -03:00
|
|
|
parse_float(v, vars[i].label, *((float *)vars[i].ptr));
|
2022-04-13 11:51:47 -03:00
|
|
|
|
2022-04-20 14:52:31 -03:00
|
|
|
} else if (vars[i].t == VarType::VECTOR3F) {
|
2022-04-13 18:15:57 -03:00
|
|
|
parse_vector3(v, vars[i].label, *(Vector3f *)vars[i].ptr);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
json_search per_motor_vars[] = {
|
2022-04-20 14:52:31 -03:00
|
|
|
{"position", &model.motor_pos, VarType::VECTOR3F},
|
|
|
|
{"vector", &model.motor_thrust_vec, VarType::VECTOR3F},
|
|
|
|
{"yaw", &model.yaw_factor, VarType::FLOAT},
|
2022-04-13 18:15:57 -03:00
|
|
|
};
|
|
|
|
char label_name[20];
|
|
|
|
for (uint8_t i=0; i<ARRAY_SIZE(per_motor_vars); i++) {
|
|
|
|
for (uint8_t j=0; j<12; j++) {
|
2023-06-14 13:43:52 -03:00
|
|
|
snprintf(label_name, 20, "motor%i_%s", j+1, per_motor_vars[i].label);
|
2023-01-28 01:47:25 -04:00
|
|
|
auto v = obj->get(label_name);
|
2024-01-31 18:01:48 -04:00
|
|
|
if (v.is<AP_JSON::null>()) {
|
2022-04-13 18:15:57 -03:00
|
|
|
// use default value
|
|
|
|
continue;
|
2022-04-13 11:51:47 -03:00
|
|
|
}
|
2024-01-04 15:15:23 -04:00
|
|
|
if (per_motor_vars[i].t == VarType::FLOAT) {
|
2022-04-20 14:52:31 -03:00
|
|
|
parse_float(v, label_name, *(((float *)per_motor_vars[i].ptr) + j));
|
|
|
|
|
|
|
|
} else if (per_motor_vars[i].t == VarType::VECTOR3F) {
|
2022-04-13 18:15:57 -03:00
|
|
|
parse_vector3(v, label_name, *(((Vector3f *)per_motor_vars[i].ptr) + j));
|
2022-04-13 11:51:47 -03:00
|
|
|
}
|
2020-10-20 04:19:54 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-28 01:47:25 -04:00
|
|
|
delete obj;
|
|
|
|
|
2020-10-20 04:19:54 -03:00
|
|
|
::printf("Loaded model params from %s\n", model_json);
|
|
|
|
}
|
2022-04-13 18:15:57 -03:00
|
|
|
|
2024-01-31 18:01:48 -04:00
|
|
|
void Frame::parse_float(AP_JSON::value val, const char* label, float ¶m) {
|
2022-04-13 18:15:57 -03:00
|
|
|
if (!val.is<double>()) {
|
|
|
|
AP_HAL::panic("Bad json type for %s: %s", label, val.to_str().c_str());
|
|
|
|
}
|
|
|
|
param = val.get<double>();
|
|
|
|
}
|
|
|
|
|
2024-01-31 18:01:48 -04:00
|
|
|
void Frame::parse_vector3(AP_JSON::value val, const char* label, Vector3f ¶m) {
|
|
|
|
if (!val.is<AP_JSON::value::array>() || !val.contains(2) || val.contains(3)) {
|
2022-04-13 18:15:57 -03:00
|
|
|
AP_HAL::panic("Bad json type for %s: %s", label, val.to_str().c_str());
|
|
|
|
}
|
|
|
|
for (uint8_t j=0; j<3; j++) {
|
|
|
|
parse_float(val.get(j), label, param[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-28 01:47:25 -04:00
|
|
|
#if AP_SIM_ENABLED
|
|
|
|
|
2020-10-20 04:19:54 -03:00
|
|
|
/*
|
|
|
|
initialise the frame
|
|
|
|
*/
|
2020-10-24 17:38:02 -03:00
|
|
|
void Frame::init(const char *frame_str, Battery *_battery)
|
2020-10-20 04:19:54 -03:00
|
|
|
{
|
|
|
|
model = default_model;
|
2020-10-24 17:38:02 -03:00
|
|
|
battery = _battery;
|
2020-10-20 04:19:54 -03:00
|
|
|
|
|
|
|
const char *colon = strchr(frame_str, ':');
|
|
|
|
size_t slen = strlen(frame_str);
|
|
|
|
if (colon != nullptr && slen > 5 && strcmp(&frame_str[slen-5], ".json") == 0) {
|
|
|
|
load_frame_params(colon+1);
|
|
|
|
}
|
|
|
|
mass = model.mass;
|
|
|
|
|
|
|
|
const float drag_force = model.mass * GRAVITY_MSS * tanf(radians(model.refAngle));
|
|
|
|
|
2020-11-28 18:51:58 -04:00
|
|
|
const float cos_tilt = cosf(radians(model.refAngle));
|
|
|
|
const float airspeed_bf = model.refSpd * cos_tilt;
|
|
|
|
const float ref_thrust = model.mass * GRAVITY_MSS / cos_tilt;
|
2020-10-20 04:19:54 -03:00
|
|
|
float ref_air_density = get_air_density(model.refAlt);
|
|
|
|
|
2020-11-28 18:51:58 -04:00
|
|
|
const float momentum_drag = cos_tilt * model.mdrag_coef * airspeed_bf * sqrtf(ref_thrust * ref_air_density * model.disc_area);
|
|
|
|
|
|
|
|
if (momentum_drag > drag_force) {
|
|
|
|
model.mdrag_coef *= drag_force / momentum_drag;
|
|
|
|
areaCd = 0.0;
|
2022-04-12 08:15:42 -03:00
|
|
|
::printf("Suggested EK3_DRAG_BCOEF_* = 0, EK3_DRAG_MCOEF = %.3f\n", (momentum_drag / (model.mass * airspeed_bf)) * sqrtf(1.225f / ref_air_density));
|
2020-11-28 18:51:58 -04:00
|
|
|
} else {
|
|
|
|
areaCd = (drag_force - momentum_drag) / (0.5f * ref_air_density * sq(model.refSpd));
|
2022-04-12 08:15:42 -03:00
|
|
|
::printf("Suggested EK3_DRAG_BCOEF_* = %.3f, EK3_DRAG_MCOEF = %.3f\n", model.mass / areaCd, (momentum_drag / (model.mass * airspeed_bf)) * sqrtf(1.225f / ref_air_density));
|
2020-11-28 18:51:58 -04:00
|
|
|
}
|
2020-10-20 04:19:54 -03:00
|
|
|
|
|
|
|
terminal_rotation_rate = model.refRotRate;
|
|
|
|
|
|
|
|
float hover_thrust = mass * GRAVITY_MSS;
|
|
|
|
float hover_power = model.refCurrent * model.refVoltage;
|
|
|
|
float hover_velocity_out = 2 * hover_power / hover_thrust;
|
|
|
|
float effective_disc_area = hover_thrust / (0.5 * ref_air_density * sq(hover_velocity_out));
|
2022-04-13 09:50:36 -03:00
|
|
|
float velocity_max = hover_velocity_out / sqrtf(model.hoverThrOut);
|
|
|
|
float effective_prop_area = effective_disc_area / num_motors;
|
2022-04-22 20:30:47 -03:00
|
|
|
float true_prop_area = model.disc_area / num_motors;
|
2016-04-21 06:56:44 -03:00
|
|
|
|
2020-10-20 04:19:54 -03:00
|
|
|
// power_factor is ratio of power consumed per newton of thrust
|
|
|
|
float power_factor = hover_power / hover_thrust;
|
|
|
|
|
2020-10-24 17:38:02 -03:00
|
|
|
battery->setup(model.battCapacityAh, model.refBatRes, model.maxVoltage);
|
|
|
|
|
2022-05-01 07:52:42 -03:00
|
|
|
if (uint8_t(model.num_motors) != num_motors) {
|
|
|
|
::printf("Warning model expected %u motors and got %u\n", uint8_t(model.num_motors), num_motors);
|
|
|
|
}
|
|
|
|
|
2020-10-20 04:19:54 -03:00
|
|
|
for (uint8_t i=0; i<num_motors; i++) {
|
|
|
|
motors[i].setup_params(model.pwmMin, model.pwmMax, model.spin_min, model.spin_max, model.propExpo, model.slew_max,
|
2022-04-13 18:15:57 -03:00
|
|
|
model.diagonal_size, power_factor, model.maxVoltage, effective_prop_area, velocity_max,
|
2022-04-22 20:30:47 -03:00
|
|
|
model.motor_pos[i], model.motor_thrust_vec[i], model.yaw_factor[i], true_prop_area,
|
|
|
|
model.mdrag_coef);
|
2020-10-20 04:19:54 -03:00
|
|
|
}
|
|
|
|
|
2022-04-13 11:51:47 -03:00
|
|
|
if (is_zero(model.moment_of_inertia.x) || is_zero(model.moment_of_inertia.y) || is_zero(model.moment_of_inertia.z)) {
|
|
|
|
// if no inertia provided, assume 50% of mass on ring around center
|
|
|
|
model.moment_of_inertia.x = model.mass * 0.25 * sq(model.diagonal_size*0.5);
|
|
|
|
model.moment_of_inertia.y = model.moment_of_inertia.x;
|
|
|
|
model.moment_of_inertia.z = model.mass * 0.5 * sq(model.diagonal_size*0.5);
|
|
|
|
}
|
2022-04-13 11:03:53 -03:00
|
|
|
|
2020-10-24 22:44:10 -03:00
|
|
|
// setup reasonable defaults for battery
|
|
|
|
AP_Param::set_default_by_name("SIM_BATT_VOLTAGE", model.maxVoltage);
|
|
|
|
AP_Param::set_default_by_name("SIM_BATT_CAP_AH", model.battCapacityAh);
|
2021-12-21 03:04:05 -04:00
|
|
|
if (model.battCapacityAh > 0) {
|
|
|
|
AP_Param::set_default_by_name("BATT_CAPACITY", model.battCapacityAh*1000);
|
|
|
|
}
|
2016-04-21 06:56:44 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
find a frame by name
|
|
|
|
*/
|
|
|
|
Frame *Frame::find_frame(const char *name)
|
|
|
|
{
|
|
|
|
for (uint8_t i=0; i < ARRAY_SIZE(supported_frames); i++) {
|
2016-04-27 21:05:04 -03:00
|
|
|
// do partial name matching to allow for frame variants
|
|
|
|
if (strncasecmp(name, supported_frames[i].name, strlen(supported_frames[i].name)) == 0) {
|
2016-04-21 06:56:44 -03:00
|
|
|
return &supported_frames[i];
|
|
|
|
}
|
|
|
|
}
|
2016-10-30 02:24:21 -03:00
|
|
|
return nullptr;
|
2016-04-21 06:56:44 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
// calculate rotational and linear accelerations
|
|
|
|
void Frame::calculate_forces(const Aircraft &aircraft,
|
2018-07-31 09:33:23 -03:00
|
|
|
const struct sitl_input &input,
|
2016-04-21 06:56:44 -03:00
|
|
|
Vector3f &rot_accel,
|
2019-09-27 16:56:15 -03:00
|
|
|
Vector3f &body_accel,
|
2020-10-20 04:19:54 -03:00
|
|
|
float* rpm,
|
|
|
|
bool use_drag)
|
2016-04-21 06:56:44 -03:00
|
|
|
{
|
|
|
|
Vector3f thrust; // newtons
|
2022-04-13 11:03:53 -03:00
|
|
|
Vector3f torque;
|
2016-04-21 06:56:44 -03:00
|
|
|
|
2020-10-20 04:19:54 -03:00
|
|
|
const float air_density = get_air_density(aircraft.get_location().alt*0.01);
|
2022-04-20 14:53:11 -03:00
|
|
|
const Vector3f gyro = aircraft.get_gyro();
|
2020-05-14 03:12:09 -03:00
|
|
|
|
2020-10-20 04:19:54 -03:00
|
|
|
Vector3f vel_air_bf = aircraft.get_dcm().transposed() * aircraft.get_velocity_air_ef();
|
|
|
|
|
2023-08-20 21:51:13 -03:00
|
|
|
const auto *_sitl = AP::sitl();
|
2016-04-21 06:56:44 -03:00
|
|
|
for (uint8_t i=0; i<num_motors; i++) {
|
2022-04-13 11:03:53 -03:00
|
|
|
Vector3f mtorque, mthrust;
|
2022-04-22 20:30:47 -03:00
|
|
|
motors[i].calculate_forces(input, motor_offset, mtorque, mthrust, vel_air_bf, gyro, air_density, battery->get_voltage(), use_drag);
|
2022-04-13 11:03:53 -03:00
|
|
|
torque += mtorque;
|
2016-04-21 06:56:44 -03:00
|
|
|
thrust += mthrust;
|
2019-09-27 16:56:15 -03:00
|
|
|
// simulate motor rpm
|
2023-08-20 21:51:13 -03:00
|
|
|
if (!is_zero(_sitl->vibe_motor)) {
|
2022-08-18 04:18:32 -03:00
|
|
|
rpm[motor_offset+i] = motors[i].get_command() * AP::sitl()->vibe_motor * 60.0f;
|
2019-09-27 16:56:15 -03:00
|
|
|
}
|
2016-04-21 06:56:44 -03:00
|
|
|
}
|
|
|
|
|
2022-04-13 11:03:53 -03:00
|
|
|
// calculate total rotational acceleration
|
|
|
|
rot_accel.x = torque.x / model.moment_of_inertia.x;
|
|
|
|
rot_accel.y = torque.y / model.moment_of_inertia.y;
|
|
|
|
rot_accel.z = torque.z / model.moment_of_inertia.z;
|
|
|
|
|
2016-04-21 06:56:44 -03:00
|
|
|
if (terminal_rotation_rate > 0) {
|
|
|
|
// rotational air resistance
|
|
|
|
rot_accel.x -= gyro.x * radians(400.0) / terminal_rotation_rate;
|
|
|
|
rot_accel.y -= gyro.y * radians(400.0) / terminal_rotation_rate;
|
|
|
|
rot_accel.z -= gyro.z * radians(400.0) / terminal_rotation_rate;
|
|
|
|
}
|
|
|
|
|
2020-10-20 04:19:54 -03:00
|
|
|
if (use_drag) {
|
|
|
|
// use the model params to calculate drag
|
2020-11-28 18:51:58 -04:00
|
|
|
Vector3f drag_bf;
|
2022-04-22 20:30:47 -03:00
|
|
|
drag_bf.x = areaCd * 0.5f * air_density * sq(vel_air_bf.x);
|
2022-04-20 15:16:18 -03:00
|
|
|
if (is_negative(vel_air_bf.x)) {
|
2020-11-28 18:51:58 -04:00
|
|
|
drag_bf.x = -drag_bf.x;
|
|
|
|
}
|
|
|
|
|
2022-04-22 20:30:47 -03:00
|
|
|
drag_bf.y = areaCd * 0.5f * air_density * sq(vel_air_bf.y);
|
2022-04-20 15:16:18 -03:00
|
|
|
if (is_negative(vel_air_bf.y)) {
|
2020-11-28 18:51:58 -04:00
|
|
|
drag_bf.y = -drag_bf.y;
|
|
|
|
}
|
|
|
|
|
2022-04-22 20:30:47 -03:00
|
|
|
drag_bf.z = areaCd * 0.5f * air_density * sq(vel_air_bf.z);
|
2022-04-20 15:16:18 -03:00
|
|
|
if (is_negative(vel_air_bf.z)) {
|
2020-11-28 18:51:58 -04:00
|
|
|
drag_bf.z = -drag_bf.z;
|
2020-10-20 04:19:54 -03:00
|
|
|
}
|
2020-11-28 18:51:58 -04:00
|
|
|
|
2022-04-20 15:16:18 -03:00
|
|
|
thrust -= drag_bf;
|
2016-04-21 06:56:44 -03:00
|
|
|
}
|
|
|
|
|
2022-04-20 15:16:18 -03:00
|
|
|
body_accel = thrust/aircraft.gross_mass();
|
2016-04-21 06:56:44 -03:00
|
|
|
}
|
|
|
|
|
2019-01-12 23:07:36 -04:00
|
|
|
|
|
|
|
// calculate current and voltage
|
2020-10-20 04:19:54 -03:00
|
|
|
void Frame::current_and_voltage(float &voltage, float ¤t)
|
2019-01-12 23:07:36 -04:00
|
|
|
{
|
2020-10-24 17:38:02 -03:00
|
|
|
float param_voltage = AP::sitl()->batt_voltage;
|
|
|
|
if (!is_equal(last_param_voltage,param_voltage)) {
|
|
|
|
battery->init_voltage(param_voltage);
|
|
|
|
last_param_voltage = param_voltage;
|
|
|
|
}
|
|
|
|
voltage = battery->get_voltage();
|
2019-01-12 23:07:36 -04:00
|
|
|
current = 0;
|
|
|
|
for (uint8_t i=0; i<num_motors; i++) {
|
2020-10-20 04:19:54 -03:00
|
|
|
current += motors[i].get_current();
|
2019-01-12 23:07:36 -04:00
|
|
|
}
|
|
|
|
}
|
2022-04-22 13:25:41 -03:00
|
|
|
#endif // AP_SIM_ENABLED
|