mixer_module: add support for test_motor (motor_test CLI command)

This commit is contained in:
Beat Küng
2019-10-21 09:42:08 +02:00
parent 349469cf75
commit 0871802568
9 changed files with 170 additions and 45 deletions
+14 -5
View File
@@ -165,6 +165,8 @@ public:
bool telemetryEnabled() const { return _telemetry != nullptr; }
private:
static constexpr uint16_t DISARMED_VALUE = 0;
enum class DShotConfig {
Disabled = 0,
DShot150 = 150,
@@ -248,8 +250,8 @@ DShotOutput::DShotOutput() :
_cycle_perf(perf_alloc(PC_ELAPSED, "dshot: cycle")),
_cycle_interval_perf(perf_alloc(PC_INTERVAL, "dshot: cycle interval"))
{
_mixing_output.setAllDisarmedValues(0);
_mixing_output.setAllMinValues(1);
_mixing_output.setAllDisarmedValues(DISARMED_VALUE);
_mixing_output.setAllMinValues(DISARMED_VALUE + 1);
_mixing_output.setAllMaxValues(DSHOT_MAX_THROTTLE);
}
@@ -286,6 +288,8 @@ DShotOutput::init()
PX4_ERR("FAILED registering class device");
}
_mixing_output.setDriverInstance(_class_instance);
// Getting initial parameter values
update_params();
@@ -721,7 +725,12 @@ void DShotOutput::updateOutputs(bool stop_motors, uint16_t outputs[MAX_ACTUATORS
} else {
for (int i = 0; i < (int)num_outputs; i++) {
up_dshot_motor_data_set(i, math::min(outputs[i], (uint16_t)DSHOT_MAX_THROTTLE), i == requested_telemetry_index);
if (outputs[i] == DISARMED_VALUE) {
up_dshot_motor_command(i, DShot_cmd_motor_stop, i == requested_telemetry_index);
} else {
up_dshot_motor_data_set(i, math::min(outputs[i], (uint16_t)DSHOT_MAX_THROTTLE), i == requested_telemetry_index);
}
}
// clear commands when motors are running
@@ -805,8 +814,8 @@ void DShotOutput::update_params()
updateParams();
// we use a minimum value of 1, since 0 is for disarmed
_mixing_output.setAllMinValues(math::constrain((int)(_param_dshot_min.get() * (float)DSHOT_MAX_THROTTLE), 1,
DSHOT_MAX_THROTTLE));
_mixing_output.setAllMinValues(math::constrain((int)(_param_dshot_min.get() * (float)DSHOT_MAX_THROTTLE),
DISARMED_VALUE + 1, DSHOT_MAX_THROTTLE));
}
+2
View File
@@ -253,6 +253,8 @@ PX4FMU::init()
PX4_ERR("FAILED registering class device");
}
_mixing_output.setDriverInstance(_class_instance);
/* force a reset of the update rate */
_current_update_rate = 0;
+8 -1
View File
@@ -496,7 +496,14 @@ void TAP_ESC::cycle()
if (test_motor_updated) {
struct test_motor_s test_motor;
orb_copy(ORB_ID(test_motor), _test_motor_sub, &test_motor);
_outputs.output[test_motor.motor_number] = RPMSTOPPED + ((RPMMAX - RPMSTOPPED) * test_motor.value);
if (test_motor.action == test_motor_s::ACTION_STOP) {
_outputs.output[test_motor.motor_number] = RPMSTOPPED;
} else {
_outputs.output[test_motor.motor_number] = RPMSTOPPED + ((RPMMAX - RPMSTOPPED) * test_motor.value);
}
PX4_INFO("setting motor %i to %.1lf", test_motor.motor_number,
(double)_outputs.output[test_motor.motor_number]);
}
+1 -1
View File
@@ -971,7 +971,7 @@ int UavcanNode::run()
orb_copy(ORB_ID(test_motor), _test_motor_sub, &_test_motor);
// Update the test status and check that we're not locked down
_test_in_progress = (_test_motor.value > 0);
_test_in_progress = (_test_motor.action == test_motor_s::ACTION_RUN);
_esc_controller.arm_single_esc(_test_motor.motor_number, _test_in_progress);
}