Offboard Mode of Pixhawk
- The vehicle obeys a position, velocity or attitude setpoint provided over MAVLink (often from a companion computer connected via serial cable or wifi). The setpoint can be provided by MAVROS.
- This mode requires position or pose/attitude information - e.g. GPS, optical flow, visual-inertial odometry, mocap, etc.
- This mode is automatic (RC control is disabled by default except to change modes).
- The vehicle must be armed before this mode can be engaged.
- The vehicle must be already be receiving a stream of target setpoints before this mode can be engaged.
- The vehicle will exit the mode if target setpoints are not received at a rate of > 2Hz.
- Other operations, like taking off, landing, return to launch, are best handled using the appropriate modes. Operations like uploading, downloading missions can be performed in any mode.
- A stream of setpoint commands must be received by the vehicle prior to engaging the mode, and in order to remain in the mode (if the message rate falls below 2Hz the vehicle will stop). In order to hold position while in this mode, the vehicle must receive a stream of setpoints for the current position.
Uses of Offboard Mode
It can be used to
- Control vehicle position, velocity, or thrust (SET_POSITION_TARGET_LOCAL_NED).
- Control vehicle attitude/orientation (SET_ATTITUDE_TARGET).
How to use it?
- We have to publish setpoints to the topic /mavros/setpoint_raw/local. These setpoints must be local i.e. use w.r.t. current local position (x, y, z).
- The message is of the type PositionTarget.
- Otherwise, we can publish to /mavros/setpoint_raw/global. These setpoints must be global i.e. use w.r.t. current GPS data (latitude, longitude, altitude).
- Using appropriate bitmasks, we can select between position, velocity or thrust control. See this for bitmask information. We can have position control in x, y, z or have velocity control in x, y and position control in z, etc. (all sorts of combinations possible).
- Yaw control (mentioned in the bitmask and the message) could not be done correctly yet.
- If using position setpoints in offboard mode, then velocity of quad is equal to the maximum set in MPC_XY_CRUISE parameter (available in QGC). The FCU applies this maximum velocity to the quad until setpoint is achieved.
Simulation using Gazebo and ROS (MAVROS)
Follow the initial setup instructions from here.
Code Editor
Python Script for position setpoints
Running the following script in a new terminal while running the simulator and MAVROS (as explained in the previous step), will make the quad in the simulation to takeoff to a height of 3m and maintain position (x, y) = (0, 0).
You can modify it to publish setpoints and move it around. Or you can modify the PositionTarget bitmask to get velocity control and publish velocity setpoints in a similar way.
Note : There is a lot of extra code in this - implementing functions to change to other modes and so on. They maybe useful later on or can be removed to keep the code short.
You can modify it to publish setpoints and move it around. Or you can modify the PositionTarget bitmask to get velocity control and publish velocity setpoints in a similar way.
Note : There is a lot of extra code in this - implementing functions to change to other modes and so on. They maybe useful later on or can be removed to keep the code short.
Hope this helped you to understand and simulate offboard mode. I will update this with any new information I get. Please contact me if you find anything wrong with this or if something is missing.
This task was done as part of the Autonomous Drone Delivery Project (Project Garuda) of IvLabs. Check out it's website.