How to set the value from a Rostopic as a global variable?
I am planning to control the position of the robotic arm according to the contact force.
I can achieve the force signal from Rostopic. The frequency of the data is quite high.
Now I want to write a python code to control the z position of the end-effector according to the force. However, I can subscribe to the topic, I can print the force value in terminal, but I do not know how to use the force value in the main functions, such as if function.
My target is to set a "if" function, if the force is over 10 N, z position -0.1.
Anybody could help? Thank you very much.
Asked by waltergun on 2022-08-03 10:24:03 UTC
Comments
In python you have a main function (only one), callback functions (as many as the number of subscribers), and normal functions (as many as you need). In order to use the same variable in two different function first you have to define it in the main function (give default value) then use "global variable_name" in the function you want to use that variable. Generally I use callback function to set the value (nothing else), and and one logic function to evaluate the values of that variable.
Asked by Ammar Albakri on 2022-08-06 06:34:21 UTC