Servers by jDrones

How to connect a Virtual Joystick to APM with no RC?

Hello everyone, I’m a new developer and I’m seeking help with a joystick issue, I hope I’m in the right place.

Basically, what I want to do is to send joystick commands to APM (ArduPilot Mission planner) from another program with Json messages. The idea is to not necessarily have an RC connected to a vehicle and neither a real joystick enabled.

I can create an instance of the RC and send my virtual commands like is shown below. The problem is that it seems to me like APM needs to have joystick controller input detection running to send virtual RC commands.

My code works on simulation sometimes but you do need to have an RC or a real joystick enabled with to arm a real drone. Is there a way I can override this? Thank you!

MAVLink.mavlink_manual_control_t virtualRc = new MAVLink.mavlink_manual_control_t();
        virtualRc.target = MainV2.comPort.MAV.compid;

        if (MainV2.sitl)
        {               
                byte[] rcreceiver = new byte[2 * 8];
                Array.ConstrainedCopy(BitConverter.GetBytes((short)roll), 0, rcreceiver, 0, 2);
                Array.ConstrainedCopy(BitConverter.GetBytes((short)pitch), 0, rcreceiver, 2, 2);
                Array.ConstrainedCopy(BitConverter.GetBytes((short)throttle), 0, rcreceiver, 4, 2);
                Array.ConstrainedCopy(BitConverter.GetBytes((short)yaw), 0, rcreceiver, 6, 2);
                Array.ConstrainedCopy(BitConverter.GetBytes((ushort)MainV2.comPort.MAV.cs.rcoverridech5), 0, rcreceiver, 8, 2);
                Array.ConstrainedCopy(BitConverter.GetBytes((ushort)MainV2.comPort.MAV.cs.rcoverridech6), 0, rcreceiver, 10, 2);
                Array.ConstrainedCopy(BitConverter.GetBytes((ushort)MainV2.comPort.MAV.cs.rcoverridech7), 0, rcreceiver, 12, 2);
                Array.ConstrainedCopy(BitConverter.GetBytes((ushort)MainV2.comPort.MAV.cs.rcoverridech8), 0, rcreceiver, 14, 2);

                SITL.SITLSEND.Send(rcreceiver, rcreceiver.Length);
            }
            return new JsonResponse(vehicle, true, "Joystick command received in the simulated vehicle");
        }
        else
        {
            virtualRc.z = (short)throttle;
            virtualRc.y = (short)roll;
            virtualRc.r = (short)yaw;
            virtualRc.x = (short)pitch;

            MainV2.comPort.sendPacket(virtualRc, MainV2.comPort.MAV.sysid, MainV2.comPort.MAV.compid);
            return new JsonResponse(vehicle, true, "Joystick command received in the real vehicle");
        }
Servers by jDrones