Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect handling of PARAM_EXT_SET message for custom camera parameters #51

Open
kuroshZ opened this issue Nov 13, 2024 · 0 comments
Open

Comments

@kuroshZ
Copy link

kuroshZ commented Nov 13, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant