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

AP_DDS: support automatic reconnect to micro-ROS agent #25228

Merged
merged 1 commit into from
Nov 10, 2023

Conversation

srmainwaring
Copy link
Contributor

Add ping test and attempt to automatically reconnect to the micro-ROS agent.

Closes #23372

For details see: #23372 (comment)

Copy link
Collaborator

@Ryanf55 Ryanf55 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, it works great on multiple interface cycles. Super fantastic improvement to the behavior.

image

update();

// check ping response
if (session.on_pong_flag == 1) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use PONG_IN_SESSION_STATUS instead of magic 1, which is set in session.h of the Micro-XRCE-DDS-Client library>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hal.scheduler->delay(1);
update();
if (comm == nullptr) {
GCS_SEND_TEXT(MAV_SEVERITY_ERROR, "DDS Client: transport invalid, exiting");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is set from uxr_init_session(&session, comm, key);, so perhaps better wording would be session invalid?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think the wording is ok: comm is set when the transport initialises - before the session is initialised.

bool AP_DDS_Client::ddsSerialInit()
{
    // setup a framed transport for serial
    uxr_set_custom_transport_callbacks(&serial.transport, true,
                                       serial_transport_open,
                                       serial_transport_close,
                                       serial_transport_write,
                                       serial_transport_read);


    if (!uxr_init_custom_transport(&serial.transport, (void*)this)) {
        return false;
    }
    comm = &serial.transport.comm;

++num_pings_missed;
}

uxr_ping_agent_session(&session, 0, 1);
Copy link
Collaborator

@Ryanf55 Ryanf55 Oct 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you intend to set a timeout of 0 here? Note - for a non-obvious C-api like this one, I might actually just create some constexpr locals to show what is being passed in.

constexpr int timout_ping_ms {0};
constexpr int ping_attempts {1};
uxr_ping_agent_session(&session, timout_ping_ms, ping_attempts);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added const stack variables in:
a14e0af

Didn't add constexpr as we're adding for readability and are happy for the compiler to optimise these away.

The 0 timeout looks odd doesn't it? This is consistent with the approach used by the PX4 DDS implementation - it must be trying to poll at least once otherwise I'd expect a timeout. Need to trace this more thoroughly to understand why it does not fail every time.

- Add ping test and attempt reconnect if connection dropped.
- Retry ping test max_attempts before exiting.
- Move `uxr_init_session` from transport init to session init for reconnect
- Tidy handling of transport.comm
- Fix codestyle

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_DDS: use PONG_IN_SESSION_STATUS in status check

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_DDS: add local variables to clarify arguments to uxr_ping_agent_session

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
@Ryanf55 Ryanf55 added MergeOnCIPass For-4.5 Planned for 4.5 release labels Nov 8, 2023
@peterbarker peterbarker merged commit 125c8fa into ArduPilot:master Nov 10, 2023
86 checks passed
@srmainwaring srmainwaring deleted the prs/pr-dds-reconnect branch November 10, 2023 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For-4.5 Planned for 4.5 release ROS
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

AP_DDS: Automatic reconnect to MicroROS Agent not working
3 participants