Can't Take off with companion computer

Hello everyone,

I’m trying to take off the drone by sending MAVLink command with a companion computer.

So far I have managed to set the flight mode and arm/disarm the drone.

My procedure is :

  • Set the mode to GUIDED
  • ARM the drone
  • send a take off command with mavlink

The code looks like this (I’m using this library ESP32-MAVLink)

void MAVLink::takeoff(const float& height){ 
  Serial.printf("Waypoint %d (takeoff) set as latitude : %f, longitude : %f, height : %f\n", this->mis_seq + 1, this->home_pos[0] / 1e7, this->home_pos[1] / 1e7, height);
  mavlink_message_t msg;
  uint8_t buf[MAVLINK_MAX_PACKET_LEN];

  this->fly_alt = height;

  uint16_t command = 22; //takeoff
  uint8_t conf = 0;
  float param7 = height;

  mavlink_msg_mission_item_int_pack(
    this->sys_id, 
    this->comp_id,
    &msg, 
    this->tgt_sys, 
    this->tgt_comp,
    this->mis_seq,
    MAV_FRAME_GLOBAL_RELATIVE_ALT_INT, 
    command,
    1,
    1,  
    0, 0, 0, 0,
    this->home_pos[0], // Home position latitude
    this->home_pos[1], // Home position longitude
    param7,
    MAV_MISSION_TYPE_MISSION
  );

  uint16_t len = mavlink_msg_to_send_buffer(buf, &msg);

  Serial1.write(buf, len);
}

I am aware that this library is not perfect for my needs and that I may have to modify the MAVLink params but I’m not sure how.

After executing the code I get a message error :

Mission unaccepted with enum 1	

Enum 1 is for Generic error / not accepting mission commands at all right now.
On mission planner I get this message :

got MISSION_REQUEST; use MISSION_REQUEST_INT!

I have the same error message when trying to set a waypoint or land the drone.

I don’t know how I’m supposed to fix that…
Thank you :slight_smile:

set mode to stabilize
arm
set mode to guided
wait for 300ms
send command MAV_CMD.Takeoff, where param7 is the desired altitude. (use command_long, not mission item)

Any reason or consideration why you didn’t select raspberry pi.

My goal is to have a <250g drone
The RPI board is too heavy and consumes too much.

I am now looking for an ESP32 MAVLink library and I am considering MAVSDK, not sure yet

Not sure if your ESP32 OS environment can handle that or not.

What about using a raspberry zero ?

1 Like

I wish I could but it is not how my team decided the project’s requirements

Now I’m trying to set up an environment for MAVLink & ESP32, doesn’t seem very easy …

It seems to work, thank you !

Should I be using command_long for everything (take off, waypoint, land, RTL, …) and for retrieving telemetries from the drone ?

Nope, please familiarize yourself with the Mavlink protocol, especially the microservices…
https://mavlink.io/en/

1 Like

I studied the mavlink protocol and rewritten some of my functions.

For takeoff I get an error 4 (MAV_RESULT_FAILED)

here is my command:

  uint16_t command = 22; //takeoff
  uint8_t conf = 0;
  float param7 = height;

  mavlink_msg_command_long_pack(
    this->sys_id, 
    this->comp_id,
    &msg, 
    this->tgt_sys, 
    this->tgt_comp,
    command,
    conf,
    0, // param1  
    0, 0, NAN,
    NAN, // Home position latitude
    NAN, // Home position longitude
    param7
  );

I have the same issue for repositining the drone (it is recommanded to use REPOSITION COMMAND for guided mode).

void MAVLink::reposition(const float& lat, const float& lng, const float& hgt){
  Serial.printf("Repositioning drone\n");

  mavlink_message_t msg;
  uint8_t buf[MAVLINK_MAX_PACKET_LEN];

  uint16_t command = 192; //reposition https://mavlink.io/en/messages/common.html#MAV_CMD_DO_REPOSITION
  uint8_t conf = 0;
  float param1 = -1;
  float param7 = hgt;

  mavlink_msg_command_int_pack( // https://mavlink.io/en/messages/common.html#COMMAND_INT
    this->sys_id, 
    this->comp_id,
    &msg, 
    this->tgt_sys, 
    this->tgt_comp,
    MAV_FRAME_GLOBAL_RELATIVE_ALT,  // https://mavlink.io/en/messages/common.html#MAV_FRAME_GLOBAL
    command,
    0,
    0,
    param1,    // : default speed
    1,         // MAV_DO_REPOSITION_FLAGS
    0,
    NAN,
    (int32_t)(lat * 1e7),  // Convert latitude to scaled integer
    (int32_t)(lng * 1e7),  // Convert longitude to scaled integer
    param7                 // Altitude or any other parameter as needed
  );

Also, I cannot retrieve some telemetries via MAVLink, the value is 0 but I can still the value in real time on mission planner…

Rightnow I have a lot of safety check disabled. Could that be the reason for all those errors ?

Any help is welcome :slight_smile: