(SOLVED) with reference to Micrortps_client does not receive uorb message and Unable to establish FastRTPS connection with pixhawk. #38 .
Plug Pixhawk 4 into companion computer via USB, make and upload the firmware from the PX4-Autopilot directory:
make px4_fmu-v5_rtps
make px4_fmu-v5_rtps upload
Enter the nsh> from ~/PX4-Autopilot/Tools$:
python3 mavlink_shell.py
Start the micrortps_client over UART instead of UDP (which works for SITL):
nsh> micrortps_client start -t UART
In a new terminal, source ROS2 and start the micrortps_agent over UART:
micrortps_agent start -t UART
In a new terminal, source ROS2 and echo the desired topic (or run the desired listener):
ros2 topic echo /fmu/vehicle_odometry/out
And the vehicle_odometry topic is printed for the Pixhawk 4 as desired. Hope this helps someone else stuck in the future!
Make sure it’s an UART connection instead of a UDP as it is a USB connection. If you’re using a pixhawk 5x, and connecting to the Companion Computer using the ETH port then use UDP.
You could later add a bash script to start PX4 at startup and automatically connect.