How to adjust the sample rate of distance sensor (rangefinder)

I follow the Pixhawk instruction (by this link:Distance Sensors (Rangefinders) · PX4 v1.9.0 User Guide)
and run the rangefinder successfully.

The sensor type is Lidar-Lite

I am curious about how to increase the sampling rate.
Now my sample rate is only 2 hz

Also, I am confused why the QGroundControl Analyze Tools detect the distance sensor only 0.2~0.8 Hz, no matter in real world or simulation ( the simulation and real Lidar should be 10 hz)




Thanks a lot

P.S
I enable rangefinder in MAVROS by this way: How to Read Distance Sensor Data from MAVROS Topic
I set the I2C connection in QGroundControl by this way: Cannnot find the distance_sensor in the QGround control

In Ardupilot firmware, people suggest,

rosrun mavros mavsys message_interval --id XX --rate YY

by this way: How to adjust the sample rate of distance sensor (rangefinder) - ArduCopter - ArduPilot Discourse

I also examine mavlink_main.cpp by this way: Increase stream rate of HIGHRES_IMU message

Someone change the sampling rate of IMU by edit this file /fs/microsd/etc/extras.txt
ref:System Startup | PX4 User Guide

Increase the sampling rate in Gazebo simulation increase sensor rate SITL · Issue #980 · mavlink/mavros · GitHub

How to change the correct publisher name: How to use distance_sensor? send distance Sensor data to FCU for use as altitude · Issue #664 · mavlink/mavros · GitHub

@AlexWUrobot …I am also trying to put my distance sensor VL53L0x into operation for collision prevention. QGC shows the distance measured but the drone in POSITION mode does not handle collision detection !! Any clues ?

In your case, you have to make sure that the drone is flying in POSITION MODE for the distance sensor to work .

Where did you install MAVROS. is it on a Raspberry Pi ?

Thanks for the reply
I install MAVROS on Jetson TX1. (with Ubuntu 18.04 and Python 2.7)
I fly the drone through offboard mode (means that Jetson TX1 computer controls the Pixhawk FMUv5 version to fly the drone)
I ran the Python script so I can subscribe the /mavros/distance_sensor/hrlv_ez4_pub
ref: MAVROS Offboard control example (Python) | PX4 User Guide

great info !! Actually i am a bit confused . Is it better to go the MavROS way or the MAVSDK way to control the Quadcopter in offboard mode …

I have not tried MAVSDK, but I think this link will be helpful:Difference MAVLink and MAVROS

She said:

MAVROS is the bridge between MAVLink and ROS. If you’re using ROS for whatever robotics you’re doing, then MAVROS is great.
If all you want is to write a simple C++ program to talk to a PX4 drone, then you should consider using the Dronecode SDK

thank you for the info…

The solution may be to edit the SD card in the Pixhawk
But I only find how to change the IMU instead of the distance sensor now.

cd /fs/microsd/etc
echo "mavlink stream -d /dev/ttyACM0 -s HIGHRES_IMU -r 100" > extras.txt

What about accessing Lidarlite from the Mavlink console menu in QGC . There is an option to adjust the bus frequency

Thanks for the info. I also found this but the unit is kHz, so I guess it may be for communication rate, instead of sampling rate. Distance Sensor · PX4 Developer Guide

I will still try that. Thanks for the reminder again.

I found some people have the similar issue
ref: lidar lite slow read rate · Issue #367 · intel-aero/meta-intel-aero · GitHub

My publish rate of (/mavros/distance_sensor/lidarlite_pub) is 10 hz in the simulation, but only 2 Hz in the real world, when readling from Pixhawk 4 (fmuV5).

If we assume the lidar-lite works well (default sampling rate 10Hz)
I would like to guess the issue may be due to the setting on Pixhawk?

Thus, I screenshot the other parameters of distance sensor (rangefinder) in the QGroundControl

I also guess the issue may be due to this revision on LidarLiteI2C.h
ref: increased rate of Lidar Lite driver over I2C · PX4/PX4-Autopilot@7ca16cd · GitHub


Maybe, I should change it to 10 ms and then

cd PX4-Autopilot
make px4_fmu-v5_default

ref: Building PX4 Software | PX4 User Guide

Great info…My concern is how do you built the px4 after changing the value …Do you have a complete procedure for doing this through Nuttx shell