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

Dds prototype #17779

Merged
merged 12 commits into from
Mar 21, 2023
Merged

Dds prototype #17779

merged 12 commits into from
Mar 21, 2023

Conversation

arshPratap
Copy link
Member

@arshPratap arshPratap commented Jun 15, 2021

Hello Ardupilot community!
This PR is work in progress and consists of the prototype code that aims to provide DDS functionality to Ardupilot for effective communication with ROS2 and Native DDS implementations

Added 2 IDL files

  • A simple Num idl to test the xrce dds functionality
  • AP_INS idl file for sending INS info

Added the eProsima XRCE Client lib as submodule
Provides Ardupilot an XRCE client to communicate with DDS/ROS2 through :
Serial(Main focus)
UDP(Only for testing,to be removed in final version)

Current Issues

  • Have tested the code through serial communication and sometimes it is found that data is not properly flushed out in the serial ports resulting in communication to XRCE agent being cut.Working on implementing a function to take care of this issue.
  • Have doubts related to setting up the build system to install the XRCE Client from the necessary submodules

Thanks !

}

if (this->use_serial) {
this->fd=open("/dev/ttyUSB1", O_RDWR | O_NOCTTY | O_NONBLOCK);
Copy link
Contributor

Choose a reason for hiding this comment

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

You should get a serial object from the hal that way you ensure that the port is configured correctly

Copy link
Contributor

Choose a reason for hiding this comment

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

Also this should be made available on other serial ports as well... maybe check how other libraries are implemented and the parameter system that sets them up.

@rishabsingh3003 rishabsingh3003 added the GSoC Google Summer of Code label Jun 16, 2021
@jmachuca77 jmachuca77 requested review from tridge and peterbarker June 16, 2021 14:45
Copy link
Contributor

@peterbarker peterbarker left a comment

Choose a reason for hiding this comment

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

Rough pass only.

ArduCopter/Copter.cpp Outdated Show resolved Hide resolved
ArduCopter/xrce-client.cpp Outdated Show resolved Hide resolved
ArduCopter/xrce-client.cpp Outdated Show resolved Hide resolved

bool AP_INS_serialize_topic(ucdrBuffer* writer, const AP_INS* topic)
{
(void) ucdr_serialize_int32_t(writer, topic->accel_count);
Copy link
Contributor

Choose a reason for hiding this comment

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

This casting-to-void is a bit of a red flag for me. If it is warranted then it deserves a comment.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like the examples in the XRCE-DDS also do this by some poor convention even though there is a perfectly good return code to consume and pass up to the application. After stripping down this implementation, I'll make sure the error codes get passed up.

Quick question - Is C++17, specifically [[nodiscard]] allowed here?

Copy link
Collaborator

@Ryanf55 Ryanf55 Feb 24, 2023

Choose a reason for hiding this comment

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

I can submit a PR upstream - this serialization function is actually adapted from the generated code from MicroXRCEDDSGen. I agree, we should not discard write issues.

  • Submit PR upstream to not void cast
  • Add submodule for fastddgen
  • Remove manually written serialization instead with autogenerated files using waf

Copy link
Collaborator

Choose a reason for hiding this comment

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

eProsima/Micro-XRCE-DDS-Gen#45
Created issue and submitted PR.

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 now part of our generator. Resolved.

* @brief This struct represents the structure AP_INS defined by the user in the IDL file.
* @ingroup AP_INS
*/
typedef struct AP_INS
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason you need a typedef?

Comment on lines 17 to 18
if (this->use_serial) {
this->fd=open("/dev/ttyUSB1", O_RDWR | O_NOCTTY | O_NONBLOCK);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (this->use_serial) {
this->fd=open("/dev/ttyUSB1", O_RDWR | O_NOCTTY | O_NONBLOCK);
if (use_serial) {
fd = open("/dev/ttyUSB1", O_RDWR | O_NOCTTY | O_NONBLOCK);

(as @jmachuca77 says, use the serial manager instead; you can still use a real serial device easily enough)

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's being used now.

Comment on lines 24 to 28
else {
if(!uxr_init_udp_transport(&this->udp_transport,UXR_IPv4,ip,port)) {
return false;
}
uxr_init_session(&this->session, &this->udp_transport.comm, 0xAAAABBBB);
Copy link
Contributor

Choose a reason for hiding this comment

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

We do not want to support UDP with this at this time - simplify the PR by always assuming use_serial

Also... dispense with this-> in member functions.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Done and Done.

bool AP_XRCE_Client::create()
{

if(_csem->take(5)){
Copy link
Contributor

Choose a reason for hiding this comment

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

taking-with-timeout is almost always something you do not want to do.

Also, usually you want to be doing WITH_SEMAPHORE(_csem)

Copy link
Collaborator

@Ryanf55 Ryanf55 Mar 14, 2023

Choose a reason for hiding this comment

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

Done (already)

Comment on lines 98 to 100
if(_csem->take(5)){
if(this->connected)
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid indenting

Suggested change
if(_csem->take(5)){
if(this->connected)
{
if(!_csem->take(5)){
return;
}
if(!this->connected)
return;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Everything is formatted with astyle on the PR.

Comment on lines 65 to 66
uxrObjectId dwriter_id ;
uint16_t dwriter_req ;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
uxrObjectId dwriter_id ;
uint16_t dwriter_req ;
uxrObjectId dwriter_id;
uint16_t dwriter_req;

and everywhere else

Copy link
Collaborator

Choose a reason for hiding this comment

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

Format is resolved with astyle

@peterbarker
Copy link
Contributor

peterbarker commented Jun 18, 2021 via email

@jmachuca77
Copy link
Contributor

Adding to the conversation so we can keep track and for easier discussion.
The pr in its current form add the submodule to the project, however it still requires manual installation of the libraries and its looking to the system folders for those libraries.
These are the instructions for building the XRCE client:
https://micro-xrce-dds.docs.eprosima.com/en/latest/installation.html

This needs to be added to the waf build system.

@arshPratap arshPratap force-pushed the ddsPrototype branch 5 times, most recently from af7d461 to ca2728d Compare July 14, 2021 13:49
@tridge
Copy link
Contributor

tridge commented Jul 16, 2021

it looks like we will need to do config.h.in processing

@tridge
Copy link
Contributor

tridge commented Jul 16, 2021

@arshPratap I've added the waf rules for config.h generation here:
https://github.com/tridge/ardupilot/commits/ddsPrototype

@arshPratap arshPratap force-pushed the ddsPrototype branch 3 times, most recently from d07b90f to bfce51a Compare August 10, 2021 23:44
@arshPratap arshPratap force-pushed the ddsPrototype branch 3 times, most recently from a8c1c7b to 3c9882f Compare August 19, 2021 14:25
@amfern
Copy link

amfern commented Sep 6, 2021

This is a very good work, i am wondering why you opted out to use XRCE client directly and not use https://github.com/micro-ROS/micro_ros_setup for example like https://github.com/micro-ROS/micro_ros_arduino

@rmackay9 rmackay9 mentioned this pull request May 24, 2022
@eMrazSVK
Copy link

Hello, is there any progress regarding implementing direct DDS ROS2 communication with ardupilot? Thank you.

@arshPratap
Copy link
Member Author

Hello, is there any progress regarding implementing direct DDS ROS2 communication with ardupilot? Thank you.

Hi @eMrazSVK ! I am so sorry I wasnt able to work on this in the recent time due to my current predicaments, but I would love to resume working on it and collaborating if you are intereseted! You can mail me : [email protected] for further information.In the mean time I would love if you could take a look here : https://github.com/arshPratap/ardupilot_ros2
and https://discuss.ardupilot.org/t/ardupilot-native-ros2-support/73720

@eMrazSVK
Copy link

Thank you for your quick response @arshPratap.

If I decided to collaborate on this, could you give me just a really rough estimate of how much time would be needed to fully implement this? Are we speaking weeks, months or years?

Thank you once again.

@arshPratap
Copy link
Member Author

arshPratap commented Sep 16, 2022

Thank you for your quick response @arshPratap.

If I decided to collaborate on this, could you give me just a really rough estimate of how much time would be needed to fully implement this? Are we speaking weeks, months or years?

Thank you once again.

I am not sure on the time frame as I believe there are few things currently in this project that I believe need to be taken care of first :

  • Working on the some of the dependencies to make sure a smooth installation of the project could be done

But I believe that this PR has been idle for a long time and I would love to see this merged as soon as possible. Also the fact that since you are interested to collaborate on this , makes me think we can work on this faster and i think we can have a month's time as a nice deadline on this. @eMrazSVK Let me know what you think...and lets start the work immediately

@Ryanf55
Copy link
Collaborator

Ryanf55 commented Mar 14, 2023

On Wed, 16 Jun 2021, Pierre Kancir wrote: You should see this as the mavlink xml, it is the definition to generate the AP_INS.cpp code that is auto generated
We don't commit the generated code in ArduPilot :-)

We generate the code now in waf, it shows up in the build directory at build time.

Copy link
Contributor

@khancyr khancyr left a comment

Choose a reason for hiding this comment

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

partial review only.
Seems ok. build looks constraint.
test build are ok
documentation is readable for dev!

libraries/AP_DDS/AP_DDS_Client.cpp Outdated Show resolved Hide resolved

void AP_DDS_Client::update_topic(builtin_interfaces_msg_Time* msg)
{
if (msg != nullptr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Early return here rather than indent. Possibly doing an internal error first?

Copy link
Collaborator

Choose a reason for hiding this comment

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

update_topic is called at a very high rate. Is it OK to do internal errors at that high rate?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Now that it's passed by reference, this is no longer an error condition.


#include "AP_DDS_Topic_Table.h"

void AP_DDS_Client::update_topic(builtin_interfaces_msg_Time* msg)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not take a reference instead?!

Suggested change
void AP_DDS_Client::update_topic(builtin_interfaces_msg_Time* msg)
void AP_DDS_Client::update_topic(builtin_interfaces_msg_Time& msg)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Done in fc514d56571d59e90a906fd36699ae0219e68973

@Ryanf55
Copy link
Collaborator

Ryanf55 commented Mar 21, 2023

Once CI passes the current build, I'll do a final cleanup on the commit history and tag for merge on build success. All PR feedback is now done. Re-tested fine after final cleanup.

Comment on lines +29 to +30
msg.sec = utc_usec / 1000000ULL;
msg.nanosec = (utc_usec % 1000000ULL) * 1000UL;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
msg.sec = utc_usec / 1000000ULL;
msg.nanosec = (utc_usec % 1000000ULL) * 1000UL;
msg = {
utc_usec / 1000000ULL,
(utc_usec % 1000000ULL) * 1000UL
};

Just a suggestion that you play with this. It means the structure is fully initialised on return, and gives you some type-checking too.

Copy link
Collaborator

@Ryanf55 Ryanf55 Mar 21, 2023

Choose a reason for hiding this comment

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

It sadly loses the context of the first element being seconds and the second element being nanoseconds. Unless you could use C++20's aggregate initialization that supports designated initializers. Maybe there a way to get the best of both worlds 🔍

Ryanf55 and others added 12 commits March 21, 2023 08:00
* Use interal forks

Signed-off-by: Ryan Friedman <[email protected]>
Co-authored-by: Arsh Pratap <[email protected]>
Co-authored-by: Andrew Tridgell <[email protected]>
Co-authored-by: Russ Webber <[email protected]>
Signed-off-by: Ryan Friedman <[email protected]>
Co-authored-by: Arsh Pratap <[email protected]>
Co-authored-by: Andrew Tridgell <[email protected]>
Signed-off-by: Ryan Friedman <[email protected]>
Co-authored-by: Rhys Mainwaring <[email protected]>
Co-authored-by: Arsh Pratap <[email protected]>
Co-authored-by: Andrew Tridgell <[email protected]>
* Use clang to verify no unused files
* Add a topic table to prepare for code generating interfaces
* Generated IDL's to to a generated directory in build
* Use black to format python files
* Populate a ROS time maessage with Linux epoch time for ROS time
* Add workarounds for PoseStamped and TwistStamped with manual mods to IDL

Signed-off-by: Ryan Friedman <[email protected]>
Co-authored-by: Rhys Mainwaring <[email protected]>
Co-authored-by: Arsh Pratap <[email protected]>
Co-authored-by: Andrew Tridgell <[email protected]>
Co-authored-by: Russ Webber <[email protected]>
Co-authored-by: Peter Barker <[email protected]>
Signed-off-by: Ryan Friedman <[email protected]>
Co-authored-by: Arsh Pratap <[email protected]>
Co-authored-by: Andrew Tridgell <[email protected]>
Co-authored-by: Russ Webber <[email protected]>
* Had to ignore pre-commit hooks for isort and mypy since there are unrelated broken issues in the file

Signed-off-by: Ryan Friedman <[email protected]>
Co-authored-by: Arsh Pratap <[email protected]>
Co-authored-by: Andrew Tridgell <[email protected]>
* Disabled by default

Signed-off-by: Ryan Friedman <[email protected]>
Co-authored-by: Arsh Pratap <[email protected]>
Co-authored-by: Andrew Tridgell <[email protected]>
Signed-off-by: Ryan Friedman <[email protected]>
Co-authored-by: Pierre Kancir <[email protected]>
@tridge tridge merged commit d05b598 into ArduPilot:master Mar 21, 2023
@russkel
Copy link
Contributor

russkel commented Mar 21, 2023

🎊 🥳

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 GSoC Google Summer of Code ROS
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.