2016-03-12 19:05:10 -04:00
|
|
|
#include "Plane.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
mavlink motor test - implements the MAV_CMD_DO_MOTOR_TEST mavlink
|
|
|
|
command so that the quadplane pilot can test an
|
|
|
|
individual motor to ensure proper wiring, rotation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// motor test definitions
|
|
|
|
#define MOTOR_TEST_PWM_MIN 800 // min pwm value accepted by the test
|
|
|
|
#define MOTOR_TEST_PWM_MAX 2200 // max pwm value accepted by the test
|
|
|
|
#define MOTOR_TEST_TIMEOUT_MS_MAX 30000 // max timeout is 30 seconds
|
|
|
|
|
|
|
|
// motor_test_output - checks for timeout and sends updates to motors objects
|
|
|
|
void QuadPlane::motor_test_output()
|
|
|
|
{
|
|
|
|
// exit immediately if the motor test is not running
|
|
|
|
if (!motor_test.running) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for test timeout
|
2016-03-31 21:09:51 -03:00
|
|
|
uint32_t now = AP_HAL::millis();
|
|
|
|
if ((now - motor_test.start_ms) >= motor_test.timeout_ms) {
|
|
|
|
if (motor_test.motor_count > 1) {
|
|
|
|
if (now - motor_test.start_ms < motor_test.timeout_ms*1.5) {
|
|
|
|
// output zero for 0.5s
|
|
|
|
motors->output_min();
|
|
|
|
} else {
|
|
|
|
// move onto next motor
|
|
|
|
motor_test.seq++;
|
|
|
|
motor_test.motor_count--;
|
|
|
|
motor_test.start_ms = now;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2016-03-12 19:05:10 -04:00
|
|
|
// stop motor test
|
|
|
|
motor_test_stop();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int16_t pwm = 0; // pwm that will be output to the motors
|
|
|
|
|
|
|
|
// calculate pwm based on throttle type
|
|
|
|
switch (motor_test.throttle_type) {
|
|
|
|
case MOTOR_TEST_THROTTLE_PERCENT:
|
|
|
|
// sanity check motor_test.throttle value
|
|
|
|
if (motor_test.throttle_value <= 100) {
|
2016-05-26 22:53:08 -03:00
|
|
|
pwm = thr_min_pwm + (thr_max_pwm - thr_min_pwm) * (float)motor_test.throttle_value*0.01f;
|
2016-03-12 19:05:10 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MOTOR_TEST_THROTTLE_PWM:
|
|
|
|
pwm = motor_test.throttle_value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MOTOR_TEST_THROTTLE_PILOT:
|
2016-09-14 21:12:56 -03:00
|
|
|
pwm = thr_min_pwm + (thr_max_pwm - thr_min_pwm) * (float)plane.channel_throttle->get_control_in()*0.01f;
|
2016-03-12 19:05:10 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
motor_test_stop();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// sanity check throttle values
|
|
|
|
if (pwm >= MOTOR_TEST_PWM_MIN && pwm <= MOTOR_TEST_PWM_MAX ) {
|
|
|
|
// turn on motor to specified pwm vlaue
|
2018-04-27 13:17:08 -03:00
|
|
|
motors->output_test_seq(motor_test.seq, pwm);
|
2016-03-12 19:05:10 -04:00
|
|
|
} else {
|
|
|
|
motor_test_stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// mavlink_motor_test_start - start motor test - spin a single motor at a specified pwm
|
|
|
|
// returns MAV_RESULT_ACCEPTED on success, MAV_RESULT_FAILED on failure
|
2017-11-27 02:16:01 -04:00
|
|
|
MAV_RESULT QuadPlane::mavlink_motor_test_start(mavlink_channel_t chan, uint8_t motor_seq, uint8_t throttle_type,
|
2016-03-31 21:09:51 -03:00
|
|
|
uint16_t throttle_value, float timeout_sec, uint8_t motor_count)
|
2016-03-12 19:05:10 -04:00
|
|
|
{
|
|
|
|
if (motors->armed()) {
|
2017-07-08 22:15:58 -03:00
|
|
|
gcs().send_text(MAV_SEVERITY_INFO, "Must be disarmed for motor test");
|
2016-03-12 19:05:10 -04:00
|
|
|
return MAV_RESULT_FAILED;
|
|
|
|
}
|
|
|
|
// if test has not started try to start it
|
|
|
|
if (!motor_test.running) {
|
|
|
|
// start test
|
|
|
|
motor_test.running = true;
|
|
|
|
|
|
|
|
// enable and arm motors
|
|
|
|
set_armed(true);
|
|
|
|
|
|
|
|
// turn on notify leds
|
|
|
|
AP_Notify::flags.esc_calibration = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set timeout
|
|
|
|
motor_test.start_ms = AP_HAL::millis();
|
|
|
|
motor_test.timeout_ms = MIN(timeout_sec * 1000, MOTOR_TEST_TIMEOUT_MS_MAX);
|
|
|
|
|
|
|
|
// store required output
|
|
|
|
motor_test.seq = motor_seq;
|
|
|
|
motor_test.throttle_type = throttle_type;
|
|
|
|
motor_test.throttle_value = throttle_value;
|
2016-03-31 21:09:51 -03:00
|
|
|
motor_test.motor_count = MIN(motor_count, 8);
|
2016-03-12 19:05:10 -04:00
|
|
|
|
|
|
|
// return success
|
|
|
|
return MAV_RESULT_ACCEPTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// motor_test_stop - stops the motor test
|
|
|
|
void QuadPlane::motor_test_stop()
|
|
|
|
{
|
|
|
|
// exit immediately if the test is not running
|
|
|
|
if (!motor_test.running) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// flag test is complete
|
|
|
|
motor_test.running = false;
|
|
|
|
|
|
|
|
// disarm motors
|
|
|
|
set_armed(false);
|
|
|
|
|
|
|
|
// reset timeout
|
|
|
|
motor_test.start_ms = 0;
|
|
|
|
motor_test.timeout_ms = 0;
|
|
|
|
|
|
|
|
// turn off notify leds
|
|
|
|
AP_Notify::flags.esc_calibration = false;
|
|
|
|
}
|