Skip to content

Incorrect handling of PARAM_EXT_SET message for custom camera parameters #51

@kuroshZ

Description

@kuroshZ

Problem:

The PARAM_EXT_SET message (ID 323) uses a char[128] array for param_value, but its interpretation depends on MAV_PARAM_EXT_TYPE. Current implementation incorrectly treats all values as strings.
Example :

 auto command = message_set.create("PARAM_EXT_SET");
  float val = 30.0f;
  std::memcpy(&param_val, &val, sizeof(float));
  command.set({
      {"target_system", 0},
      {"target_component", MAV_COMP_ID_CAMERA},
      {"param_id", "YAW ANGLE"},
      {"param_value", val},
      {"param_type", MAV_PARAM_EXT_TYPE_REAL32},
  });
  fmt::print("command: {} \n ", command.toString());
  send_command(command);

Output:

 param_id: "YAW ANGLE"
  param_type: 9
  param_value: ""
  target_component: 100
  target_system: 0

The correct way of putting this message together is for example to use memcpy to copy the float value to the char array (example using c_library_v2 ):

void send_param_ext_sent()
    {
        mavlink_message_t msg;
        mavlink_param_ext_set_t param_ext;
        param_ext.target_system = 0;
        param_ext.target_component = MAV_COMP_ID_CAMERA;
        std::string param_id = "YAW ANGLE";
        std::copy(param_id.begin(), param_id.end(), param_ext.param_id);
        param_ext.param_id[param_id.size()] = '\0';

        float value = 60.0f;
        memcpy(param_ext.param_value, &value, sizeof(float));

        param_ext.param_type = MAV_PARAM_EXT_TYPE_REAL32;

        mavlink_msg_param_ext_set_encode(255, 0, &msg, &param_ext);
        uint8_t buffer[MAVLINK_MAX_PACKET_LEN];
        uint16_t len = mavlink_msg_to_send_buffer(buffer, &msg);

        asio::write(socket_, asio::buffer(buffer, len));
        fmt::print("Sent PARAM_EXT_SET\n");
    }

Question:

Is there a quick fix for this issue in the Message Object implementation, or is it possible to manually set the value as a workaround?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions