subscriber class not returning value
Here is code
class Robotreacher(object):
def __init__(self):
#rospy.init_node('robot_control_node', anonymous=True)
self._event = threading.Event()
self.waistp = None
self.shoulderp = None
self.elbowp = None
self.waistv = None
self.shoulderv = None
self.elbowv = None
def joint_callback(self, data):
self.waistp = math.degrees(data.position[5])+180
self.shoulderp = abs(math.degrees(data.position[4])-90)
self.elbowp = abs(math.degrees(data.position[0])-90)
self.waistv = data.velocity[5]
self.shoulderv = data.velocity[4]
self.elbowv = data.velocity[0]
self._event.set()
q = [self.waistp, self.shoulderp, self.elbowp, self.waistv, self.shoulderv, self.elbowv]
#print(q)
def get_states(self, timeout=None):
self._event.wait(timeout)
q = [self.waistp, self.shoulderp, self.elbowp, self.waistv, self.shoulderv, self.elbowv]
return q
if __name__ == '__main__':
rospy.init_node('robot_control_node', anonymous=True)
p = Robotreacher()
rospy.Subscriber('/rx150/joint_states', JointState, p)
n = p.get_states()
print(n)
All the indentations are correct. cannot get the joint states to print nor get their values.
In your original post, they were definitely incorrect.
Because the
rospy.Subscriber
is defined incorrectly (and outside the class for some strange reasons).Nevertheless, looking at your code, it seems better to spend some time learning Python and ROS as well. It seems you are simply trying to run someone else's code.
I'm just in state of frustration and anxiety. Been trying to finish this code for 2 years, learned a lot about ros and python from playing with other peoples code