Ask Your Question
0

error pickling_unable to pickle : attribution look up failed

asked 2020-11-16 12:58:03 -0500

updated 2020-11-16 19:58:21 -0500

This a node for a new experiment that I'm doing and it collects the data from tf topic while running a turtlebot3_gazebo_world.launch and stores it's value as a txt/pkl file in form of serialized list of objects.

import rospy
import pickle
from teleop_record.msg import TB3Pose

msg = """

Record Your TurtleBot3 Path!
----------------------------
r - Record current point as step

m - set current point as next milestone path

s - stop and save file

CTRL-C to save & quit

"""

e = """

Communications Failed

"""


tb3_pose = TB3Pose()
path_object_list = []
steps = 0
milestones = 0
file_ext = ".txt"

class path(object):
       def __init__(self, step, pose, milestone):
            self.step = step
            tb3pose = TB3Pose()    
            tb3pose = pose    
            self.pose_x = tb3pose.x    
            self.pose_y = tb3pose.y    
            self.pose_w = tb3pose.theta    
            self.milestone = milestone   


def updatepose(data):    
          global tb3_pose    
          tb3_pose.x = data.x    
          tb3_pose.y = data.y    
          tb3_pose.theta = data.theta    
          #print("i'm here")    
          #rospy.loginfo(tb3_pose)    


def incr_mile():    
  global milestones    
  milestones = milestones + 1    

def record_pose():    
            global steps    
            global milestones    
            global path_object_list    
            steps = steps + 1    
            pose = TB3Pose()    
            pose = tb3_pose    
            x = path(steps,pose,milestones)    
            path_object_list.append(x)    
            print(path_object_list)


def save_path():    
          global path_object_list    
          file_name = input("Define name for the Path file : ")    
          file_path = "/home/paul_pavish/catkin_ws/src/teleop_record/nodes/"#
          file_path_name = file_path + file_name + file_ext    
          print("Creating File..." + file_path_name)    
          open_file = open(file_path_name, "wb")    
          print("Writing Path to file...")    
          pickle.dump(path_object_list, open_file)    
          open_file.close()    
          print("Path file saved as " + file_path_name)    


def print_list():    
  x = 0    
  global steps    
  #while x < steps:    
  #  print(path_object_list[x])    
  #  x = x + 1

  for obj in path_object_list:    
        print(obj)


def subs():    
  print(msg)    
  rospy.init_node('turtlebot3_recorder')    
  sub = rospy.Subscriber('TB3Poser', TB3Pose, updatepose)   

  while(1):
        key = input('')    
        if key == 'r':
          record_pose()    
          print("recording point")

        elif key == 'm':
          print("Recording milestone")
          incr_mile()
          record_pose()

        elif key == 's':
          print("Exiting record loop..Press ctrl+s to save and exit.")    
          save_path()    
          break

        else:    
          print("INVALID COMMAND")

  rospy.spin()


if __name__=="__main__":

   try:    
            subs()    
            #print_list()

   except rospy.ROSInterruptException:
            pass

The program runs well collecting values and storing them as a list(even printing the list of objects), but it enters the save_path() function and reaches pickle.dump() it shows this error :

Record Your TurtleBot3 Path!
----------------------------

r - Record current point as step
m - set current point as next milestone path
s - stop and save file


CTRL-C to save & quit

r
[<__main__.path object at 0x7ff1323c3e20>]
recording point
r
[<__main__.path object at 0x7ff1323c3e20>, <__main__.path object at 0x7ff1323f92e0>]
recording point
r
[<__main__.path object at 0x7ff1323c3e20>, <__main__.path object at 0x7ff1323f92e0>, <__main__.path object at 0x7ff1323f9070>]
recording point
m
Recording milestone
[<__main__.path object at 0x7ff1323c3e20>, <__main__.path object at 0x7ff1323f92e0>, <__main__.path object at 0x7ff1323f9070>, <__main__.path object at 0x7ff1323f9820>]
s
Exiting record loop..Press ctrl+s to save and exit.
Define name for the Path file : sd
Creating File.../home/paul_pavish/catkin_ws/src/teleop_record/nodes/sd.txt
Writing Path to file...
Traceback (most recent call last):
  File "/home/paul_pavish/catkin_ws/devel/lib/teleop_record/teleop_record_node.py", line 15, in <module>
    exec(compile(fh.read(), python_script, 'exec'), context)
  File "/home/paul_pavish/catkin_ws/src/teleop_record/nodes/teleop_record_node.py ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-01-05 08:03:30 -0500

I found a way around this.

Instead of Pickling a list of classes, I just stored them list of lists of values, without using classes to sort and structure the values. I just assigned values to the list like a matrix of matrixes, so it was easier to store values into the list and retrieve it using the matrix positions for any required set values in the matrix.

Hope this helps.

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

1 follower

Stats

Asked: 2020-11-16 12:58:03 -0500

Seen: 82 times

Last updated: Jan 05 '21