Confusion about LIDAR Range finder combining with GPS guided

Hello, I am currently working on a crop sprayer code. I have the spraying velocity and pump control running on an onboard computer. (Ideally I would like to run it on the PX4)

Basically what I am trying todo is be able to program autonomous missions over sugar cane at a height of 2m~5m over the crops constantly. So for that I would need a lidar to maintain the distance.

Is there anyway to activate range finder while in auto mode/guided? also is there a variable where if it reaches the end of the crops and sees a more than 6m~3m difference than it currently is to hold its position instead of trying to level down to the ground.

In other words you take off at 0m, go ontop of crop. Start the mission so it fixes itself without falling over when the crops end or if there are holes in the field. So for example use X,Y from gps but Z height from range finder. Sorry if this is confusing, I tried my best at explaing the situation.


So I’m going to assume you’re using ROS for offboard? If so, there is actually a plugin for mavros in the mavros extras package that specifically sends distance sensor messages to the px4, this works regardless of flight mode