Skip to content

Sub: turn lights and video_switch into aux functions #29863

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ArduSub/GCS_MAVLink_Sub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ bool GCS_MAVLINK_Sub::send_info()

CHECK_PAYLOAD_SIZE(NAMED_VALUE_FLOAT);
send_named_float("Lights1",
SRV_Channels::get_output_norm(SRV_Channel::k_rcin9) / 2.0f + 0.5f);
SRV_Channels::get_output_norm(SRV_Channel::k_lights1) / 2.0f + 0.5f);

CHECK_PAYLOAD_SIZE(NAMED_VALUE_FLOAT);
send_named_float("Lights2",
Expand Down
4 changes: 2 additions & 2 deletions ArduSub/Parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,8 @@ static const struct AP_Param::defaults_table_struct defaults_table[] = {
{ "BATT_CAPACITY", 0},
{ "LEAK1_PIN", 27},
{ "SCHED_LOOP_RATE", 200},
{ "SERVO13_FUNCTION", 59}, // k_rcin9, lights 1
{ "SERVO14_FUNCTION", 60}, // k_rcin10, lights 2
{ "SERVO13_FUNCTION", 181}, // k_lights1
{ "SERVO14_FUNCTION", 182}, // k_lights2
{ "SERVO16_FUNCTION", 7}, // k_mount_tilt
{ "SERVO16_REVERSED", 1},
#else
Expand Down
76 changes: 30 additions & 46 deletions ArduSub/joystick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
namespace {
float cam_tilt = 1500.0;
float cam_pan = 1500.0;
int16_t lights1 = 1100;
int16_t lights2 = 1100;
float lights1 = 0;
float lights2 = 0;
int16_t rollTrim = 0;
int16_t pitchTrim = 0;
int16_t zTrim = 0;
int16_t xTrim = 0;
int16_t yTrim = 0;
int16_t video_switch = 1100;
int16_t x_last, y_last, z_last;
uint32_t buttons_prev;

Expand All @@ -32,9 +31,6 @@ void Sub::init_joystick()
{
default_js_buttons();

lights1 = RC_Channels::rc_channel(8)->get_radio_min();
lights2 = RC_Channels::rc_channel(9)->get_radio_min();

set_mode(Mode::Number::MANUAL, ModeReason::RC_COMMAND); // Initialize flight mode

if (g.numGainSettings < 1) {
Expand All @@ -49,6 +45,9 @@ void Sub::init_joystick()
}

gain = constrain_float(gain, 0.1, 1.0);
SRV_Channels::set_output_scaled(SRV_Channel::k_lights1, 0.0);
SRV_Channels::set_output_scaled(SRV_Channel::k_lights2, 0.0);
SRV_Channels::set_output_scaled(SRV_Channel::k_video_switch, 0.0);
}

void Sub::transform_manual_control_to_rc_override(int16_t x, int16_t y, int16_t z, int16_t r, uint16_t buttons, uint16_t buttons2, uint8_t enabled_extensions,
Expand Down Expand Up @@ -138,9 +137,6 @@ void Sub::transform_manual_control_to_rc_override(int16_t x, int16_t y, int16_t

RC_Channels::set_override(6, cam_pan, tnow); // camera pan
RC_Channels::set_override(7, cam_tilt, tnow); // camera tilt
RC_Channels::set_override(8, lights1, tnow); // lights 1
RC_Channels::set_override(9, lights2, tnow); // lights 2
RC_Channels::set_override(10, video_switch, tnow); // video switch

// Store old x, y, z values for use in input hold logic
x_last = x;
Expand Down Expand Up @@ -216,10 +212,10 @@ void Sub::handle_jsbutton_press(uint8_t _button, bool shift, bool held)
static bool video_toggle = false;
video_toggle = !video_toggle;
if (video_toggle) {
video_switch = 1900;
SRV_Channels::set_output_scaled(SRV_Channel::k_video_switch, 1000);
gcs().send_text(MAV_SEVERITY_INFO,"Video Toggle: Source 2");
} else {
video_switch = 1100;
SRV_Channels::set_output_scaled(SRV_Channel::k_video_switch, 0.0);
gcs().send_text(MAV_SEVERITY_INFO,"Video Toggle: Source 1");
}
}
Expand All @@ -233,71 +229,59 @@ void Sub::handle_jsbutton_press(uint8_t _button, bool shift, bool held)
case JSButton::button_function_t::k_lights1_cycle:
if (!held) {
static bool increasing = true;
RC_Channel* chan = RC_Channels::rc_channel(8);
uint16_t min = chan->get_radio_min();
uint16_t max = chan->get_radio_max();
uint16_t step = (max - min) / g.lights_steps;
uint16_t step = 1000.0 / g.lights_steps;
if (increasing) {
lights1 = constrain_float(lights1 + step, min, max);
lights1 = constrain_float(lights1 + step, 0.0, 1000.0);
} else {
lights1 = constrain_float(lights1 - step, min, max);
lights1 = constrain_float(lights1 - step, 0.0, 1000.0);
}
if (lights1 >= max || lights1 <= min) {
if (lights1 >= 1000.0 || lights1 <= 0.0) {
increasing = !increasing;
}
SRV_Channels::set_output_scaled(SRV_Channel::k_lights1, lights1);
}
break;
case JSButton::button_function_t::k_lights1_brighter:
if (!held) {
RC_Channel* chan = RC_Channels::rc_channel(8);
uint16_t min = chan->get_radio_min();
uint16_t max = chan->get_radio_max();
uint16_t step = (max - min) / g.lights_steps;
lights1 = constrain_float(lights1 + step, min, max);
uint16_t step = 1000.0 / g.lights_steps;
lights1 = constrain_float(lights1 + step, 0.0, 1000.0);
SRV_Channels::set_output_scaled(SRV_Channel::k_lights1, lights1);
}
break;
case JSButton::button_function_t::k_lights1_dimmer:
if (!held) {
RC_Channel* chan = RC_Channels::rc_channel(8);
uint16_t min = chan->get_radio_min();
uint16_t max = chan->get_radio_max();
uint16_t step = (max - min) / g.lights_steps;
lights1 = constrain_float(lights1 - step, min, max);
uint16_t step = 1000.0 / g.lights_steps;
lights1 = constrain_float(lights1 - step, 0.0, 1000.0);
SRV_Channels::set_output_scaled(SRV_Channel::k_lights1, lights1);
}
break;
case JSButton::button_function_t::k_lights2_cycle:
if (!held) {
if (!held) {
static bool increasing = true;
RC_Channel* chan = RC_Channels::rc_channel(9);
uint16_t min = chan->get_radio_min();
uint16_t max = chan->get_radio_max();
uint16_t step = (max - min) / g.lights_steps;
uint16_t step = 1000.0 / g.lights_steps;
if (increasing) {
lights2 = constrain_float(lights2 + step, min, max);
lights2 = constrain_float(lights2 + step, 0.0, 1000.0);
} else {
lights2 = constrain_float(lights2 - step, min, max);
lights2 = constrain_float(lights2 - step, 0.0, 1000.0);
}
if (lights2 >= max || lights2 <= min) {
if (lights2 >= 1000.0 || lights2 <= 0.0) {
increasing = !increasing;
}
SRV_Channels::set_output_scaled(SRV_Channel::k_lights2, lights2);
}
break;
case JSButton::button_function_t::k_lights2_brighter:
if (!held) {
RC_Channel* chan = RC_Channels::rc_channel(9);
uint16_t min = chan->get_radio_min();
uint16_t max = chan->get_radio_max();
uint16_t step = (max - min) / g.lights_steps;
lights2 = constrain_float(lights2 + step, min, max);
uint16_t step = 1000.0 / g.lights_steps;
lights2 = constrain_float(lights2 + step, 0.0, 1000.0);
SRV_Channels::set_output_scaled(SRV_Channel::k_lights2, lights2);
}
break;
case JSButton::button_function_t::k_lights2_dimmer:
if (!held) {
RC_Channel* chan = RC_Channels::rc_channel(9);
uint16_t min = chan->get_radio_min();
uint16_t max = chan->get_radio_max();
uint16_t step = (max - min) / g.lights_steps;
lights2 = constrain_float(lights2 - step, min, max);
uint16_t step = 1000.0 / g.lights_steps;
lights2 = constrain_float(lights2 - step, 0.0, 1000.0);
SRV_Channels::set_output_scaled(SRV_Channel::k_lights2, lights2);
}
break;
case JSButton::button_function_t::k_gain_toggle:
Expand Down
10 changes: 0 additions & 10 deletions ArduSub/radio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,6 @@ void Sub::init_rc_in()

RC_Channels::set_override(6, 1500); // camera pan channel
RC_Channels::set_override(7, 1500); // camera tilt channel

RC_Channel* chan = RC_Channels::rc_channel(8);
uint16_t min = chan->get_radio_min();
RC_Channels::set_override(8, min); // lights 1 channel

chan = RC_Channels::rc_channel(9);
min = chan->get_radio_min();
RC_Channels::set_override(9, min); // lights 2 channel

RC_Channels::set_override(10, 1100); // video switch
#endif
}

Expand Down
5 changes: 4 additions & 1 deletion libraries/SRV_Channel/SRV_Channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const AP_Param::GroupInfo SRV_Channel::var_info[] = {
// @Values{Plane}: 41:TiltMotorsFront,45:TiltMotorsRear,46:TiltMotorRearLeft,47:TiltMotorRearRight
// @Values: 51:RCIN1,52:RCIN2,53:RCIN3,54:RCIN4,55:RCIN5,56:RCIN6,57:RCIN7,58:RCIN8,59:RCIN9,60:RCIN10,61:RCIN11,62:RCIN12,63:RCIN13,64:RCIN14,65:RCIN15,66:RCIN16
// @Values{Plane, Copter, Rover}: 51:RCIN1,52:RCIN2,53:RCIN3,54:RCIN4,55:RCIN5,56:RCIN6,57:RCIN7,58:RCIN8,59:RCIN9,60:RCIN10,61:RCIN11,62:RCIN12,63:RCIN13,64:RCIN14,65:RCIN15,66:RCIN16
// @Values{Sub}: 51:RCIN1/Pitch,52:RCIN2/Roll,53:RCIN3/HeaveVertical,54:RCIN4/YawTurn,55:RCIN5/SurgeForward,56:RCIN6/SwayLateral,57:RCIN7/CameraPan,58:RCIN8/CameraTilt,59:RCIN9/Lights1Level,60:RCIN10/Lights2Level,61:RCIN11/VideoSwitch,62:RCIN12,63:RCIN13,64:RCIN14,65:RCIN15,66:RCIN16
// @Values{Sub}: 51:RCIN1/Pitch,52:RCIN2/Roll,53:RCIN3/HeaveVertical,54:RCIN4/YawTurn,55:RCIN5/SurgeForward,56:RCIN6/SwayLateral,57:RCIN7/CameraPan,58:RCIN8/CameraTilt,59:RCIN9,60:RCIN10,61:RCIN11,62:RCIN12,63:RCIN13,64:RCIN14,65:RCIN15,66:RCIN16
// @Values: 67:Ignition,69:Starter
// @Values{Plane}: 67:Ignition,69:Starter
// @Values: 70:Throttle
Expand Down Expand Up @@ -163,6 +163,9 @@ const AP_Param::GroupInfo SRV_Channel::var_info[] = {
// @Values{Plane, Copter}: 168:Motor21,169:Motor22,170:Motor23,171:Motor24
// @Values{Plane, Copter}: 172:Motor25,173:Motor26,174:Motor27,175:Motor28
// @Values{Plane, Copter}: 176:Motor29,177:Motor30,178:Motor31,179:Motor32
// @Values: 180:CameraZoom
// @Values{Sub}: 181:Lights1,182:Lights2
// @Values{Sub}: 183:VideoSwitch
// @User: Standard
// @RebootRequired: True
AP_GROUPINFO("FUNCTION", 5, SRV_Channel, function, 0),
Expand Down
3 changes: 3 additions & 0 deletions libraries/SRV_Channel/SRV_Channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ class SRV_Channel {
k_motor31 = 178,
k_motor32 = 179,
k_cam_zoom = 180,
k_lights1 = 181,
k_lights2 = 182,
k_video_switch = 183,
k_nr_aux_servo_functions ///< This must be the last enum value (only add new values _before_ this one)
} Function;

Expand Down
3 changes: 3 additions & 0 deletions libraries/SRV_Channel/SRV_Channel_aux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ void SRV_Channel::aux_servo_function_setup(void)
break;
case k_cam_zoom:
case k_cam_focus:
case k_lights1:
case k_lights2:
case k_video_switch:
set_range(1000);
break;
default:
Expand Down
Loading