PX4 direct command on motors

Goodevening,
I am trying to set my control system of the drone Iris but I am not able to send trust values to the drone due to some errors. Following a list of command which I use to start the simulation

Navigate to the folder

cd  ~/Desktop/PX4-Autopilot

Start simulation with px4

make px4_sitl gazebo_iris

Starting mavros

ros2 run mavros mavros_node --ros-args -p fcu_url:=udp://:14540@

Here I get an error about transformation which have been solved with

ros2 run tf2_ros static_transform_publisher 0 0 0 0 0 0 map base_link_frd

Setting the mode

ros2 service call /mavros/set_mode mavros_msgs/srv/SetMode "{custom_mode: 'OFFBOARD'}"

Arming the drone

ros2 service call /mavros/cmd/arming mavros_msgs/srv/CommandBool "{value: true}"

Give a setpoint

ros2 topic pub /mavros/setpoint_position/local geometry_msgs/msg/PoseStamped "
header:
  frame_id: 'map'
pose:
  position:
    x: 0.0
    y: 0.0
    z: 0.5
  orientation:
    w: 1.0
" --rate 10

Sometimes I first publish the setpoint and later arm the drone, I do not remeber which configuration work but the drone hover at desired position, so the simulation work.
Now I pass to MANUAL mode because I want manually command the motors

ros2 service call /mavros/set_mode mavros_msgs/srv/SetMode "{custom_mode: 'MANUAL'}"

Arming the drone again because it turn off

ros2 service call /mavros/cmd/arming mavros_msgs/srv/CommandBool "{value: true}"

But I get error doing that, even if I do

ros2 topic pub /mavros/actuator_control mavros_msgs/msg/ActuatorControl "
group_mix: 0
controls: [0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8]
"

Before arming the drone. Following the error

ros2 service call /mavros/cmd/arming mavros_msgs/srv/CommandBool "{value: true}"
requester: making request: mavros_msgs.srv.CommandBool_Request(value=True)

response:
mavros_msgs.srv.CommandBool_Response(success=False, result=1)

I have done several check but I can’t figure it out

N.B: I changed some parameters with px4 shell but nothing works. I am on Ubuntu 20.04, ROS2 Foxy, Gazebo classic

1 Like

It seems to me that there is no problem, but I think you should check the pre-flight checklist status in QGC first to see if it is normal.

The pre-flight checklist fails and I do not understand why, do you know how to solve?

Actually I modified the code to disable the checklist and I am able to arm the drone in OFFBOARD mode, but still my drone doesn’t move with

ros2 topic pub  /mavros/setpoint_attitude mavros_msgs/msg/AttitudeTarget "
orientation:
  x: 0.0
  y: 0.0
  z: 0.0
  w: 1.0
body_rate:
  x: 0.0
  y: 0.0
thrust: 0.8"

or

ros2 topic pub /mavros/actuator_control mavros_msgs/msg/ActuatorControl "
group_mix: 0
controls: [0.7, -0.2, 0.1, 0.05, 0.0, 0.0, 0.0, 0.0]"

I see only motor that are turned on in Gazebo but they are not receiving effective trust. I have done also ros2 topic echo and messages and published in both cases

Do you get any errors in the PX4 console output?

Do you make sure to always/continuously send setpoints? Offboard requires commands to be sent continuously.

1 Like

Yes, I tried by sending the setpoint in a continous way and also stopping it but nothing work

I actually px4 doesn’t give me outputs, I can tell you that I had problem

  • with pre-flight checklist: solved by modifying directly the code returning always true
  • arming the drone: “commander arm” was not going to hard the drone due to some error, so I force it with “commander arm -f”

With this modification, I can control the drone by sending cartesian setpoint ( everything work perfectly ), but still it ignore torque command. Do you know what are the precise steps to let let the drone be commanded by my torques?

I believe support for direct motor commands via MAVLink has been removed with newer PX4 versions, unfortunately.

1 Like