mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-19 11:33:35 +08:00
mixer_module: add support for test_motor (motor_test CLI command)
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user