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: Added direct actuator control #29179

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

snktshrma
Copy link
Contributor

@snktshrma snktshrma commented Jan 29, 2025

This adds a new topic /ap/cmd_mot to allow external controllers control actuators directly. This adds support for external controller and planners (MPC, etc) to handle actuator control directly.

To run:

  1. Run Copter SITL
  2. On mavproxy, param set DISARM_DELAY 0
  3. Switch to Guided and arm.
  4. Publish:
ros2 topic pub /ap/experimental/cmd_mot ardupilot_msgs/msg/MotorControl "{timestamp: {sec: 0, nanosec: 0}, actuator: [0.7, 0.7, 0.7, 0.7, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]}"

This addition currently doesn't support case where publisher stops and switches the vehicle to a stable mode. In that case, the actuator output just resets to 0 (Min PWM) if no updates are received.

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.

Overall looking good. We'll need a review from a copter maintainer such as Randy or Pete Hall.

}

guided_motor_state.update_time_ms = millis();
memcpy(guided_motor_state.actuator, actuator, AP_MOTORS_MAX_NUM_MOTORS * sizeof(float));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
memcpy(guided_motor_state.actuator, actuator, AP_MOTORS_MAX_NUM_MOTORS * sizeof(float));
memcpy(guided_motor_state.actuator, actuator, ARRAY_SIZE(guided_motor_state.actuator));

If you changed to double in the actuators, then this would not require a change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @Ryanf55 ! So ARRAY_SIZE gives number of elements and because of that it will not copy anything after 8th element(32bytes). Either way you suggest using double(float64) instead of float32?

Comment on lines 911 to 912
uint32_t tnow = millis();
if (tnow - guided_motor_state.update_time_ms > get_timeout_ms()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
uint32_t tnow = millis();
if (tnow - guided_motor_state.update_time_ms > get_timeout_ms()) {
if (millis()- guided_motor_state.update_time_ms > get_timeout_ms()) {

No need for the local if you only use it once.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -0,0 +1,2 @@
builtin_interfaces/Time timestamp # ms
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 add documentation what this message is for. Something like

"Control the direct motor outputs of the vehicle"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!
Also I have modified the actuator array length to 32 in sync with AP_MOTORS_MAX_NUM_MOTORS.

.dw_id = uxrObjectId{.id=to_underlying(TopicIndex::MOTOR_CONTROL_SUB), .type=UXR_DATAWRITER_ID},
.dr_id = uxrObjectId{.id=to_underlying(TopicIndex::MOTOR_CONTROL_SUB), .type=UXR_DATAREADER_ID},
.topic_rw = Topic_rw::DataReader,
.topic_name = "rt/ap/cmd_mot",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we make this an experimental topic till we've flown it on a vehicle?

Copy link
Contributor Author

@snktshrma snktshrma Jan 30, 2025

Choose a reason for hiding this comment

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

Got it! Done

libraries/AP_DDS/AP_DDS_config.h Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ROS WikiNeeded needs wiki update
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants