15 _watchdogTimer.setInterval(100);
16 _watchdogTimer.setSingleShot(
false);
17 connect(&_watchdogTimer, &QTimer::timeout,
this, &ActuatorTest::watchdogTimeout);
18 _watchdogTimer.start();
23 _actuators->clearAndDeleteContents();
24 delete _allMotorsActuator;
29 _actuators->clearAndDeleteContents();
31 if (_allMotorsActuator) {
32 _allMotorsActuator->deleteLater();
35 _allMotorsActuator =
nullptr;
39 if (actuator->isMotor()) {
40 motorActuator = actuator;
42 _actuators->append(actuator);
45 _allMotorsActuator =
new Actuator(
this, tr(
"All Motors"), motorActuator->
min(), motorActuator->
max(), motorActuator->
defaultValue(),
53void ActuatorTest::resetStates()
57 for (
int i = 0; i < _actuators->
count(); ++i) {
58 _states.append(ActuatorState{});
62void ActuatorTest::watchdogTimeout()
64 for (
int i = 0; i < _states.size(); ++i) {
65 if (_states[i].state == ActuatorState::State::Active) {
66 if (_states[i].lastUpdated.elapsed() > 100) {
67 qCWarning(ActuatorTestingLog) <<
"Stopping actuator due to timeout:" << i;
68 _states[i].state = ActuatorState::State::StopRequest;
77 if (!_active || index >= _states.size()) {
80 qCDebug(ActuatorTestingLog) <<
"setting actuator: index:" << index <<
"value:" << value;
82 _states[index].value = value;
83 _states[index].state = ActuatorState::State::Active;
84 _states[index].lastUpdated.start();
90 if (index >= _states.size() || index < -1) {
93 qCDebug(ActuatorTestingLog) <<
"stop actuator control: index:" << index;
96 for (
int i = 0; i < _states.size(); ++i) {
97 if (_states[i].state == ActuatorState::State::Active) {
98 _states[i].state = ActuatorState::State::StopRequest;
102 if (_states[index].state == ActuatorState::State::Active) {
103 _states[index].state = ActuatorState::State::StopRequest;
111 qCDebug(ActuatorTestingLog) <<
"setting active: " << active;
121 actuatorTest->ackHandler(
static_cast<MAV_RESULT
>(ack.result), failureCode);
127 _commandInProgress =
false;
131 }
else if (commandResult == MAV_RESULT_ACCEPTED) {
132 if (_currentState != -1 && _states[_currentState].state == ActuatorState::State::Stopping) {
133 _states[_currentState].state = ActuatorState::State::NotActive;
137 if (_currentState != -1) {
138 _states[_currentState].state = ActuatorState::State::NotActive;
143 if (commandResult == MAV_RESULT_TEMPORARILY_REJECTED) {
144 message = tr(
"Actuator test command temporarily rejected");
145 }
else if (commandResult == MAV_RESULT_DENIED) {
146 message = tr(
"Actuator test command denied");
147 }
else if (commandResult == MAV_RESULT_UNSUPPORTED) {
148 message = tr(
"Actuator test command not supported");
150 message = tr(
"Actuator test command failed");
160void ActuatorTest::sendNext()
162 if (_commandInProgress) {
167 for (
int i = 0; i < _states.size(); ++i) {
168 _currentState = (_currentState + 1) % _states.size();
169 Actuator* actuator = _actuators->value<Actuator*>(_currentState);
170 if (_states[_currentState].state == ActuatorState::State::Active) {
171 sendMavlinkRequest(actuator->
function(), _states[_currentState].value, 1.f);
173 }
else if (_states[_currentState].state == ActuatorState::State::StopRequest) {
174 _states[_currentState].state = ActuatorState::State::Stopping;
175 sendMavlinkRequest(actuator->
function(), NAN, 0.f);
181void ActuatorTest::sendMavlinkRequest(
int function,
float value,
float timeout)
183 qCDebug(ActuatorTestingLog) <<
"Sending actuator test function:" << function <<
"value:" << value;
191 _vehicle->sendMavCommandWithHandler(
193 MAV_COMP_ID_AUTOPILOT1,
194 MAV_CMD_ACTUATOR_TEST,
202 _commandInProgress =
true;
#define QGC_LOGGING_CATEGORY(name, categoryStr)
struct __mavlink_command_ack_t mavlink_command_ack_t
Q_INVOKABLE void setActive(bool active)
ActuatorTest(Vehicle *vehicle)
void updateFunctions(const QList< Actuator * > &actuators)
Q_INVOKABLE void setChannelTo(int index, float value)
Q_INVOKABLE void stopControl(int index)
QmlObjectListModel * actuators()
float defaultValue() const
int count() const override final
void showAppMessage(const QString &message, const QString &title)
Modal application message. Queued if the UI isn't ready yet.
MavCmdResultHandler resultHandler
nullptr for no handler
struct VehicleTypes::MavCmdAckHandlerInfo_s MavCmdAckHandlerInfo_t
Callback info bundle for sendMavCommandWithHandler.
MavCmdResultFailureCode_t
@ MavCmdResultFailureNoResponseToCommand
No response from vehicle to command.