Proper Mavlink message for offboard mode control?

I am creating this Mavlink message to send to jmavsim SITL.
It sends successfully but the quadcopter does not move. It does slightly tilt to one side for a couple seconds but that is all.

I can’t find a resource anywhere that will confirm or deny I have the proper layout to send this. The pixhawk switches to offboard mode as well since I have this looping at 20 hertz.

msg = vehicle.message_factory.set_position_target_local_ned_encode(
0, # time_boot_ms
0, 0,
mavutil.mavlink.MAV_FRAME_LOCAL_NED, # frame
0b110111000011, # type_mask (only positions enabled)
5, 5, 5, # x, y, z
0, 0, 0, # x, y, z velocity in m/s
0, 0, 0, # x, y, z acceleration
0, 0) # yaw, yaw_rate

The main trick which it sounds like you’re aware of is you have to send your commands at a fast enough rate to keep in offboard mode. Otherwise it will fall back to (loiter?) mode I’m assuming as a safety measure. According to this, https://dev.px4.io/en/ros/mavros_offboard.html its 2Hz,

First start your loop sending the set_position_target_local_ned_encode commands at this rate, if you dont want to actually execute it then set the mask to ignore all inputs. Once you have this loop running in some thread switch modes to offboard and block until set.

I’m using DroneKit and pymavlink and I change modes something like this,

 while self.mode != "OFFBOARD":
    self._master.set_mode_px4('OFFBOARD', None, None)
    time.sleep(1)

Looking at your mask it looks different than mine which is 0b0000111111111000

According to http://mavlink.org/messages/common#SET_ATTITUDE_TARGET

It says

Bitmask to indicate which dimensions should be ignored by the vehicle: a value of 0b0000000000000000 or 0b0000001000000000 indicates that none of the setpoint dimensions should be ignored. If bit 10 is set the floats afx afy afz should be interpreted as force instead of acceleration. Mapping: bit 1: x, bit 2: y, bit 3: z, bit 4: vx, bit 5: vy, bit 6: vz, bit 7: ax, bit 8: ay, bit 9: az, bit 10: is force setpoint, bit 11: yaw, bit 12: yaw rate

So right now you are ignoring x and y positions

1 Like