subscriber class not returning value

asked 2022-11-16 21:44:38 -0500

PGTKing gravatar image

updated 2022-11-17 04:34:32 -0500

ravijoshi gravatar image

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.

edit retag flag offensive close merge delete

Comments

All the indentations are correct.

In your original post, they were definitely incorrect.

cannot get the joint states to print nor get their values.

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.

ravijoshi gravatar image ravijoshi  ( 2022-11-17 04:38:23 -0500 )edit

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

PGTKing gravatar image PGTKing  ( 2022-11-17 19:02:04 -0500 )edit