Take off command from MAVLink

How do you send a command to takeoff directly from MAVLink (from a companion computer)? Right now via MAVLink I:
-check GPS and EKF to make sure I can arm the vehicle
-change mode to Guided

  • send the arm command (and verify the vehicle does in fact arm)
  • send this takeoff command:
    mavlink_msg_command_long_pack(250, 1, &message, 1, 1, MAV_CMD_NAV_TAKEOFF, 0, 0, 0, 0, 0, 0, 0, alt)
    (and then send it to the autopilot)

but the command is not accepted by the autopilot. Do I need to do anything else such as query or set the home position?