python deep copy of ROS message
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!
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.
Added error messages.