Script for Dynamically Updating Gravity using Accelerometer

Hello everyone,
I am currently working on a project which will include taking a UR5 Robot on a parabolic flight. My main concern with taking the robot on these is the periods of 2G gravity during insertion, and the low gravity phase, wherein I am worried the protective stop will kick in for the robot as the gravity is changing a lot.
My idea was to use an accelerometer on board the robot to dynamically update the gravity of the robot to keep it from protective stopping.
I have attached it to the analogue in 1 and 2 ports to get two axis of gravity (The third isnt needed as there will not be much movement).
However I am fairly new to writing script with UR Script, and am wondering how to set it up that the set_gravity function reads from the analogue inputs and converts them to gravity values to continuously update during operation.
Is it as simple as setting values to the analogue inputs (with conversion from the voltage to gravity) and then setting up a thread to continuously update the set_gravity function with these values?
Any help is greatly appreciated