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.
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
- Create a Python ROS 2 package and add the offboard node from lesson M6-T11 (check the message field names in your px4_msgs).
- Run PX4 SITL, the agent, and the node. The vehicle should switch to offboard mode, arm and climb to 5 m.
- 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). - Measure the setpoint publication rate with
ros2 topic hz.
Part 2: velocity setpoints
- In
OffboardControlModesetvelocity = Trueandposition = False. InTrajectorySetpointset the position fields to NaN and fillvelocityin NED m/s. - 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.0Part 3: failure experiments
- Pause the publisher for 2 s (for example
time.sleepin the timer callback) and record what the vehicle does. - Send a position setpoint with a positive (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
| Symptom | Likely cause | What to check |
|---|---|---|
| Offboard rejected | Stream not started or mode flags do not match | Stream for about a second before the mode command; match flags to the setpoint type |
| Vehicle ignores setpoints | Wrong topic names or px4_msgs mismatch | Check ros2 topic echo on /fmu/in topics from your node |
| Jerky motion | Setpoint rate low or unsmoothed steps | Raise 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.