How to lift random weight at certain distance?

Yes, this is to accommodate for the varying payloads. I did some digging around the forum for any other ideas and you came up with this code (link to topic: Dynamic Payload setting in UR E series to pick the dynamic payload - #2 by sya )

Wait 0.2
zero_ftsensor()
Pick_Part
Wait 0.2
Var_1 = force()
Var_2 = Var_1/10 //Newton to kg
set_payload_mass(Var_2)

So I put that in my code to look something like this:

Before Start
Weight_Shift:= False
Wait 2.0
...
Robot Program
Weight_Shift:= False
MoveL
 First_Pose
 Above_Bin_1
 Trap_Handle
 Gripper Close
 Wait: 0.3
 Weight_Shift:= True
 Wait: 0.3
 Weigh_Bin
 Wait: 3.0
 Lift_Up
 Wait: 1.0
 Weight_Shift:= False
 ...

Thread_1
If Weight_Shift =? True
 zero_ftsensor()
 var_1:= force()
 var_2:= var_1/10
 set_payload_mass(var_2)
 sync()

 

I ran this in the simulator and it seems to work fine but there are no real life external forces acting on it so I’m a bit skeptical if I uploaded this to my Cobot. The idea is that the thread is monitoring the code and when Weight_Shift goes to True, it will change the payload constantly until the variable is set to False again. Is this a bad approach? I don’t have much experience coding such large robots..