Offboard control without ROS

I am trying to control the pixhawk through serial communication using MavLink. I am able to send and receive messages from the pixhawk but I do not receive x-y local position as there is no GPS in the indoor environment.

It also refuses to accept setpoints. Considering the quad stays stable when being flown by r/c in the same environment, surely it is possible to have offboard control. All the tutorials seem to use ROS and it very hard to find info on how to do this using C/C++.

Any tips on the steps that need to be taken would be greatly appreciated. As of now I can get it to arm, go into offboard mode, and that’s about it. How do I command it to move to a set x-y position? If that is not possible then even if i can send it commands to control attitude that would be fine as I would be able to move the craft? Something similar to what the r/c controller would send to command the pixhawk.

The system will only accept position set points if it has local position estimates available, which means that you will need MOCAP data, spoofed GPS, or optical flow + range detection.

These alternate features have to be explicitly enabled in some of the state estimators (LPE, EKF2) by setting parameters, which can be done in QGroundControl.

Thanks for the reply!

So if it will not accept set points without local position, is it possible to control the attitude (roll,pitch,yaw,thrust) in some way?

Can I use the mavlink msg: RC_CHANNELS_OVERRIDE to spoof r/c control?

I think it won’t accept local position setpoints without local position estimates (can’t do closed loop position control without position estimates).

You could spoof the rc channels, but that seems a bit convoluted, since you will have to map attitude / accelleration to equivalent rc signals. This may require knowledge of the rc calibration to do the inverse mapping. Furthermore, if for some reason the vehicle switches control modes, i.e. from manual to attitude, then the interpretation of the rc channels will change.

It is my understanding that the attitude set point is used by the attitude controller to generate the control outputs. But you should have a look at the software architecture in the docs, they are quite helpful.

Here is one way to get it working; have the GCS computer send attitude_setpoint and offboard_control_mode messages to the pixhawk via a radio. Switch the control mode into offboard via a mode switch on your rc transmitter. Then the mavlink receiver should publish attitude_setpoint messages that it receives, which will be used by the attitude controller.

For reference, here is some relevant code from the mc_position_control module:

indent preformatted text by 4 spaces    		
        /* publish attitude setpoint
	 * Do not publish if offboard is enabled but position/velocity/accel control is disabled,
	 * in this case the attitude setpoint is published by the mavlink app. Also do not publish
	 * if the vehicle is a VTOL and it's just doing a transition (the VTOL attitude control module will generate
	 * attitude setpoints for the transition).
	 */
	if (!(_control_mode.flag_control_offboard_enabled &&
	      !(_control_mode.flag_control_position_enabled ||
		_control_mode.flag_control_velocity_enabled ||
		_control_mode.flag_control_acceleration_enabled))) {

		if (_att_sp_pub != nullptr) {
			orb_publish(_attitude_setpoint_id, _att_sp_pub, &_att_sp);

		} else if (_attitude_setpoint_id) {
			_att_sp_pub = orb_advertise(_attitude_setpoint_id, &_att_sp);
		}
         }

From here you can see that the position control module will defer to the mavlink receiver for attitude setpoint messages. The other three flags for acceleration, velocity, and position, are related to to the position control mode (i.e. they require GPS / optical flow & range detection / motion capture to estimate vehicle translation).

Hey Joseph,

We got a px4flow module and now the systems has local position estimates but still won’t accept setpoints.

I am sending position set points once every 0.2 seconds and there is no change in the motor outputs.

Am i missing something?

are you sending MAV_CMD_NAV_GUIDED_ENABLE ?