Home        Store        Docs        Blog

Custom Joystick Button Functions


#1

Hi BlueRobotics Team!

I currently have BlueRov2 and it has been working great !

Recently, however, I developed a need to add two additional components: a thruster and relay.

I have working prototype via the following steps:

  1. These components are connected the GPIO pins on the Raspberry Pi.
  2. The ESC for the thruster is connected to the PWM GPIO of the Pi
  3. The relay is connected to a generic GPIO pin.
  4. Both additional components can be controlled via a python script that I wrote, which I am happy to share.
  5. The python scripts were pushed onto the raspberry pi.
  6. We ‘ssh’ into the raspberry, execute the scripts, and use keyboard inputs to control the components

While this is great, typing in keyboard inputs in addition to using the joystick is difficult.

Therefore we are now at the point of wanting to setup custom Joystick Buttons to perform these functions.

From what I read from these two posts ( A little help on setting up a PWM Relay Switch? and Adding gripper servos to essentially a bluerov2-Ish rov), I believe there are two solutions. With each of the solutions, I have some questions on how to accomplish them.

S1: Connect my additional components inputs to the pixhawk and configure the buttons using QGroundControl. Looking at the following documentation (https://www.ardusub.com/operators-manual/button-functions.html) the pixhawk has a RELAY_PIN and Aux1. However, I am very confused on how to set each one up when looking at QGroundControl.
Q1: Does the RELAY_PIN refer to Aux5 or Aux6 ? What Pins are they? How can I pick which Aux pin they are assigned to ? (http://ardupilot.org/copter/docs/common-relay.html).
Q2: How can I change the BRD_PWM_COUNT value ? What effect does this have on the relay and PWM pins?
Q3: For the “servo_1_inc: Increase Aux1 servo output by 50 pwm” in the Servo Control subsection of https://www.ardusub.com/operators-manual/button-functions.html, what does 50 pwm mean? I am used to setting a frequency and duty cycle.

S2: Utilize the AP_JSButton.cpp and AP_JSButton.h API that you guys have gracefully provided ! I would rewrite my python scripts in c++ and read digital values from the joystick controller.
Q4: Is there example code on reading the digital values either from the buttons or joy stick on the controller? I am having a hard time understanding how to leverage the API to read joystick inputs.

Thank you!


(Jacob) #2

Q1: Does the RELAY_PIN refer to Aux5 or Aux6 ? What Pins are they? How can I pick which Aux pin they are assigned to ? (http://ardupilot.org/copter/docs/common-relay.html).

The default configuration is Aux1-4 configured for pwm, Aux 5/6 configured for relay. The BOARD_PWM_COUNT parameter controls how many pins are configured for pwm, starting at Aux1. This parameter controls the actual hardware to be able to perform the requested feature. The relay outputs can be remapped (among the allocated pins) using the RELAY parameters.

Q2: How can I change the BRD_PWM_COUNT value ? What effect does this have on the relay and PWM pins?

The parameter can be changed using the Parameters tab in the Vehicle Setup menu.

Q3: For the “servo_1_inc: Increase Aux1 servo output by 50 pwm” in the Servo Control subsection of https://www.ardusub.com/operators-manual/button-functions.html, what does 50 pwm mean? I am used to setting a frequency and duty cycle.

Increase the pulse width by 50 microseconds.

Q4: Is there example code on reading the digital values either from the buttons or joy stick on the controller? I am having a hard time understanding how to leverage the API to read joystick inputs.

Here’s how QGC does it. We are also working on a pure pymavlink example.