I am trying to write my own HIL code that makes use of the MAVLINK protocol and a Pixhawk autopilot. I'll try to explain what I'm trying to do before I go into the problems I am having:
The overall architecture of my system is I want to use an actual Pixhawk to command motions in a simulated environment (in this case it is a ROS/Gazebo environment) and then have the simulated environment provide inputs back to the Pixhawk controller to subsequently update the motor commands (and so on...the loop continues). I will be getting waypoints from an external source to actually guide the motion, but that is neither here nor there at this point.
I have my simulation environment set up and sending a HIL_STATE MAVLINK message (this will be changed to the HIL_STATE_QUATERNION message in the near future) which should then be picked up by the Pixhawk and the controller should update motor/servo commands accordingly. The problem I am having is two-fold:
1) I can't seem to get the Pixhawk into HIL mode. I know there is a MAVLINK message "SET_MODE" but it doesn't seem to be working properly. (see https://pixhawk.ethz.ch/mavlink/ for the MAVLINK common messages)
2) I can't seem to find any messages that would dictate motor commands, either PWM or RPM directly.
So my questions are: 1) Does anyone know how to set the Pixhawk into HIL programmatically (i.e. without Mission Planner or other GCS software)? and 2) Does anyone have any insight into how I can get the controller output from the Pixhawk (i.e. the motor commands)?
Any help would be greatly appreciated, thank you!
P.S. I am doing this with a simulated quadrotor, but the same process will most likely be applied to a fixed wing as well, so either ArduCopter or ArduPlane suggestions would be helpful.