How to control motor movements and throttle using Arduino IDE, MAVLink, and Pixhawk

Hello everyone,

I am implementing the connectivity between the Pixhawk(2.4.8) and webapp. Please find the project setup information below,

Setup details :

  1. pixhawk 2.4.8
  2. ESP 8266
  3. M8N gps
  4. 2 wheel with motor
  5. R8FM Radio link to control motors
  6. Battery (2200mAh)

Development Tool:

I Using "Arduino IDE" tool to write code in ESP8266.

Installed Libraries:

  1. MAVLink.h
  2. Arduino.h

Setup Image:

By using the above setup, I can arm & disarm and control left and right motors using Joystick controller.

QGC Connection:

What we trying to do?

Here instead of Joystick we trying to control the project setup via web app. I established the connection between Pixhawk and server via webscoket (for data transfer between server and project setup). I can able to get the device info (GPS, motor and battery info) to webserver via custom code written in ESP 8266.

Problem Facing:

Same like, we trying to give input to arm & disarm and to control left and right motors. From the code written in ESP8266, cmd given to arm & disarm is working

CMD to arm and disarm:

arm command :
mavlink_msg_command_long_pack(
255, // System ID
190, // Component ID
&msg, // MAVLink message
1, // Target system ID (Pixhawk)
0, // Target component ID (all components)
MAV_CMD_COMPONENT_ARM_DISARM, // Command ID
0, // Confirmation
1, 0, 0, 0, 0, 0, 0 // Parameters (1 to arm)
);

disarm command :
mavlink_msg_command_long_pack(
255, // System ID
190, // Component ID
&msg, // MAVLink message
1, // Target system ID (Pixhawk)
0, // Target component ID (all components)
MAV_CMD_COMPONENT_ARM_DISARM, // Command ID
0, // Confirmation
0, 0, 0, 0, 0, 0, 0 // Parameters (0 to disarm)
);

but the cmd to control the left and right motors are not accepted by the kit.

CMD to run motors:

mavlink_msg_command_long_pack(
	255, 190, &msg,
	1, 0,
	MAV_CMD_DO_CHANGE_SPEED,
	0,
	MAV_MODE_FLAG_CUSTOM_MODE_ENABLED, MAV_MODE_MANUAL_ARMED, throttle, 0, 0, 0, 0
);

Please find the QGC logs:

I checked the QGroundControl (QGC) logs, which only show 'arm' and 'disarm' logs. There are no throttle or other command logs.

Questions:

  1. Can you confirm my libraries are correct ?
  2. What are the mavlink commands to control left and right motors ? - to spin front and back
  3. Is there is any alternative libraries to control whole devices ?
  4. Is there is any existing solution to control pixhawk and its connected device via web ?

This is Ardupilot stuff, you'll probably find your answers there.
https://ardupilot.org/ardupilot/index.html