I want to publish two odometry messages that share most of the fields. To avoid copying all the elements one by one I try:
odom_new = Odometry(odom_old)
But this give me an error.
File "/opt/ros/electric/ros/core/roslib/src/roslib/message.py", line 362, in init raise TypeError("Invalid number of arguments, args should be %s"%str(self.slots)+" args are"+str(args)) TypeError: Invalid number of arguments, args should be ['header', 'child_frame_id', 'pose', 'twist']
Then I try:
odom_new = Odometry(odom_old.header, odom_old.child_frame_id, odom_old.pose, odom_old.twist)
This doesn't give me any errors but just creates a pointer from the new object to the old one. Then, when the new one is modified the old one too (I need an independent object)
After this I try:
import copy
odom_new = copy.deepcopy(odom_old)
But again this solution fails.
odom_new = copy.deepcopy(odom_old) AttributeError: 'function' object has no attribute 'deepcopy'
Any Idea about how to create a deep copy of a ROS message in Python? Sorry, my Python knowledge is very limited :P!
Originally posted by narcispr on ROS Answers with karma: 307 on 2012-07-02
Post score: 2
Original comments
Comment by Lorenz on 2012-07-02:
What's the failure you are getting? Please always post backtraces and error messages when posting questions to save your and other people's time.
Comment by narcispr on 2012-07-02:
Added error messages.