ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

getting unexpected message from subcriber callback

asked 2022-11-11 15:13:15 -0600

PGTKing gravatar image

updated 2022-11-12 07:43:52 -0600

gvdhoorn gravatar image

here is code

class Robotreacher:
    def __init__(self):
        rospy.init_node('robot_control_node', anonymous=True)
        self.waisttalker = rospy.Publisher('/rx150/waist_controller/command', Float64, queue_size=10)
        self.shouldertalker = rospy.Publisher('/rx150/shoulder_controller/command', Float64, queue_size=10)
        self.elbowtalker = rospy.Publisher('/rx150/elbow_controller/command', Float64, queue_size=10)
        rospy.Subscriber('/rx150/joint_states', JointState, self.joint_callback)
        #rospy.spin()

    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]
        #print("joint is", position)
        #time.sleep(0.1)

    def joint_states(self):
        return self.waistp, self.shoulderp, self.elbowp, self.waistv, self.shoulderv, self.elbowv



def give_force():
    x =  random.randrange(-4, 4, 1)
    y =  random.randrange(-4, 4, 1)
    z =  random.randrange(-4, 4, 1)
    waisttalker.publish(x)
    shouldertalker.publish(y)
    elbowtalker.publish(z)
    time.sleep(0.3)
    #print("joint states are", self.waistp, self.shoulderp, self.elbowp, self.waistv, self.shoulderv, self.elbowv)


def Robotreacher_looper():
    i = 0
    reward = 0
    for i in range(60):
        r = Robotreacher()
        print("r is", r.joint_states)
        give_force()


if __name__ == '__main__':
    try:
        Robotreacher_looper()
    except rospy.ROSInterruptException:
        pass

this is the result I get from the terminal

r is <bound method Robotreacher.joint_states of <__main__.Robotreacher object at 0x7f78acd1cf40>>
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-11-12 07:45:14 -0600

gvdhoorn gravatar image

updated 2022-11-12 07:45:56 -0600

This is a Python problem, not a ROS one.

In a nutshell: r.joint_states references the method object. It does not call it.

That object reference is of type bound method Robotreacher.joint_states of <__main__.Robotreacher object at 0x7f78acd1cf40>.

To call it, you'd use:

print("r is", r.joint_states())

note the () after the identifier joint_states.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2022-11-11 15:13:15 -0600

Seen: 60 times

Last updated: Nov 12 '22