Ask Your Question
0

I can't really understand what I'm doing wrong

asked 2013-04-25 21:41:40 -0500

Rizqa gravatar image

updated 2014-01-28 17:16:21 -0500

ngrennan gravatar image

I can't really understand what I'm doing wrong.. I try to get a value-object from another method.. this is my code

 #!/usr/bin/env python


class tracksendi():
def __init__(self):
    rospy.on_shutdown(self.shutdown)

    rospy.Subscriber('robotis/servo_head_pan_joint',
                     Float64, self.posisi_ax12_pan)
    rospy.Subscriber('robotis/servo_head_tilt_joint',
                     Float64, self.posisi_ax12_tilt)
    rospy.Subscriber('robotis/servo_right_elbow_joint',
                     Float64, self.posisi_ax12_elbow)

    while not rospy.is_shutdown():
        self.operasikan_servo()
        rate.sleep()

def posisi_ax12_pan(self,pan):
    self.posisi_pan_servo = pan.data   
    return

def posisi_ax12_tilt(self,tilt):
    self.posisi_tilt_servo = tilt.data
    return     

def posisi_ax12_elbow(self,elbow):
    self.posisi_elbow_data = elbow.data
    return

def ambil_timestamp(self,waktu):
    self.data_time_joint_states = waktu.header.stamp
    return             

def operasikan_servo(self):
# Lengan Kanan
    try:

        vektor_n_rs = self.posisi_pan_servo - self.posisi_tilt_servo
        vektor_re_rs = self.posisi_tilt_servo - self.posisi_elbow_data

    except KeyError:
        pass


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

But, I get this error

vektor_n_rs = self.posisi_pan_servo - self.posisi_tilt_servo  

AttributeError: tracksendi instance has no attribute 'posisi_pan_servo'

How that problem solved ???

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-04-25 23:05:04 -0500

ChickenSoup gravatar image

Initialize all your variables in the __init__ function. e.g. self.posisi_pan_servo = 0 etc.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-04-25 21:41:40 -0500

Seen: 115 times

Last updated: Apr 25 '13