Skip to the content
FixTheRobot Explore Robotics / UAV / Module 6 / M6-L5

UAV Systems Engineering · M6-L5 · Hands-on lab (runs on your machine)

Send position and velocity commands

Take control of the simulated vehicle from your own code and measure what the setpoint stream does.

  • UAV Software and Flight-Controller Integration
  • Implementation-specific
  • About 90 minutes

What you will do

You will write and run the offboard node from lesson M6-T11, extend it to velocity control, and verify the stream rate and the failsafe when the stream stops.

Before you start

  • Lab “Connect ROS 2 with PX4” completed (topics visible, px4_msgs built).
  • Lesson M6-T11 (offboard control) and lesson M1-T4 (frames).

Part 1: position setpoints

  1. Create a Python ROS 2 package and add the offboard node from lesson M6-T11 (check the message field names in your px4_msgs).
  2. Run PX4 SITL, the agent, and the node. The vehicle should switch to offboard mode, arm and climb to 5 m.
  3. Change the setpoint to a square of 5 m sides, advancing to the next corner when within 0.5 m (read /fmu/out/vehicle_local_position).
  4. Measure the setpoint publication rate with ros2 topic hz.

Part 2: velocity setpoints

  1. In OffboardControlMode set velocity = True and position = False. In TrajectorySetpoint set the position fields to NaN and fill velocity in NED m/s.
  2. Command 1 m/s north for 5 s and then stop. Check that the vehicle’s measured velocity follows and plot setpoint against measurement from the ULog.
import math
# In the setpoint publisher, for velocity control (NED, m/s). NaN means "not controlled":
sp.position = [math.nan, math.nan, math.nan]
sp.velocity = [1.0, 0.0, 0.0]        # 1 m/s north
sp.yaw = 0.0
Fields for velocity control. Confirm the control-mode flags in OffboardControlMode match.

Part 3: failure experiments

  • Pause the publisher for 2 s (for example time.sleep in the timer callback) and record what the vehicle does.
  • Send a position setpoint with a positive zz (underground) and observe, then correct.
  • Run the planner computation on the same thread as the publisher with an artificial 300 ms delay and measure the stream gaps.

How to know it worked

  • The vehicle enters offboard mode and flies the square with an acceptance radius.
  • The velocity setpoint is tracked (plot from the log).
  • You observed the dropout failsafe and can state how the setpoint stream timing caused it.

If it does not work

Troubleshooting
SymptomLikely causeWhat to check
Offboard rejectedStream not started or mode flags do not matchStream for about a second before the mode command; match flags to the setpoint type
Vehicle ignores setpointsWrong topic names or px4_msgs mismatchCheck ros2 topic echo on /fmu/in topics from your node
Jerky motionSetpoint rate low or unsmoothed stepsRaise the rate; rate-limit setpoint changes

References

Record your progress

Saved in this browser. This lab runs on your own machine, so the site cannot check it for you.