PX4 / PX4-Autopilot

PX4 Autopilot Software
https://px4.io
BSD 3-Clause "New" or "Revised" License
8.48k stars 13.5k forks source link

[Bug] Servo motor angle error #23171

Closed MayurRabadiya closed 5 months ago

MayurRabadiya commented 5 months ago

Describe the bug

Hello, I have created a custom SITL for tilting a quadcopter. I am using gazebo harmonic and PX4 (main branch).

I wanted to control the servo motor from ROS2 in offboard mode. I am sending servo angle (-1 to 1 equals -90 to 90) on topic /fmu/in/actuator_motors. But with a 1 (90 degree) servo motor that is not rotating as expected, it rotates 60–70 degrees, approx.

`param set-default CA_SV_CS_COUNT 4

param set-default SIM_GZ_SV_FUNC1 201 param set-default SIM_GZ_SV_FUNC2 202 param set-default SIM_GZ_SV_FUNC3 203 param set-default SIM_GZ_SV_FUNC4 204

param set-default SIM_GZ_SV_MIN1 0 param set-default SIM_GZ_SV_MIN2 0 param set-default SIM_GZ_SV_MIN3 0 param set-default SIM_GZ_SV_MIN4 0

param set-default SIM_GZ_SV_MAX1 1000 param set-default SIM_GZ_SV_MAX2 1000 param set-default SIM_GZ_SV_MAX3 1000 param set-default SIM_GZ_SV_MAX4 1000

param set-default CA_SV_TL0_MAXA 90 param set-default CA_SV_TL0_MINA -90 param set-default CA_SV_TL1_MAXA 90 param set-default CA_SV_TL1_MINA -90 param set-default CA_SV_TL2_MAXA 90 param set-default CA_SV_TL2_MINA -90 param set-default CA_SV_TL3_MAXA 90 param set-default CA_SV_TL3_MINA -90 ` This is my AirFrame configuration.

To Reproduce

Is it possible to use mave_interface_plugin with gazebo harmonic?

Expected behavior

The servo motor should rotate 90 degrees with an input of 90 degrees or 1.

Screenshot / Media

No response

Flight Log

https://github.com/PX4/PX4-Autopilot/assets/43095609/9376f040-f7c3-43cf-9bf1-b92ae919ee0c

Software Version

PX4 (Main)

Flight controller

Simulation

Vehicle type

None

How are the different components wired up (including port information)

No response

Additional context

No response

MayurRabadiya commented 5 months ago

I have found the solution for the above problem. I am not sure if this is bug or correct, but below solution worked for me.

https://github.com/PX4/PX4-Autopilot/blob/157f7cf40b943527d19db9eb0f8a4bd6f36d8f66/src/modules/simulation/gz_bridge/GZMixingInterfaceServo.cpp#L68

here, at this line I have just multiplied the Pi/2 value and it worked for me.

L68 --> double output = ((outputs[i] - 500) / 500.0) * 1.5707963268;