Modification to guided mode

I was looking to modify the guided mode to use rangefinder data to set a minimum altitude with respect to the global frame. From the guided mode code, I could understand that range finder data is mostly used for terrain mapping, whereas in loiter mode or alt_hold mode there is the explicit use of rangefinder data to control the altitude. Any hints or solutions on how to go about this modification are most welcome.

There is already a minimum altitude fence feature in ArduCopter 4.1.

Please take a look at it to see if it suits your needs.
And if not, please explain in detail what you are trying to achieve and why.

Hey, thanks for your response! Yes, I did go through that, but I am not sure if it uses the rangefinder data and I am not setting fences or boundaries beforehand.
My exact need is to use the rangefinder data and constantly get altitude information and if the vehicle dips below a certain limit, calculate the difference and bring it back up.

I have an old PR that does just that: https://github.com/ArduPilot/ardupilot/pull/16261
Take a look at that as a starting point.