2016-03-12 19:05:10 -04:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
|
|
|
#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:
|
ArduPlane: Fix up after refactoring RC_Channel class
Further to refactor of RC_Channel class which included
adding get_xx set_xx methods, change reads and writes to the public members
to calls to get and set functionsss
old public member(int16_t) get function -> int16_t set function (int16_t)
(expression where c is an object of type RC_Channel)
c.radio_in c.get_radio_in() c.set_radio_in(v)
c.control_in c.get_control_in() c.set_control_in(v)
c.servo_out c.get_servo_out() c.set_servo_out(v)
c.pwm_out c.get_pwm_out() // use existing
c.radio_out c.get_radio_out() c.set_radio_out(v)
c.radio_max c.get_radio_max() c.set_radio_max(v)
c.radio_min c.get_radio_min() c.set_radio_min(v)
c.radio_trim c.get_radio_trim() c.set_radio_trim(v);
c.min_max_configured() // return true if min and max are configured
Because data members of RC_Channels are now private and so cannot be written directly
some overloads are provided in the Plane classes to provide the old functionality
new overload Plane::stick_mix_channel(RC_Channel *channel)
which forwards to the previously existing
void stick_mix_channel(RC_Channel *channel, int16_t &servo_out);
new overload Plane::channel_output_mixer(Rc_Channel* , RC_Channel*)const
which forwards to
(uint8_t mixing_type, int16_t & chan1, int16_t & chan2)const;
Rename functions
RC_Channel_aux::set_radio_trim(Aux_servo_function_t function)
to RC_Channel_aux::set_trim_to_radio_in_for(Aux_servo_function_t function)
RC_Channel_aux::set_servo_out(Aux_servo_function_t function, int16_t value)
to RC_Channel_aux::set_servo_out_for(Aux_servo_function_t function, int16_t value)
Rationale:
RC_Channel is a complicated class, which combines
several functionalities dealing with stick inputs
in pwm and logical units, logical and actual actuator
outputs, unit conversion etc, etc
The intent of this PR is to clarify existing use of
the class. At the basic level it should now be possible
to grep all places where private variable is set by
searching for the set_xx function.
(The wider purpose is to provide a more generic and
logically simpler method of output mixing. This is a small step)
2016-05-08 05:33:02 -03:00
|
|
|
pwm = plane.channel_throttle->get_radio_in();
|
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
|
|
|
|
motors->output_test(motor_test.seq, pwm);
|
|
|
|
} 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
|
|
|
|
uint8_t 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()) {
|
|
|
|
plane.gcs_send_text(MAV_SEVERITY_INFO, "Must be disarmed for motor test");
|
|
|
|
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;
|
|
|
|
}
|