In that log the firmware is 4.1.4 - you should definitely upgrade to latest stable.
There are very important fixes included for the Cube Orange, and much more.
What motors, props and ESCs do you have? Is it the T-Motor integrated motor/mount/ESC combination?
I think thereās basic tuning problems to be solved before you can properly investigate rangefinder and altitude issues.
Thereās sections where Pitch/DesirePitch and Roll/DesiredRoll have parted ways and Iām a bit surprised you are not reporting a loss of attitude control and possible crash.
I would start by setting these, even though they are not directly related to attitude or altitude
ARMING_CHECK,1
ATC_THR_MIX_MAN,0.5
BATT_FS_CRT_ACT,1
FENCE_ENABLE,1 ā check other Fence parameters
PILOT_THR_BHV,7 ā I believe you have a spring-centred throttle
Your motors are sometimes hitting their minimum spin value, set
MOT_SPIN_MIN,0.15
This can cause what appears to be instability, when attitude control cant do what it needs to.
Yaw is the only axis that is working OK, but I suspect having Yaw PIDs twice the value of pitch/roll PIDs is taking too much away from the other axes
I would set:
ATC_ANG_YAW_P,5
ATC_RAT_YAW_I 0.08
ATC_RAT_YAW_P 0.8
This may make yaw a little less locked in than before, but you can deal with that later.
Set these to aid tuning
INS_HNTCH_ENABLE,1 ā set this then refresh params to see the rest
INS_HNTCH_MODE,1
INS_HNTCH_REF,0.16
INS_HNTCH_FREQ,45
INS_HNTCH_BW,23
INS_HNTCH_FM_RAT,0.7
INS_LOG_BAT_MASK,1
INS_LOG_BAT_OPT,4
You pitch and roll PIDs are a bit odd, I would do a test in Stabilise and AltHold (no payload) with these
If there is reasonable stability, then do some pitch and roll maneuvers and try Loiter mode.
ATC_ACCEL_P_MAX,40000
ATC_ACCEL_R_MAX,40000
ATC_ACCEL_Y_MAX,14000
ATC_ANG_RLL_P,5
ATC_ANG_PIT_P,5
ATC_RAT_RLL_P,0.12
ATC_RAT_RLL_I,0.12
ATC_RAT_RLL_D,0.003
ATC_RAT_PIT_P,0.12
ATC_RAT_PIT_I,0.12
ATC_RAT_PIT_D,0.003
If there is slight instability, reduce the ATC_RAT values by 10% and retest
Letās see that log file.