I’m trying to change the gain value through mavlink by “pushing” buttons virtually with pymavlink library.
For example here is my joystick configuration for gain buttons.
And here is my code to change gain value by pushing buttons.
buttons=1<<11 #11 for gain increase, 12 for gain decrease
This virtually pushing button thing is working on SITL(running on RASP+navigator) without any problem. It works on real robot as well, but there is a problem: my vehicle(RASP(blueos)+companion) disarm itself everytime I change the gain.
I don’t know what is the problem that disarms the vehicle automatically.
Thanks for your answers in advance.
Hi again @EliotBR,
I’m controlling the vehicle also by using pymavlink, by using “set_rc_channel_pwm(channel_id, PWM)” function of pymavlink. And I am controlling vehicle reading a custom joystick from python and sending appropriate control commands. The vehicle behaves itself very well with this configuration, there is no problem yet.
I’m reminding you that, I’m working on a Basic ROV gui and backend to both control robot and show telemetry datas.
I’m using qgroundcontrol to monitor the situation, and I can see that the vehicle is actually disarming.
No, it does not. It is working without a problem with using qgroundcontrol.
Hmm, odd. Does it also disarm when you send other joystick button commands, or just when you change the gain?
I’m actually trying to perform all the actions with mavlink commands if possible.
For example, I’m changing the mods (manual, stabilize, depth hold) with pymavlink functions. Since I did not find any function to change the gain value, that is why I decided to do that “virtually push” thing.
The other thing that I’m doing with buttons is camera mount_tilt_up and down joystick functions. And that function does not work at all by “virtually pushing”. I’m working on it rn, idk why this happens. I will inform.
Is there any problem about my button implementation code that you spotted?
If there is another option to do this by mavlink commands, please tell me, I prefer to try with commands.
ArduSub’s gain control mostly only makes sense in the case of a joystick, because human thumbs don’t gain extra fidelity by themselves when trying to limit the control actions. ArduSub’s gain functionality should work, and if it’s working through QGroundControl* then your code must be doing something differently.
That said, if you want equivalent behaviour without sending button commands you can just have a gain variable in your control code that scales down the values before they get sent to the autopilot.
*Note: In order to fully support joystick buttons, QGroundControl sends its motion commands and joystick button values to ArduSub via
Incrementing and decrementing the mount tilt angles should also work fine, although if you’re trying to avoid using the joystick button functions then you could achieve similar behaviour by
- changing the mount tilt output channel’s
SERVOn_FUNCTION parameter value from
- tracking the current output PWM value
- can be stored when you send one, or actively read from
SERVO_OUTPUT_RAW messages from the autopilot
- incrementing and decrementing that value in your code when the user tries to tilt the camera, in which case you can send a
MAV_CMD_DO_SET_SERVO command for the channel to change it.
- If relevant you could “clean up” before the vehicle turns off by setting the servo function back to
MountTilt before closing down
- that assumes a clean shut down (e.g. it wouldn’t be able to if the vehicle suddenly / unexpectedly disconnected, or was powered down without your program knowing it was going to lose connection).
Not necessarily, although commanding the vehicle to stop moving every time you want to send a joystick button function could be problematic, and it’s possible there’s an issue somewhere else in your code (or your general communications approach) that isn’t shown in the snippet you’ve provided.