Creating a Script to allow UR5 to read accelerometer and set gravity level in real time

Hello Everyone,
I have a question regarding creating a script for a UR5 robot. Basically I am intending to be changing the gravity and orientation level that the UR5 will undergo, so to avoid the safety functions kicking in I am going to use an accelerometer to measure the gravity level of two axis, and then feed them into the robot using the two analogue inputs. Then I will read the two analogue inputs and then use them to use the set_gravity function in the robot so it will update it’s gravity level in real time. However I am running into problems in writing the script. I intend to use the script function that is in the robot itself, adding in a script structure and write it on the robot itself rather than outside from a laptop and using the TCP connection. However, I am having problems in writing the script.
I intially thought something like this could work:
thread update_gravity():
while (True):
Jx=(get_standard_analog_in(0)-Xoffset)*Xscale
Jy=(get_tool_analog_in(0)-Yoffset)*Yscale
Jz=(get_standard_analog_in(1)-Zoffset)*Zscale
#or something similar with modbus_get_signal_status(“Jx”,false) et.c.
set_gravity(Jx,Jy,Jz)
sync(); # sleep until next 125Hz tick
end

However I am running into problems, as the script writing in the robot seems very basic, with only True, False, and, or, xor and not functions available and trying to write while using the keyboard I am unable to submit it as a line.
Does anyone have experience in writing a script within the GUI of the robot itself or will I have to use an outside source?
Any help would be greatly appreciated,
Thank you!

I’m not sure what the question is… Your problem is that you cannot submit a program to the robot? Perhaps this is just a simple line ending issue (robot expects \r\n).

You can also directly input this program directly in the teach pendant or save it tinto a file, upload it to the robot and import it as a multi-line script.