Switch Pixhawk modes with Arduino using MAVLINK

Hey everyone

I am currently building a tracked rover for a school project and it is controlled with a pixhawk autopilot and i would like to be able able to switch "flight modes" (from auto to manual/manual to auto) with an arduino mega when it detects an object infront of it ( I have the code for the distance sensors already) however i am struggling with the code to send signal to switch modes through MAVLINK ( beginner to the communication between the two) so i was wondering what a code looks like , if anyone has examples as to then just edit to my configuration

I was also wondering how to control a gimbal from the pixhawk using my ground station controller (9XR Pro)

Thanks in advance

Any news on the problem? Did you manage to solve it or did you find another way around it?

I am working on an autonomous rover and I have a similar challenge.

Thank you in advance!
Best regards