2015-05-13 00:16:45 -03:00
|
|
|
#include "Rover.h"
|
|
|
|
|
2018-05-07 23:35:08 -03:00
|
|
|
#include "RC_Channel.h"
|
|
|
|
|
|
|
|
// defining these two macros and including the RC_Channels_VarInfo
|
|
|
|
// header defines the parameter information common to all vehicle
|
|
|
|
// types
|
|
|
|
#define RC_CHANNELS_SUBCLASS RC_Channels_Rover
|
|
|
|
#define RC_CHANNEL_SUBCLASS RC_Channel_Rover
|
|
|
|
|
|
|
|
#include <RC_Channel/RC_Channels_VarInfo.h>
|
2017-02-20 10:26:18 -04:00
|
|
|
|
2018-05-07 23:35:08 -03:00
|
|
|
int8_t RC_Channels_Rover::flight_mode_channel_number() const
|
2012-04-30 04:17:14 -03:00
|
|
|
{
|
2018-05-07 23:35:08 -03:00
|
|
|
return rover.g.mode_channel;
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|
|
|
|
|
2018-05-07 23:35:08 -03:00
|
|
|
void RC_Channel_Rover::mode_switch_changed(modeswitch_pos_t new_pos)
|
|
|
|
{
|
|
|
|
if (new_pos < 0 || (uint8_t)new_pos > rover.num_modes) {
|
|
|
|
// should not have been called
|
|
|
|
return;
|
2016-12-20 09:32:57 -04:00
|
|
|
}
|
2018-05-07 23:35:08 -03:00
|
|
|
Mode *new_mode = rover.mode_from_mode_num((Mode::Number)rover.modes[new_pos].get());
|
|
|
|
if (new_mode != nullptr) {
|
|
|
|
rover.set_mode(*new_mode, MODE_REASON_TX_COMMAND);
|
2016-12-20 09:32:57 -04:00
|
|
|
}
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|
|
|
|
|
2018-05-07 23:35:08 -03:00
|
|
|
// init_aux_switch_function - initialize aux functions
|
|
|
|
void RC_Channel_Rover::init_aux_function(const aux_func_t ch_option, const aux_switch_pos_t ch_flag)
|
2012-04-30 04:17:14 -03:00
|
|
|
{
|
2018-05-07 23:35:08 -03:00
|
|
|
// init channel options
|
|
|
|
switch(ch_option) {
|
|
|
|
// the following functions do not need initialising:
|
|
|
|
case SAVE_WP:
|
|
|
|
case LEARN_CRUISE:
|
|
|
|
case ARMDISARM:
|
|
|
|
case MANUAL:
|
|
|
|
case ACRO:
|
|
|
|
case STEERING:
|
|
|
|
case HOLD:
|
|
|
|
case AUTO:
|
|
|
|
case GUIDED:
|
|
|
|
case LOITER:
|
|
|
|
case FOLLOW:
|
2018-09-14 04:09:07 -03:00
|
|
|
case SAILBOAT_TACK:
|
2018-05-07 23:35:08 -03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
RC_Channel::init_aux_function(ch_option, ch_flag);
|
|
|
|
break;
|
|
|
|
}
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|
|
|
|
|
2017-08-22 04:06:23 -03:00
|
|
|
|
2018-05-07 23:35:08 -03:00
|
|
|
bool RC_Channels_Rover::has_valid_input() const
|
2017-08-22 04:06:23 -03:00
|
|
|
{
|
2018-05-07 23:35:08 -03:00
|
|
|
if (rover.failsafe.bits & FAILSAFE_EVENT_THROTTLE) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2017-08-22 04:06:23 -03:00
|
|
|
}
|
|
|
|
|
2018-05-07 23:35:08 -03:00
|
|
|
void RC_Channel_Rover::do_aux_function_change_mode(Mode &mode,
|
|
|
|
const aux_switch_pos_t ch_flag)
|
2018-06-06 04:02:01 -03:00
|
|
|
{
|
|
|
|
switch(ch_flag) {
|
2018-05-07 23:35:08 -03:00
|
|
|
case HIGH:
|
|
|
|
rover.set_mode(mode, MODE_REASON_TX_COMMAND);
|
2018-06-06 04:02:01 -03:00
|
|
|
break;
|
2018-05-07 23:35:08 -03:00
|
|
|
case MIDDLE:
|
2018-06-06 04:02:01 -03:00
|
|
|
// do nothing
|
|
|
|
break;
|
2018-05-07 23:35:08 -03:00
|
|
|
case LOW:
|
|
|
|
if (rover.control_mode == &mode) {
|
|
|
|
rc().reset_mode_switch();
|
2018-06-06 04:02:01 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 23:39:30 -03:00
|
|
|
void RC_Channel_Rover::add_waypoint_for_current_loc()
|
|
|
|
{
|
|
|
|
// create new mission command
|
|
|
|
AP_Mission::Mission_Command cmd = {};
|
|
|
|
|
|
|
|
// set new waypoint to current location
|
|
|
|
cmd.content.location = rover.current_loc;
|
|
|
|
|
|
|
|
// make the new command to a waypoint
|
|
|
|
cmd.id = MAV_CMD_NAV_WAYPOINT;
|
|
|
|
|
|
|
|
// save command
|
|
|
|
if (rover.mode_auto.mission.add_cmd(cmd)) {
|
|
|
|
hal.console->printf("Added waypoint %u", (unsigned)rover.mode_auto.mission.num_commands());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-07 23:35:08 -03:00
|
|
|
void RC_Channel_Rover::do_aux_function(const aux_func_t ch_option, const aux_switch_pos_t ch_flag)
|
2017-08-22 04:06:23 -03:00
|
|
|
{
|
2018-05-07 23:35:08 -03:00
|
|
|
switch (ch_option) {
|
|
|
|
case DO_NOTHING:
|
2013-02-07 18:21:22 -04:00
|
|
|
break;
|
2018-05-07 23:35:08 -03:00
|
|
|
case SAVE_WP:
|
|
|
|
if (ch_flag == HIGH) {
|
2017-08-22 04:06:23 -03:00
|
|
|
// do nothing if in AUTO mode
|
2018-05-07 23:35:08 -03:00
|
|
|
if (rover.control_mode == &rover.mode_auto) {
|
2017-08-22 04:06:23 -03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if disarmed clear mission and set home to current location
|
2018-05-07 23:35:08 -03:00
|
|
|
if (!rover.arming.is_armed()) {
|
2018-12-11 20:10:20 -04:00
|
|
|
rover.mode_auto.mission.clear();
|
2018-05-29 21:52:57 -03:00
|
|
|
if (!rover.set_home_to_current_location(false)) {
|
|
|
|
// ignored
|
|
|
|
}
|
2017-08-22 04:06:23 -03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-28 22:45:34 -04:00
|
|
|
// record the waypoint if not in auto mode
|
2018-05-07 23:35:08 -03:00
|
|
|
if (rover.control_mode != &rover.mode_auto) {
|
2018-08-16 23:39:30 -03:00
|
|
|
if (rover.mode_auto.mission.num_commands() == 0) {
|
|
|
|
// add a home location....
|
|
|
|
add_waypoint_for_current_loc();
|
2012-11-28 07:44:03 -04:00
|
|
|
}
|
2018-08-16 23:39:30 -03:00
|
|
|
add_waypoint_for_current_loc();
|
2012-11-28 07:44:03 -04:00
|
|
|
}
|
|
|
|
}
|
2013-02-07 18:21:22 -04:00
|
|
|
break;
|
2017-08-22 08:53:36 -03:00
|
|
|
|
|
|
|
// learn cruise speed and throttle
|
2018-05-07 23:35:08 -03:00
|
|
|
case LEARN_CRUISE:
|
|
|
|
if (ch_flag == HIGH) {
|
|
|
|
rover.cruise_learn_start();
|
2017-08-22 08:53:36 -03:00
|
|
|
}
|
|
|
|
break;
|
2017-11-30 23:15:50 -04:00
|
|
|
|
|
|
|
// arm or disarm the motors
|
2018-05-07 23:35:08 -03:00
|
|
|
case ARMDISARM:
|
|
|
|
if (ch_flag == HIGH) {
|
|
|
|
rover.arm_motors(AP_Arming::RUDDER);
|
|
|
|
} else if (ch_flag == LOW) {
|
|
|
|
rover.disarm_motors();
|
2017-11-30 23:15:50 -04:00
|
|
|
}
|
|
|
|
break;
|
2017-11-30 23:48:49 -04:00
|
|
|
|
|
|
|
// set mode to Manual
|
2018-05-07 23:35:08 -03:00
|
|
|
case MANUAL:
|
|
|
|
do_aux_function_change_mode(rover.mode_manual, ch_flag);
|
2017-11-30 23:48:49 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
// set mode to Acro
|
2018-05-07 23:35:08 -03:00
|
|
|
case ACRO:
|
|
|
|
do_aux_function_change_mode(rover.mode_acro, ch_flag);
|
2017-11-30 23:48:49 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
// set mode to Steering
|
2018-05-07 23:35:08 -03:00
|
|
|
case STEERING:
|
|
|
|
do_aux_function_change_mode(rover.mode_steering, ch_flag);
|
2017-11-30 23:48:49 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
// set mode to Hold
|
2018-05-07 23:35:08 -03:00
|
|
|
case HOLD:
|
|
|
|
do_aux_function_change_mode(rover.mode_hold, ch_flag);
|
2017-11-30 23:48:49 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
// set mode to Auto
|
2018-05-07 23:35:08 -03:00
|
|
|
case AUTO:
|
|
|
|
do_aux_function_change_mode(rover.mode_auto, ch_flag);
|
2017-11-30 23:48:49 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
// set mode to RTL
|
2018-05-07 23:35:08 -03:00
|
|
|
case RTL:
|
|
|
|
do_aux_function_change_mode(rover.mode_rtl, ch_flag);
|
2017-11-30 23:48:49 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
// set mode to SmartRTL
|
2018-05-07 23:35:08 -03:00
|
|
|
case SMART_RTL:
|
|
|
|
do_aux_function_change_mode(rover.mode_smartrtl, ch_flag);
|
2017-11-30 23:48:49 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
// set mode to Guided
|
2018-05-07 23:35:08 -03:00
|
|
|
case GUIDED:
|
|
|
|
do_aux_function_change_mode(rover.mode_guided, ch_flag);
|
2017-11-30 23:48:49 -04:00
|
|
|
break;
|
2018-05-24 05:13:12 -03:00
|
|
|
|
|
|
|
// Set mode to LOITER
|
2018-05-07 23:35:08 -03:00
|
|
|
case LOITER:
|
|
|
|
do_aux_function_change_mode(rover.mode_loiter, ch_flag);
|
2018-05-24 05:13:12 -03:00
|
|
|
break;
|
2018-05-24 01:47:07 -03:00
|
|
|
|
|
|
|
// Set mode to Follow
|
2018-05-07 23:35:08 -03:00
|
|
|
case FOLLOW:
|
|
|
|
do_aux_function_change_mode(rover.mode_follow, ch_flag);
|
|
|
|
break;
|
|
|
|
|
2018-07-02 04:21:37 -03:00
|
|
|
// set mode to Simple
|
|
|
|
case SIMPLE:
|
|
|
|
do_aux_function_change_mode(rover.mode_simple, ch_flag);
|
|
|
|
break;
|
|
|
|
|
2018-09-14 04:09:07 -03:00
|
|
|
// trigger sailboat tack
|
|
|
|
case SAILBOAT_TACK:
|
2018-11-01 03:11:37 -03:00
|
|
|
// any switch movement interpreted as request to tack
|
|
|
|
rover.control_mode->handle_tack_request();
|
2018-09-14 04:09:07 -03:00
|
|
|
break;
|
|
|
|
|
2018-05-07 23:35:08 -03:00
|
|
|
default:
|
|
|
|
RC_Channel::do_aux_function(ch_option, ch_flag);
|
2018-05-24 01:47:07 -03:00
|
|
|
break;
|
|
|
|
|
2012-11-28 07:44:03 -04:00
|
|
|
}
|
2012-04-30 04:17:14 -03:00
|
|
|
}
|