Skip to content

Python ROS2 interface with PX4 through a Fast-RTPS bridge

License

Notifications You must be signed in to change notification settings

kirinrobotics/pyx4

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pyx4

Python ROS2 interface with PX4 through a Fast-RTPS bridge.

Requirements

You need to install the required packages for PX4, ROS, and XRCE-DDS before running the Pyx4 examples, as instructed in this guide.

Getting Started

Setting up Pyx4:

cd dev_ws/src
git clone https://github.com/kirinslab/pyx4.git
cd dev_ws
colcon build --packages-select pyx4
source install/setup.bash

Sample

Run the example to read information about GPS Position:

ros2 run pyx4 pyx4_gps

Output:

RECEIVED VEHICLE GPS POSITION DATA
==================================
[Lat] :  473977440
[lon] :  85455944
[Alt]:  487624
[Heading] :  nan
RECEIVED VEHICLE GPS POSITION DATA
==================================
[Lat] :  473977472
[lon] :  85455960
[Alt]:  487939
[Heading] :  nan

QoS for PX4 Python

PX4 QoS settings for publishers are incompatible with the default QoS settings for ROS 2 subscribers. So if ROS 2 code needs to subscribe to a uORB topic, it will need to use compatible QoS settings.

PX4 uses the following QoS settings for Sensor Data subscribers:

rmw_qos_profile_t qos_profile = rmw_qos_profile_sensor_data;
auto qos = rclcpp::QoS(rclcpp::QoSInitialization(qos_profile.history, 5), qos_profile);

PX4 defines qos_profile as rmw_qos_profile_sensor_data. You can look up this profile in QoS Profiles as follows:

static const rmw_qos_profile_t rmw_qos_profile_sensor_data =
{
  RMW_QOS_POLICY_HISTORY_KEEP_LAST,
  5,
  RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT,
  RMW_QOS_POLICY_DURABILITY_VOLATILE,
  RMW_QOS_DEADLINE_DEFAULT,
  RMW_QOS_LIFESPAN_DEFAULT,
  RMW_QOS_POLICY_LIVELINESS_SYSTEM_DEFAULT,
  RMW_QOS_LIVELINESS_LEASE_DURATION_DEFAULT,
  false
}

Looking up the values of rmw_qos_profile_sensor_data corresponding to the classes defined in the QoS rclpy library. We get the following results:

qos = QoSProfile(
            history=HistoryPolicy.RMW_QOS_POLICY_HISTORY_KEEP_LAST,
            depth=5,
            reliability=ReliabilityPolicy.RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT,
            durability=DurabilityPolicy.RMW_QOS_POLICY_DURABILITY_VOLATILE
        )

With QoS defined in Python, we can use it to read the packets that PX4 publishes using ROS2 and Python.

Author

haiquantran2897@gmail.com

Reference

License

Copyright (c) Kirinslab. All rights reserved. Licensed under the GPT-3 license.

About

Python ROS2 interface with PX4 through a Fast-RTPS bridge

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages