|
|
|
@ -5,7 +5,6 @@
@@ -5,7 +5,6 @@
|
|
|
|
|
|
|
|
|
|
// Anonymous namespace to hold variables used only in this file
|
|
|
|
|
namespace { |
|
|
|
|
int16_t mode_switch_pwm = 1100; |
|
|
|
|
float cam_tilt = 1500.0; |
|
|
|
|
int16_t lights1 = 1100; |
|
|
|
|
int16_t lights2 = 1100; |
|
|
|
@ -18,7 +17,6 @@ int16_t video_switch = 1100;
@@ -18,7 +17,6 @@ int16_t video_switch = 1100;
|
|
|
|
|
int16_t x_last, y_last, z_last; |
|
|
|
|
uint16_t buttons_prev; |
|
|
|
|
float gain; |
|
|
|
|
bool toggle_mode = true; |
|
|
|
|
|
|
|
|
|
// Servo control output channels
|
|
|
|
|
// TODO: Allow selecting output channels
|
|
|
|
@ -33,7 +31,7 @@ void Sub::init_joystick()
@@ -33,7 +31,7 @@ void Sub::init_joystick()
|
|
|
|
|
{ |
|
|
|
|
default_js_buttons(); |
|
|
|
|
|
|
|
|
|
set_mode((control_mode_t)flight_modes[0].get(), MODE_REASON_TX_COMMAND); // Initialize flight mode
|
|
|
|
|
set_mode(MANUAL, MODE_REASON_TX_COMMAND); // Initialize flight mode
|
|
|
|
|
|
|
|
|
|
if (g.numGainSettings < 1) { |
|
|
|
|
g.numGainSettings.set_and_save(1); |
|
|
|
@ -97,7 +95,7 @@ void Sub::transform_manual_control_to_rc_override(int16_t x, int16_t y, int16_t
@@ -97,7 +95,7 @@ void Sub::transform_manual_control_to_rc_override(int16_t x, int16_t y, int16_t
|
|
|
|
|
|
|
|
|
|
channels[2] = constrain_int16((z+zTrim)*throttleScale+throttleBase,1100,1900); // throttle
|
|
|
|
|
channels[3] = constrain_int16(r*rpyScale+rpyCenter,1100,1900); // yaw
|
|
|
|
|
channels[4] = mode_switch_pwm; // for testing only
|
|
|
|
|
//channels[4] = mode_switch_pwm; // for testing only
|
|
|
|
|
|
|
|
|
|
if (!roll_pitch_flag) { |
|
|
|
|
// adjust forward and lateral with joystick input instead of roll and pitch
|
|
|
|
@ -125,10 +123,6 @@ void Sub::transform_manual_control_to_rc_override(int16_t x, int16_t y, int16_t
@@ -125,10 +123,6 @@ void Sub::transform_manual_control_to_rc_override(int16_t x, int16_t y, int16_t
|
|
|
|
|
|
|
|
|
|
void Sub::handle_jsbutton_press(uint8_t button, bool shift, bool held) |
|
|
|
|
{ |
|
|
|
|
// For attempts to change control mode
|
|
|
|
|
control_mode_t next_mode = control_mode; |
|
|
|
|
uint16_t next_mode_switch_pwm = mode_switch_pwm; |
|
|
|
|
|
|
|
|
|
// Act based on the function assigned to this button
|
|
|
|
|
switch (get_button(button)->function(shift)) { |
|
|
|
|
case JSButton::button_function_t::k_arm_toggle: |
|
|
|
@ -144,43 +138,32 @@ void Sub::handle_jsbutton_press(uint8_t button, bool shift, bool held)
@@ -144,43 +138,32 @@ void Sub::handle_jsbutton_press(uint8_t button, bool shift, bool held)
|
|
|
|
|
case JSButton::button_function_t::k_disarm: |
|
|
|
|
init_disarm_motors(); |
|
|
|
|
break; |
|
|
|
|
case JSButton::button_function_t::k_mode_toggle: |
|
|
|
|
if (!held) { |
|
|
|
|
next_mode = (control_mode_t)flight_modes[toggle_mode?1:0].get(); |
|
|
|
|
next_mode_switch_pwm = toggle_mode?1300:1100; |
|
|
|
|
toggle_mode = !toggle_mode; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case JSButton::button_function_t::k_mode_manual: |
|
|
|
|
set_mode(MANUAL, MODE_REASON_TX_COMMAND); |
|
|
|
|
break; |
|
|
|
|
case JSButton::button_function_t::k_mode_stabilize: |
|
|
|
|
set_mode(STABILIZE, MODE_REASON_TX_COMMAND); |
|
|
|
|
break; |
|
|
|
|
case JSButton::button_function_t::k_mode_1: |
|
|
|
|
next_mode = (control_mode_t)flight_modes[0].get(); |
|
|
|
|
next_mode_switch_pwm = 1100; |
|
|
|
|
toggle_mode = true; |
|
|
|
|
case JSButton::button_function_t::k_mode_depth_hold: |
|
|
|
|
set_mode(ALT_HOLD, MODE_REASON_TX_COMMAND); |
|
|
|
|
break; |
|
|
|
|
case JSButton::button_function_t::k_mode_2: |
|
|
|
|
next_mode = (control_mode_t)flight_modes[1].get(); |
|
|
|
|
next_mode_switch_pwm = 1300; |
|
|
|
|
toggle_mode = false; |
|
|
|
|
case JSButton::button_function_t::k_mode_auto: |
|
|
|
|
set_mode(AUTO, MODE_REASON_TX_COMMAND); |
|
|
|
|
break; |
|
|
|
|
case JSButton::button_function_t::k_mode_3: |
|
|
|
|
next_mode = (control_mode_t)flight_modes[2].get(); |
|
|
|
|
next_mode_switch_pwm = 1420; |
|
|
|
|
toggle_mode = false; |
|
|
|
|
case JSButton::button_function_t::k_mode_guided: |
|
|
|
|
set_mode(GUIDED, MODE_REASON_TX_COMMAND); |
|
|
|
|
break; |
|
|
|
|
case JSButton::button_function_t::k_mode_4: |
|
|
|
|
next_mode = (control_mode_t)flight_modes[3].get(); |
|
|
|
|
next_mode_switch_pwm = 1550; |
|
|
|
|
toggle_mode = false; |
|
|
|
|
case JSButton::button_function_t::k_mode_circle: |
|
|
|
|
set_mode(CIRCLE, MODE_REASON_TX_COMMAND); |
|
|
|
|
break; |
|
|
|
|
case JSButton::button_function_t::k_mode_5: |
|
|
|
|
next_mode = (control_mode_t)flight_modes[4].get(); |
|
|
|
|
next_mode_switch_pwm = 1690; |
|
|
|
|
toggle_mode = false; |
|
|
|
|
case JSButton::button_function_t::k_mode_acro: |
|
|
|
|
set_mode(ACRO, MODE_REASON_TX_COMMAND); |
|
|
|
|
break; |
|
|
|
|
case JSButton::button_function_t::k_mode_6: |
|
|
|
|
next_mode = (control_mode_t)flight_modes[5].get(); |
|
|
|
|
next_mode_switch_pwm = 1900; |
|
|
|
|
toggle_mode = false; |
|
|
|
|
case JSButton::button_function_t::k_mode_poshold: |
|
|
|
|
set_mode(POSHOLD, MODE_REASON_TX_COMMAND); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case JSButton::button_function_t::k_mount_center: |
|
|
|
|
cam_tilt = g.cam_tilt_center; |
|
|
|
|
break; |
|
|
|
@ -501,23 +484,6 @@ void Sub::handle_jsbutton_press(uint8_t button, bool shift, bool held)
@@ -501,23 +484,6 @@ void Sub::handle_jsbutton_press(uint8_t button, bool shift, bool held)
|
|
|
|
|
// Not implemented
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Update the control mode if needed
|
|
|
|
|
if (control_mode != next_mode) { |
|
|
|
|
if (set_mode(next_mode, MODE_REASON_TX_COMMAND)) { |
|
|
|
|
// Notify user
|
|
|
|
|
if (ap.initialised) { |
|
|
|
|
AP_Notify::events.user_mode_change = 1; |
|
|
|
|
} |
|
|
|
|
// Update CH5 pwm value (For GCS)
|
|
|
|
|
mode_switch_pwm = next_mode_switch_pwm; |
|
|
|
|
} else { |
|
|
|
|
// Notify user
|
|
|
|
|
if (ap.initialised) { |
|
|
|
|
AP_Notify::events.user_mode_change_failed = 1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
JSButton* Sub::get_button(uint8_t index) |
|
|
|
@ -564,10 +530,10 @@ JSButton* Sub::get_button(uint8_t index)
@@ -564,10 +530,10 @@ JSButton* Sub::get_button(uint8_t index)
|
|
|
|
|
void Sub::default_js_buttons() |
|
|
|
|
{ |
|
|
|
|
JSButton::button_function_t defaults[16][2] = { |
|
|
|
|
{JSButton::button_function_t::k_mode_manual, JSButton::button_function_t::k_none}, |
|
|
|
|
{JSButton::button_function_t::k_mode_stabilize, JSButton::button_function_t::k_none}, |
|
|
|
|
{JSButton::button_function_t::k_mode_depth_hold, JSButton::button_function_t::k_none}, |
|
|
|
|
{JSButton::button_function_t::k_none, JSButton::button_function_t::k_none}, |
|
|
|
|
{JSButton::button_function_t::k_mode_1, JSButton::button_function_t::k_none}, |
|
|
|
|
{JSButton::button_function_t::k_mode_3, JSButton::button_function_t::k_none}, |
|
|
|
|
{JSButton::button_function_t::k_mode_2, JSButton::button_function_t::k_none}, |
|
|
|
|
|
|
|
|
|
{JSButton::button_function_t::k_disarm, JSButton::button_function_t::k_none}, |
|
|
|
|
{JSButton::button_function_t::k_shift, JSButton::button_function_t::k_none}, |
|
|
|
|