ROS2 interface for controlling thrust and attitude

Hi guys,

I am controlling a copter with ROS2 humble and I would like to ask how to send thrust + attitude cmd in guided and guided_noGPS modes.

I followed guides on Ardupilot webstite and SITM can run with ROS2 humble. However, ROS 2 Interfaces shows only ap/joy, ap/cmd_vel and ap/cmd_gps_pose are provided.

Unfortunately, it seems like none of them can enable me to send thrust + attitude commands. But I believe it should be possible, as there is already a function void AC_AttitudeControl::input_thrust_vector_heading(const Vector3f& thrust_vector, float heading_angle_cd, float heading_rate_cds), which is defined in ardupilot/libraries/AC_AttitudeControl /AC_AttitudeControl_Multi.cpp.

HI @robin_drone,

I think RyanF is probably best place to help here.

One thing I can add is we have the GUID_OPTIONS parameter that affects how mavlink SET_ATTITUDE_TARGET messages are interpreted (it changes whether the “thrust” field is interpreted as thrust or climb-rate. This may be unrelated though.

Thanks for the input. This isn’t yet supported. Please create an issue on Github, tag me me with the request (ryanf55) on Github, and we can work out a message definition suitable for the application. Once we have a suitable message chosen, it would be much appreciated if you wanted to contribute a feature for it.

Cheers!

1 Like

Thanks for your reply. Yes, that should be considered in ROS2 interface.

@rfriedman , thanks so much for your reply.

Yes, I am willing to help on this. Now, I am on holiday, let me create the request when I am back to work :).

1 Like

Here’s some related work from @snktshrma

@rfriedman , I am still working on this. Do you know if there is someone else interested in or working on that?

Just work it out with @snktshrma - it doens’t matter to me who finishes the feature. Whoever has time is ok.

Hi @robin_drone ! So individual Motor Control works fine and is complete. Here’s the PR:

For attitude and thrust control, I started it out but yet to complete. I’ll try to complete it this week. In any case, if you want to use direct motor control, feel free to use my PR.

Hi @snktshrma , sorry to reply so late. How is it going? Are you still working on thrust and attitude control?

Hi @robin_drone ! So the thrust and attitude code is done but there are changes to be done to XRCE c codegen. I did not get time to work on the codegen part. I’ll complete that over this weekend.

For the AP related changes, here it is: Commits · snktshrma/ardupilot · GitHub

1 Like

@snktshrma Hey, I had some doubts regarding how your code works. Is your code specifically for external controllers other than the autopilot board running ArduCopter?

Also, how does one control the thruster PWM of the ArduCopter board, say a Pixhawk 4, within a ROS 2 network?

Hi @robin_drone ! Here’s the official PR for this:

Hi @ishaan ! Yes, this is for offboard attitude and thrust control over ROS2 DDS.
This follows the similar message structure as Copter Commands in Guided Mode — Dev documentation

2 Likes

That is amazing!!!

@snktshrma ,Could you please briefly introduce how DDS of ROS2 communicate with ArduCopter in the source code?

Because I really want to contribute to ROS2-ArduCopter as well. Unfortunately, I have found little information about how it is implemented in the source code of ArduCopter.

It would be definitely helpful to me if you can explain this a little.

Hi @robin_drone,

We’re always looking for more devs to help! Maybe you’ve already found it but here is our ROS2 developer docs.

1 Like

Hi @robin_drone ! As @rmackay9 sir suggested, look at the docs and also at readme at AP_DDS library on github. Also have a look at and skim through some of these PRs. They’ll give you a sense of how various function in main AP code are modified/called and used by AP_DDS library.

https://github.com/ArduPilot/ardupilot/pulls?q=is%3Apr+AP_DDS+is%3Aclosed
.AP_DDS: Copter takeoff service by snktshrma · Pull Request #26911 · ArduPilot/ardupilot · GitHub

1 Like