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_Scripting: allow setting throttle factor from add_motor_raw #28071

Closed
wants to merge 1 commit into from

Conversation

magate
Copy link
Contributor

@magate magate commented Sep 10, 2024

add_motor_raw defaults throttle factor to 1:

void add_motor_raw(int8_t motor_num, float roll_fac, float pitch_fac, float yaw_fac, uint8_t testing_order, float throttle_factor = 1.0f);

There is a scripting set_throttle_factor. This does not seem to be working with frame class (https://ardupilot.org/plane/docs/parameters-Plane-stable-V4.5.6.html#q-frame-class-frame-class) 15 though.

@IamPete1
Copy link
Member

You can't add fields without breaking existing scripts.

It certainly should work, they key thing is that you have to set the factors after adding the motor but prior to calling the init. We have a partial example with the static matrix:

function update_static_mixer(ratio)
MotorsMatrix:add_motor_raw(0,-0.5, 0.5, 0.5, 2)
MotorsMatrix:add_motor_raw(1, 0.5,-0.5, 0.5, 4)
MotorsMatrix:add_motor_raw(2, 0.5, 0.5,-0.5, 1)
MotorsMatrix:add_motor_raw(3,-0.5,-0.5,-0.5, 3)
throttle_factors = build_factors(ratio)
MotorsMatrix:set_throttle_factor(0, throttle_factors[1])
MotorsMatrix:set_throttle_factor(1, throttle_factors[2])
MotorsMatrix:set_throttle_factor(2, throttle_factors[3])
MotorsMatrix:set_throttle_factor(3, throttle_factors[4])
if not MotorsMatrix:init(4) then
warn_user("Failed to initialize motor matrix!", MAV_SEVERITY.EMERGENCY)
else
if ratio ~= last_ratio then
warn_user("Set ratio to " .. tostring(ratio), MAV_SEVERITY.INFO)
last_ratio = ratio
end
end
motors:set_frame_string("Static CoM adjust")
end

What behavior are you seeing?

@magate
Copy link
Contributor Author

magate commented Sep 11, 2024

You can't add fields without breaking existing scripts.

It certainly should work, they key thing is that you have to set the factors after adding the motor but prior to calling the init. We have a partial example with the static matrix:

function update_static_mixer(ratio)
MotorsMatrix:add_motor_raw(0,-0.5, 0.5, 0.5, 2)
MotorsMatrix:add_motor_raw(1, 0.5,-0.5, 0.5, 4)
MotorsMatrix:add_motor_raw(2, 0.5, 0.5,-0.5, 1)
MotorsMatrix:add_motor_raw(3,-0.5,-0.5,-0.5, 3)
throttle_factors = build_factors(ratio)
MotorsMatrix:set_throttle_factor(0, throttle_factors[1])
MotorsMatrix:set_throttle_factor(1, throttle_factors[2])
MotorsMatrix:set_throttle_factor(2, throttle_factors[3])
MotorsMatrix:set_throttle_factor(3, throttle_factors[4])
if not MotorsMatrix:init(4) then
warn_user("Failed to initialize motor matrix!", MAV_SEVERITY.EMERGENCY)
else
if ratio ~= last_ratio then
warn_user("Set ratio to " .. tostring(ratio), MAV_SEVERITY.INFO)
last_ratio = ratio
end
end
motors:set_frame_string("Static CoM adjust")
end

What behavior are you seeing?

This looks like what I want. I'll play with it a bit more. Thanks.

@magate magate closed this Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants