mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-06-26 08:30:35 +08:00
Merge branch 'master' into navigator_rewrite
Conflicts: src/drivers/gps/gps.cpp src/drivers/gps/mtk.cpp src/modules/commander/commander.cpp src/modules/ekf_att_pos_estimator/ekf_att_pos_estimator_main.cpp src/modules/navigator/mission.cpp src/modules/navigator/mission.h src/modules/navigator/navigator_main.cpp src/modules/navigator/navigator_state.h src/modules/position_estimator_inav/position_estimator_inav_main.c
This commit is contained in:
@@ -447,6 +447,7 @@ public:
|
||||
QUAD_WIDE, /**< quad in wide configuration */
|
||||
HEX_X, /**< hex in X configuration */
|
||||
HEX_PLUS, /**< hex in + configuration */
|
||||
HEX_COX,
|
||||
OCTA_X,
|
||||
OCTA_PLUS,
|
||||
OCTA_COX,
|
||||
@@ -516,7 +517,7 @@ private:
|
||||
float _roll_scale;
|
||||
float _pitch_scale;
|
||||
float _yaw_scale;
|
||||
float _deadband;
|
||||
float _idle_speed;
|
||||
|
||||
unsigned _rotor_count;
|
||||
const Rotor *_rotors;
|
||||
|
||||
@@ -67,6 +67,11 @@
|
||||
namespace
|
||||
{
|
||||
|
||||
float constrain(float val, float min, float max)
|
||||
{
|
||||
return (val < min) ? min : ((val > max) ? max : val);
|
||||
}
|
||||
|
||||
/*
|
||||
* These tables automatically generated by multi_tables - do not edit.
|
||||
*/
|
||||
@@ -110,6 +115,14 @@ const MultirotorMixer::Rotor _config_hex_plus[] = {
|
||||
{ 0.866025, 0.500000, 1.00 },
|
||||
{ -0.866025, -0.500000, -1.00 },
|
||||
};
|
||||
const MultirotorMixer::Rotor _config_hex_cox[] = {
|
||||
{ -0.866025, 0.500000, -1.00 },
|
||||
{ -0.866025, 0.500000, 1.00 },
|
||||
{ -0.000000, -1.000000, -1.00 },
|
||||
{ -0.000000, -1.000000, 1.00 },
|
||||
{ 0.866025, 0.500000, -1.00 },
|
||||
{ 0.866025, 0.500000, 1.00 },
|
||||
};
|
||||
const MultirotorMixer::Rotor _config_octa_x[] = {
|
||||
{ -0.382683, 0.923880, -1.00 },
|
||||
{ 0.382683, -0.923880, -1.00 },
|
||||
@@ -147,6 +160,7 @@ const MultirotorMixer::Rotor *_config_index[MultirotorMixer::MAX_GEOMETRY] = {
|
||||
&_config_quad_wide[0],
|
||||
&_config_hex_x[0],
|
||||
&_config_hex_plus[0],
|
||||
&_config_hex_cox[0],
|
||||
&_config_octa_x[0],
|
||||
&_config_octa_plus[0],
|
||||
&_config_octa_cox[0],
|
||||
@@ -158,6 +172,7 @@ const unsigned _config_rotor_count[MultirotorMixer::MAX_GEOMETRY] = {
|
||||
4, /* quad_wide */
|
||||
6, /* hex_x */
|
||||
6, /* hex_plus */
|
||||
6, /* hex_cox */
|
||||
8, /* octa_x */
|
||||
8, /* octa_plus */
|
||||
8, /* octa_cox */
|
||||
@@ -171,12 +186,12 @@ MultirotorMixer::MultirotorMixer(ControlCallback control_cb,
|
||||
float roll_scale,
|
||||
float pitch_scale,
|
||||
float yaw_scale,
|
||||
float deadband) :
|
||||
float idle_speed) :
|
||||
Mixer(control_cb, cb_handle),
|
||||
_roll_scale(roll_scale),
|
||||
_pitch_scale(pitch_scale),
|
||||
_yaw_scale(yaw_scale),
|
||||
_deadband(-1.0f + deadband), /* shift to output range here to avoid runtime calculation */
|
||||
_idle_speed(-1.0f + idle_speed * 2.0f), /* shift to output range here to avoid runtime calculation */
|
||||
_rotor_count(_config_rotor_count[geometry]),
|
||||
_rotors(_config_index[geometry])
|
||||
{
|
||||
@@ -247,6 +262,9 @@ MultirotorMixer::from_text(Mixer::ControlCallback control_cb, uintptr_t cb_handl
|
||||
} else if (!strcmp(geomname, "6x")) {
|
||||
geometry = MultirotorMixer::HEX_X;
|
||||
|
||||
} else if (!strcmp(geomname, "6c")) {
|
||||
geometry = MultirotorMixer::HEX_COX;
|
||||
|
||||
} else if (!strcmp(geomname, "8+")) {
|
||||
geometry = MultirotorMixer::OCTA_PLUS;
|
||||
|
||||
@@ -276,67 +294,67 @@ MultirotorMixer::from_text(Mixer::ControlCallback control_cb, uintptr_t cb_handl
|
||||
unsigned
|
||||
MultirotorMixer::mix(float *outputs, unsigned space)
|
||||
{
|
||||
float roll = get_control(0, 0) * _roll_scale;
|
||||
float roll = constrain(get_control(0, 0) * _roll_scale, -1.0f, 1.0f);
|
||||
//lowsyslog("roll: %d, get_control0: %d, %d\n", (int)(roll), (int)(get_control(0, 0)), (int)(_roll_scale));
|
||||
float pitch = get_control(0, 1) * _pitch_scale;
|
||||
float yaw = get_control(0, 2) * _yaw_scale;
|
||||
float thrust = get_control(0, 3);
|
||||
float pitch = constrain(get_control(0, 1) * _pitch_scale, -1.0f, 1.0f);
|
||||
float yaw = constrain(get_control(0, 2) * _yaw_scale, -1.0f, 1.0f);
|
||||
float thrust = constrain(get_control(0, 3), 0.0f, 1.0f);
|
||||
//lowsyslog("thrust: %d, get_control3: %d\n", (int)(thrust), (int)(get_control(0, 3)));
|
||||
float max = 0.0f;
|
||||
float fixup_scale;
|
||||
float min_out = 0.0f;
|
||||
float max_out = 0.0f;
|
||||
float scale_yaw = 1.0f;
|
||||
|
||||
/* use an output factor to prevent too strong control signals at low throttle */
|
||||
float min_thrust = 0.05f;
|
||||
float max_thrust = 1.0f;
|
||||
float startpoint_full_control = 0.40f;
|
||||
float output_factor;
|
||||
|
||||
/* keep roll, pitch and yaw control to 0 below min thrust */
|
||||
if (thrust <= min_thrust) {
|
||||
output_factor = 0.0f;
|
||||
/* linearly increase the output factor from 0 to 1 between min_thrust and startpoint_full_control */
|
||||
|
||||
} else if (thrust < startpoint_full_control && thrust > min_thrust) {
|
||||
output_factor = (thrust / max_thrust) / (startpoint_full_control - min_thrust);
|
||||
/* and then stay at full control */
|
||||
|
||||
} else {
|
||||
output_factor = max_thrust;
|
||||
}
|
||||
|
||||
roll *= output_factor;
|
||||
pitch *= output_factor;
|
||||
yaw *= output_factor;
|
||||
|
||||
|
||||
/* perform initial mix pass yielding un-bounded outputs */
|
||||
/* perform initial mix pass yielding unbounded outputs, ignore yaw */
|
||||
for (unsigned i = 0; i < _rotor_count; i++) {
|
||||
float tmp = roll * _rotors[i].roll_scale +
|
||||
float out = roll * _rotors[i].roll_scale +
|
||||
pitch * _rotors[i].pitch_scale +
|
||||
yaw * _rotors[i].yaw_scale +
|
||||
thrust;
|
||||
|
||||
if (tmp > max)
|
||||
max = tmp;
|
||||
/* limit yaw if it causes outputs clipping */
|
||||
if (out >= 0.0f && out < -yaw * _rotors[i].yaw_scale) {
|
||||
yaw = -out / _rotors[i].yaw_scale;
|
||||
}
|
||||
|
||||
outputs[i] = tmp;
|
||||
/* calculate min and max output values */
|
||||
if (out < min_out) {
|
||||
min_out = out;
|
||||
}
|
||||
if (out > max_out) {
|
||||
max_out = out;
|
||||
}
|
||||
|
||||
outputs[i] = out;
|
||||
}
|
||||
|
||||
/* scale values into the -1.0 - 1.0 range */
|
||||
if (max > 1.0f) {
|
||||
fixup_scale = 2.0f / max;
|
||||
/* scale down roll/pitch controls if some outputs are negative, don't add yaw, keep total thrust */
|
||||
if (min_out < 0.0) {
|
||||
float scale_in = thrust / (thrust - min_out);
|
||||
|
||||
/* mix again with adjusted controls */
|
||||
for (unsigned i = 0; i < _rotor_count; i++) {
|
||||
outputs[i] = scale_in * (roll * _rotors[i].roll_scale + pitch * _rotors[i].pitch_scale) + thrust;
|
||||
}
|
||||
|
||||
} else {
|
||||
fixup_scale = 2.0f;
|
||||
/* roll/pitch mixed without limiting, add yaw control */
|
||||
for (unsigned i = 0; i < _rotor_count; i++) {
|
||||
outputs[i] += yaw * _rotors[i].yaw_scale;
|
||||
}
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < _rotor_count; i++)
|
||||
outputs[i] = -1.0f + (outputs[i] * fixup_scale);
|
||||
/* scale down all outputs if some outputs are too large, reduce total thrust */
|
||||
float scale_out;
|
||||
if (max_out > 1.0f) {
|
||||
scale_out = 1.0f / max_out;
|
||||
|
||||
/* ensure outputs are out of the deadband */
|
||||
for (unsigned i = 0; i < _rotor_count; i++)
|
||||
if (outputs[i] < _deadband)
|
||||
outputs[i] = _deadband;
|
||||
} else {
|
||||
scale_out = 1.0f;
|
||||
}
|
||||
|
||||
/* scale outputs to range _idle_speed..1, and do final limiting */
|
||||
for (unsigned i = 0; i < _rotor_count; i++) {
|
||||
outputs[i] = constrain(_idle_speed + (outputs[i] * (1.0f - _idle_speed) * scale_out), _idle_speed, 1.0f);
|
||||
}
|
||||
|
||||
return _rotor_count;
|
||||
}
|
||||
|
||||
@@ -52,6 +52,15 @@ set hex_plus {
|
||||
120 CW
|
||||
}
|
||||
|
||||
set hex_cox {
|
||||
60 CW
|
||||
60 CCW
|
||||
180 CW
|
||||
180 CCW
|
||||
-60 CW
|
||||
-60 CCW
|
||||
}
|
||||
|
||||
set octa_x {
|
||||
22.5 CW
|
||||
-157.5 CW
|
||||
@@ -85,7 +94,7 @@ set octa_cox {
|
||||
-135 CW
|
||||
}
|
||||
|
||||
set tables {quad_x quad_plus quad_v quad_wide hex_x hex_plus octa_x octa_plus octa_cox}
|
||||
set tables {quad_x quad_plus quad_v quad_wide hex_x hex_plus hex_cox octa_x octa_plus octa_cox}
|
||||
|
||||
proc factors {a d} { puts [format "\t{ %9.6f, %9.6f, %5.2f }," [rcos [expr $a + 90]] [rcos $a] [expr -$d]]}
|
||||
|
||||
@@ -104,13 +113,13 @@ foreach table $tables {
|
||||
puts "};"
|
||||
}
|
||||
|
||||
puts "const MultirotorMixer::Rotor *_config_index\[MultirotorMixer::Geometry::MAX_GEOMETRY\] = {"
|
||||
puts "const MultirotorMixer::Rotor *_config_index\[MultirotorMixer::MAX_GEOMETRY\] = {"
|
||||
foreach table $tables {
|
||||
puts [format "\t&_config_%s\[0\]," $table]
|
||||
}
|
||||
puts "};"
|
||||
|
||||
puts "const unsigned _config_rotor_count\[MultirotorMixer::Geometry::MAX_GEOMETRY\] = {"
|
||||
puts "const unsigned _config_rotor_count\[MultirotorMixer::MAX_GEOMETRY\] = {"
|
||||
foreach table $tables {
|
||||
upvar #0 $table angles
|
||||
puts [format "\t%u, /* %s */" [expr [llength $angles] / 2] $table]
|
||||
|
||||
@@ -521,73 +521,15 @@ param_save_default(void)
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
if (res == OK) {
|
||||
res = param_export(fd, false);
|
||||
res = param_export(fd, false);
|
||||
|
||||
if (res != OK) {
|
||||
warnx("failed to write parameters to file: %s", filename);
|
||||
}
|
||||
if (res != OK) {
|
||||
warnx("failed to write parameters to file: %s", filename);
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
return res;
|
||||
|
||||
#if 0
|
||||
const char *filename_tmp = malloc(strlen(filename) + 5);
|
||||
sprintf(filename_tmp, "%s.tmp", filename);
|
||||
|
||||
/* delete temp file if exist */
|
||||
res = unlink(filename_tmp);
|
||||
|
||||
if (res != OK && errno == ENOENT)
|
||||
res = OK;
|
||||
|
||||
if (res != OK)
|
||||
warn("failed to delete temp file: %s", filename_tmp);
|
||||
|
||||
if (res == OK) {
|
||||
/* write parameters to temp file */
|
||||
fd = open(filename_tmp, O_WRONLY | O_CREAT | O_EXCL);
|
||||
|
||||
if (fd < 0) {
|
||||
warn("failed to open temp file: %s", filename_tmp);
|
||||
res = ERROR;
|
||||
}
|
||||
|
||||
if (res == OK) {
|
||||
res = param_export(fd, false);
|
||||
|
||||
if (res != OK)
|
||||
warnx("failed to write parameters to file: %s", filename_tmp);
|
||||
}
|
||||
|
||||
close(fd);
|
||||
}
|
||||
|
||||
if (res == OK) {
|
||||
/* delete parameters file */
|
||||
res = unlink(filename);
|
||||
|
||||
if (res != OK && errno == ENOENT)
|
||||
res = OK;
|
||||
|
||||
if (res != OK)
|
||||
warn("failed to delete parameters file: %s", filename);
|
||||
}
|
||||
|
||||
if (res == OK) {
|
||||
/* rename temp file to parameters */
|
||||
res = rename(filename_tmp, filename);
|
||||
|
||||
if (res != OK)
|
||||
warn("failed to rename %s to %s", filename_tmp, filename);
|
||||
}
|
||||
|
||||
free(filename_tmp);
|
||||
|
||||
return res;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -281,13 +281,19 @@ perf_reset(perf_counter_t handle)
|
||||
|
||||
void
|
||||
perf_print_counter(perf_counter_t handle)
|
||||
{
|
||||
perf_print_counter_fd(0, handle);
|
||||
}
|
||||
|
||||
void
|
||||
perf_print_counter_fd(int fd, perf_counter_t handle)
|
||||
{
|
||||
if (handle == NULL)
|
||||
return;
|
||||
|
||||
switch (handle->type) {
|
||||
case PC_COUNT:
|
||||
printf("%s: %llu events\n",
|
||||
dprintf(fd, "%s: %llu events\n",
|
||||
handle->name,
|
||||
((struct perf_ctr_count *)handle)->event_count);
|
||||
break;
|
||||
@@ -295,7 +301,7 @@ perf_print_counter(perf_counter_t handle)
|
||||
case PC_ELAPSED: {
|
||||
struct perf_ctr_elapsed *pce = (struct perf_ctr_elapsed *)handle;
|
||||
|
||||
printf("%s: %llu events, %lluus elapsed, %llu avg, min %lluus max %lluus\n",
|
||||
dprintf(fd, "%s: %llu events, %lluus elapsed, %llu avg, min %lluus max %lluus\n",
|
||||
handle->name,
|
||||
pce->event_count,
|
||||
pce->time_total,
|
||||
@@ -308,7 +314,7 @@ perf_print_counter(perf_counter_t handle)
|
||||
case PC_INTERVAL: {
|
||||
struct perf_ctr_interval *pci = (struct perf_ctr_interval *)handle;
|
||||
|
||||
printf("%s: %llu events, %llu avg, min %lluus max %lluus\n",
|
||||
dprintf(fd, "%s: %llu events, %llu avg, min %lluus max %lluus\n",
|
||||
handle->name,
|
||||
pci->event_count,
|
||||
(pci->time_last - pci->time_first) / pci->event_count,
|
||||
@@ -349,12 +355,12 @@ perf_event_count(perf_counter_t handle)
|
||||
}
|
||||
|
||||
void
|
||||
perf_print_all(void)
|
||||
perf_print_all(int fd)
|
||||
{
|
||||
perf_counter_t handle = (perf_counter_t)sq_peek(&perf_counters);
|
||||
|
||||
while (handle != NULL) {
|
||||
perf_print_counter(handle);
|
||||
perf_print_counter_fd(fd, handle);
|
||||
handle = (perf_counter_t)sq_next(&handle->link);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,16 +121,26 @@ __EXPORT extern void perf_cancel(perf_counter_t handle);
|
||||
__EXPORT extern void perf_reset(perf_counter_t handle);
|
||||
|
||||
/**
|
||||
* Print one performance counter.
|
||||
* Print one performance counter to stdout
|
||||
*
|
||||
* @param handle The counter to print.
|
||||
*/
|
||||
__EXPORT extern void perf_print_counter(perf_counter_t handle);
|
||||
|
||||
/**
|
||||
* Print all of the performance counters.
|
||||
* Print one performance counter to a fd.
|
||||
*
|
||||
* @param fd File descriptor to print to - e.g. 0 for stdout
|
||||
* @param handle The counter to print.
|
||||
*/
|
||||
__EXPORT extern void perf_print_all(void);
|
||||
__EXPORT extern void perf_print_counter_fd(int fd, perf_counter_t handle);
|
||||
|
||||
/**
|
||||
* Print all of the performance counters.
|
||||
*
|
||||
* @param fd File descriptor to print to - e.g. 0 for stdout
|
||||
*/
|
||||
__EXPORT extern void perf_print_all(int fd);
|
||||
|
||||
/**
|
||||
* Reset all of the performance counters.
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
|
||||
#define SIGMA 0.000001f
|
||||
|
||||
__EXPORT void pid_init(PID_t *pid, uint8_t mode, float dt_min)
|
||||
__EXPORT void pid_init(PID_t *pid, pid_mode_t mode, float dt_min)
|
||||
{
|
||||
pid->mode = mode;
|
||||
pid->dt_min = dt_min;
|
||||
|
||||
@@ -136,12 +136,26 @@ void pwm_limit_calc(const bool armed, const unsigned num_channels, const uint16_
|
||||
}
|
||||
|
||||
effective_pwm[i] = output[i] * (max_pwm[i] - ramp_min_pwm)/2 + (max_pwm[i] + ramp_min_pwm)/2;
|
||||
|
||||
/* last line of defense against invalid inputs */
|
||||
if (effective_pwm[i] < ramp_min_pwm) {
|
||||
effective_pwm[i] = ramp_min_pwm;
|
||||
} else if (effective_pwm[i] > max_pwm[i]) {
|
||||
effective_pwm[i] = max_pwm[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PWM_LIMIT_STATE_ON:
|
||||
for (unsigned i=0; i<num_channels; i++) {
|
||||
effective_pwm[i] = output[i] * (max_pwm[i] - min_pwm[i])/2 + (max_pwm[i] + min_pwm[i])/2;
|
||||
|
||||
/* last line of defense against invalid inputs */
|
||||
if (effective_pwm[i] < min_pwm[i]) {
|
||||
effective_pwm[i] = min_pwm[i];
|
||||
} else if (effective_pwm[i] > max_pwm[i]) {
|
||||
effective_pwm[i] = max_pwm[i];
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -140,7 +140,7 @@ int rc_calibration_check(int mavlink_fd) {
|
||||
/* sanity checks pass, enable channel */
|
||||
if (count) {
|
||||
mavlink_log_critical(mavlink_fd, "ERROR: %d config error(s) for RC channel %d.", count, (i + 1));
|
||||
warnx(mavlink_fd, "ERROR: %d config error(s) for RC channel %d.", count, (i + 1));
|
||||
warnx("ERROR: %d config error(s) for RC channel %d.", count, (i + 1));
|
||||
usleep(100000);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user