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

Introduce actuator output function parameters #18265

Merged
merged 54 commits into from
Oct 18, 2021
Merged

Conversation

bkueng
Copy link
Member

@bkueng bkueng commented Sep 20, 2021

  • Unifies the control allocation builds & adds a param SYS_CTRL_ALLOC
  • Introduces output functions as described in https://docs.google.com/document/d/10WsNyjARZEuDeCNywnwBnUy3FhX4CR2fmSL0b4eZl6U/edit?pli=1#heading=h.8g8ygrtolpw8
    • Only if SYS_CTRL_ALLOC is set, the output params are used, otherwise existing behavior is used
    • Remove direct mixer for control allocation
    • Add servos to uavcan as an example
    • The structure to handle output functions is generic, making it easy to add new functions and subscribing to any topic (e.g. 4b59357)
  • fmu pwm outputs:
    • parse timer_config.cpp and generate per-timer config params
    • add capture pins to pwm pins for boards that have them (with matching param label):
      • fmu-v5: 3 additional pins, 11 total now
      • durandal-v1: 5 additional pins, 10 total now
      • pix32v5: 3 additional pins, 11 total now
      • fmu-v5x, fmu-v6u, fmu-v6x: 1 additional pin, 9 total now
  • output param naming: PWM_FMU_* is used for FMU, SITL and HIL_ACT_* for HITL outputs. I'm not completely set on these though.

qgc_output_params_func

qgc_output_params_timer_config

qgc_output_params_func_dropdown

This can go in before or after the IO mixing change (#16444).

See individual commits for details.

@hamishwillee @JacobCrabill

@dagar
Copy link
Member

dagar commented Sep 20, 2021

  • output param naming: PWM_FMU_* is used for FMU, SITL and HIL_ACT_* for HITL outputs. I'm not completely set on these though.

This is borderline bike-shedding, but should we try to settle this one now? (previous discussion https://docs.google.com/document/d/10WsNyjARZEuDeCNywnwBnUy3FhX4CR2fmSL0b4eZl6U/edit?pli=1&disco=AAAANoXLsW0)

There are kind of 2 parts of this that I question (mildly).

  1. Perpetuating legacy naming everywhere that we could instead be close to deprecating. I'm in favor of these outputs being named as close as possible to what's user facing. I believe the majority of boards have been and continue to be MAIN/AUX on the case with only a few exceptions. Even on px4_fmu-v5 the pixhawk 4 says has ports labelled FMU and I/O, but on the pixhawk 4 mini it's MAIN, and on the CUAV board v5 it's MAIN/AUX.

  2. The idea that we're going to get users to do the right thing because default airframes will now go to FMU (AUX) first. I think this is going to seem pretty odd for all but the most technical users that understand the full picture and history. The availability of DSHOT on only some outputs and trivial airframe output/mixing configuration in the GUI will take care of this for the majority of the cases where it might even matter.

I actually don't think we should even be carrying opinionated default airframes that we pretend will work everywhere. There are a handful of cases where exact configurations should be carried. For the rest it should be a generic start. A "generic quadcopter" should default to using 4 MAIN outputs, but otherwise carry no actuator specifics. Then on the GUI side it should be easy for a user to switch those over to DSHOT, UAVCAN, etc on arbitrary outputs and set any specifics.

@dagar
Copy link
Member

dagar commented Sep 20, 2021

Is "Actuator Set X" for Mavlink MAV_CMD_DO_SET_SERVO?

Screenshot from 2021-09-20 10-29-11

Even with the potential for conflicts what if we just let people use servo directly? We could do something like reject the command if Servo X is in use by control allocation, etc.

Screenshot from 2021-09-20 10-30-55

@bkueng
Copy link
Member Author

bkueng commented Sep 21, 2021

This is borderline bike-shedding, but should we try to settle this one now?

We might as well.

I'm in favor of these outputs being named as close as possible to what's user facing.

Agreed. I don't think it will matter much though in this case, as the config UI will not even show the param name, just the label.

I think this is going to seem pretty odd for all but the most technical users that understand the full picture and history

Odd yes, but is it really a problem? They can ask and there's a good reason. It is a historical problem that we have to carry.
Most people will probably not know about any downsides and just stick to the default.

Overall I tend towards PWM_FMU_, but really only slightly.

I actually don't think we should even be carrying opinionated default airframes that we pretend will work everywhere. There are a handful of cases where exact configurations should be carried. For the rest it should be a generic start. A "generic quadcopter" should default to using 4 MAIN outputs, but otherwise carry no actuator specifics. Then on the GUI side it should be easy for a user to switch those over to DSHOT, UAVCAN, etc on arbitrary outputs and set any specifics.

I see that the same way.


Is "Actuator Set X" for Mavlink MAV_CMD_DO_SET_SERVO?

No, it's for DO_SET_ACTUATOR. I did not plan to add support for MAV_CMD_DO_SET_SERVO, but if needed I'd rather map it to the (future) actuator test interface.

@jlecoeur
Copy link
Contributor

jlecoeur commented Sep 21, 2021

Is "Actuator Set X" for Mavlink MAV_CMD_DO_SET_SERVO?

No, it's for DO_SET_ACTUATOR. I did not plan to add support for MAV_CMD_DO_SET_SERVO, but if needed I'd rather map it to the (future) actuator test interface.

What about "MAVLink X" or "MAVLink Actuator X" or "MAVLink Set X", or again "MAVLink Input X".
This would directly hint at the link with MAVLink (I first thought it was a group "set" of actuators).

@dagar
Copy link
Member

dagar commented Sep 21, 2021

Is "Actuator Set X" for Mavlink MAV_CMD_DO_SET_SERVO?

No, it's for DO_SET_ACTUATOR. I did not plan to add support for MAV_CMD_DO_SET_SERVO, but if needed I'd rather map it to the (future) actuator test interface.

What about "MAVLink X" or "MAVLink Actuator X" or "MAVLink Set X", or again "MAVLink Input X".
This would directly hint at the link with MAVLink (I first thought it was a group "set" of actuators).

If it makes sense I'm hoping we can skip including "Mavlink" in the naming, then continue using the vehicle_command in a ROS2 world.

type: enum
default: 400
values:
-5: DShot150
Copy link
Member

Choose a reason for hiding this comment

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

What about boards that don't have dshot (kinetis, imxrt, etc)?

Copy link
Member Author

Choose a reason for hiding this comment

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

They're automatically removed. Also for timers w/o DMA.

-5: DShot150
-4: DShot300
-3: DShot600
-2: DShot1200
Copy link
Member

Choose a reason for hiding this comment

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

So this means using PWM_FMU_* parameters to configure dshot min/max/disarm/etc as well?

Can't we have DSHOT_* parameters per physical output configured to dshot? Then we'd have appropriate defaults for min, disarmed, etc and the PWM parameters could have units in microseconds.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, dshot uses separate params. Just the function is the same.

@dagar
Copy link
Member

dagar commented Sep 21, 2021

I'm in favor of these outputs being named as close as possible to what's user facing.

Agreed. I don't think it will matter much though in this case, as the config UI will not even show the param name, just the label.

Maybe this is where we disagree. I don't think we need to have much of a disconnect between the param name and the label. We should map these parameters to particular physical outputs unambiguously on a per board basis.

For example on the original pixhawk (and pixhawk 2, etc) we have 8 MAIN and 6 AUX outputs clearly labelled. PWM_MAIN_* can always refer to those px4io outputs regardless of it being active or not (SYS_USE_IO).

In the fmu-v5 case it would be set early in boot based on hardware version, but then the location of PWM_MAIN and PWM_AUX is effectively static per board.

I think this is going to seem pretty odd for all but the most technical users that understand the full picture and history

Odd yes, but is it really a problem? They can ask and there's a good reason. It is a historical problem that we have to carry.
Most people will probably not know about any downsides and just stick to the default.

The transition is potentially problematic depending on how it's handled for the remaining in tree airframes.

Other than that's it's going to look like a PX4 oddity that will have to be explained again and again. From historical usage many people will have certain expectations for MAIN and AUX. I don't think it's worth fighting that existing experience, but we can still move away from it going forward with labeling on newer boards and an increasing number of boards dropping the px4io entirely.

I don't want to try and trick people into doing something slightly better in the face of 10 years of convention.

@jlecoeur
Copy link
Contributor

Is "Actuator Set X" for Mavlink MAV_CMD_DO_SET_SERVO?

No, it's for DO_SET_ACTUATOR. I did not plan to add support for MAV_CMD_DO_SET_SERVO, but if needed I'd rather map it to the (future) actuator test interface.

What about "MAVLink X" or "MAVLink Actuator X" or "MAVLink Set X", or again "MAVLink Input X".
This would directly hint at the link with MAVLink (I first thought it was a group "set" of actuators).

If it makes sense I'm hoping we can skip including "Mavlink" in the naming, then continue using the vehicle_command in a ROS2 world.

Right, then "Offboard X" might be a better fit

_actuator_controls_5_pub.publish(actuator_controls_5);
_actuator_motors_pub.publish(actuator_motors);

// TODO: servos
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure to see the point of using separate topics.

  • We will have unused actuator data in both topics, which IMO hinders the debugging and logging experience
  • I do not buy the pre-arm argument. Any output can be unsafe to activate pre-flight, we should not infer it from its type. We should rather get it from an output-level "PREARMABLE" parameter, effective for control_alloc function and other functions.
  • Control allocator will need parameters to decide which output goes to the motor topic and which goes to the servo topic

Copy link
Member

Choose a reason for hiding this comment

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

I do not buy the pre-arm argument. Any output can be unsafe to activate pre-flight, we should not infer it from its type. We should rather get it from an output-level "PREARMABLE" parameter, effective for control_alloc function and other functions.

Having this safety property at the lowest level makes sense to me if ultimately we can have the feedback/status tightly integrated. The higher level component telling the landing gear to retract, or the gimbal to deploy, or the engine to start should be able to know (easily) that the command isn't possible at this stage of operation.

Copy link
Member Author

Choose a reason for hiding this comment

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

IMO we generally need a bit more semantics, be it for ease of configurability & use or system inspection. While at the same time it does not reduce generality.

Control allocator will need parameters to decide which output goes to the motor topic and which goes to the servo topic

It knows this already.

@JacobCrabill
Copy link
Member

Unfortunately I'm not sure when I'll have the chance to dig through this in detail, but at a high level, what's different between this PR and #16808?

@bkueng
Copy link
Member Author

bkueng commented Sep 22, 2021

In the fmu-v5 case it would be set early in boot based on hardware version, but then the location of PWM_MAIN and PWM_AUX is effectively static per board.

This is the case that doesn't work. You'd have to select the metadata as well dynamically. That's possible, but not something I want to add.

Alright, let's go with PWM_MAIN/AUX then.


Unfortunately I'm not sure when I'll have the chance to dig through this in detail, but at a high level, what's different between this PR and #16808?

The main one is that outputs can directly subscribe to any topic, not just actuator_controls.


Right, then "Offboard X" might be a better fit

That's fine with me, but you can also use it in missions.

@bkueng bkueng force-pushed the ctrl_alloc_function_params branch 2 times, most recently from 9cc8422 to 987f46b Compare October 5, 2021 11:40
@bkueng
Copy link
Member Author

bkueng commented Oct 5, 2021

Updates:

  • changed params to PWM_MAIN_*
  • rebased & handling px4io
  • renamed Actuator_Set -> Offboard_Actuator_Set

@dagar dagar force-pushed the ctrl_alloc_function_params branch from f45611f to 142f4b3 Compare October 6, 2021 19:49
@dagar
Copy link
Member

dagar commented Oct 6, 2021

I've resolved the remaining build failures. I actually disagree with the offboard part of Offboard_Actuator_Set, but overall this is such an important improvement we can settle these little details later.

Is everyone else happy to move forward with this?

dagar
dagar previously approved these changes Oct 6, 2021
@dagar
Copy link
Member

dagar commented Oct 7, 2021

Over on px4_fmu-v6x_default.

/opt/gcc/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld: px4_fmu-v6x_default.elf section `.text' will not fit in region `flash'
1783
/opt/gcc/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld: region `flash' overflowed by 15649 bytes
1784
collect2: error: ld returned 1 exit status

@bkueng bkueng force-pushed the ctrl_alloc_function_params branch 2 times, most recently from 92a86c6 to 5b1858b Compare October 8, 2021 11:26
bkueng and others added 17 commits October 18, 2021 10:34
This happened with multi-instance, when the second instance did not load
a mixer. Then the first instance would always return false in
update_pwm_out_state, and continuously call up_pwm_servo_arm.
This led to irregular pulses, e.g. with an output set to fixed 1500us, I
saw pulses of e.g. 1800us occationally (they were in a range of
[1500-2100]).
The parameter additions are only used internally for the pwm generator.
…tivenessMatrix

clang tidy error:
/__w/PX4-Autopilot/PX4-Autopilot/src/modules/control_allocator/ActuatorEffectiveness/ActuatorEffectivenessMultirotor.cpp:50:34: error: default arguments on virtual or override methods are prohibited [google-default-arguments,-warnings-as-errors]
ActuatorEffectivenessMultirotor::getEffectivenessMatrix(matrix::Matrix<float, NUM_AXES, NUM_ACTUATORS> &matrix,
The implementation assumed timers are defined in the same order as used
in the channels. This could lead to a mismatch between TIMx param and
actual timer config.
Now we use the actual array index, same as in the code.
So that the ordering of the generated params make more sense.
TIM1 is now for channels 2-4 instead of 5-8.
The defaults changed in the previous commit for per-channel params,
so we make sure that the overall params are still used as long as the
per-channel params are default.
So that all failures can be evaluated.
…ance

This fixes the case where oneshot was enabled with multi-instance pwm_out,
triggering oneshot updates too close to each other and as a result could
lead to spinning motors while disarmed.
@bkueng bkueng force-pushed the ctrl_alloc_function_params branch from 5b1858b to 564e8a8 Compare October 18, 2021 08:34
@bkueng
Copy link
Member Author

bkueng commented Oct 18, 2021

Rebased, CI passing. Should be good to go from my side if there's nothing else.

@dookei
Copy link

dookei commented Feb 14, 2022

Hi, I am currently trying to use this PR. Unfortunately I am not able to find any reference to PWM_MAIN_FUNC exept on the mixer files. As this been tested? I would just like to control a few servos from an application.

@DronecodeBot
Copy link

This pull request has been mentioned on Discussion Forum for PX4, Pixhawk, QGroundControl, MAVSDK, MAVLink. There might be relevant details there:

https://discuss.px4.io/t/using-do-set-actuator-to-releasing-the-payload/28686/3

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

Successfully merging this pull request may close these issues.

7 participants