How to implement custom button functions in joystick.cpp

Hello everyone,

I am just getting started with a BlueROV Heavy and as a first “programming exercise” I tried implementing a couple of custom joystick button functions to turn the lights on and off. However, I can’t get it to work.

Going on the information I found on Joystick Setup Page · GitBook, I added my code to the custom case statements in the big switch in Sub::handle_jsbutton_press in ArduSub/joystick.cpp and then assigned those custom functions to joystick buttons in QGC. However, when I upload my .apj file to the ROV, QGC occasionally says “IMU forced reset” and also the normal lights functions (brighter and darker) don’t seem anymore. Here is my code, starting on line 573 in joystick.cpp. I simply copied from the k_lights1_brighter and k_lights1_darker cases and modified it slightly.

case JSButton::button_function_t::k_custom_1:
    // make lights really bright
    if (!held) {
        RC_Channel* chan = RC_Channels::rc_channel(8);
        uint16_t max = chan->get_radio_max();
        lights1 = max;
    }
    break;
case JSButton::button_function_t::k_custom_2:
    // make lights really dark
    if (!held) {
        RC_Channel* chan = RC_Channels::rc_channel(8);
        uint16_t min = chan->get_radio_min();
        lights1 = min;
    }
    break;

There are no errors when building the package. I am on Windows 10 with Eclipse and my code base is the most current version from Github.

Could anybody please point me into the right direction? I’m sure I must be missing something but I don’t really know where to start looking.

Thank you!

Anne

Are you building master? that could case a couple of issues.

This looks right.

IIRC this will change channel 9, not 8. You can use QGC’s MAVLink Inspector to check the state of each channel in the SERVO_OUTPUT_RAW messages.

Thank you very much for your reply!

I created a branch called playground and I am pretty confident I am building on that. It looks like this in Eclipse:

grafik

I first run git pull origin master in cygwin64 and then in Eclipse, I build configure and then sub. Everything finishes without issues. Is this the correct approach?

Thank you for the hint, I will try this out!

I am using this particular channel because it is also used in the existing code to access the lights (line 235 in joystick.cpp):

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);
    }
    break;

I find it weird my modification seems to knock out this existing code as well. Is there anything else I need to do with the lights1 variable maybe?

Hi,

This is actually affecting RC_IN. You need to check the corresponding SERVOX_FUNCTION and check if it is set to “RCIN9”

Yeah, your branch is based on master, not stable (ArduSub-stable). This means you get new features and possibly some bugs.

After being diverted to another project for a couple of months, I finally managed to solve the issue (it was a hardware problem :roll_eyes:). I also switched to the ArduSub-stable branch and I am not getting the IMU errors anymore. The code in my original post now works without any problems, in case anybody wants to have a play around :slight_smile:
Channel 8 (which maps to channel 9) was the correct one for our setup.

Thank you @williangalvani !

2 Likes