Localization: Exercise 3.5

I don’t exactly understand this solution. Why is there robot_pose=Pose() in the beginning? Why PoseWithCovarianceStamped in later steps? It would be helpful if you could let me understand the code in a better way.

1 Like

Hi @apurva.mramdham,

The Subscriber ’/amcl_pose’ returns a PoseWithCovarianceStamped message. The callback extracts the pose from that message (robot_pose = msg.pose.pose) and the service returns just that pose. Have a look at those two message types here:
PoseWithCovarianceStamped
Pose

I hope that explained it

Hello together,
I honestly don’t understand the meaning of robot_pose = Pose() and the import of Pose exactly either. It also works if you omit the line, doesn’t it?

Best regards
Sebastian

so the /amcl_pose topic is using the posewithcovariancestamped message type, hence you give it as the message type in the subscriber. so to put it simply you need this subscriber to print the robot pose when the client requests it to. it happens that the pose message is a sub set of posewithcovariancestamped(pwcs) i.e the posewithcovariancestamped is a collection of multiple message types bundled into one, hence a subset. when you do msg.pose.pose you are accessing the pose part of the pwcs message type. when you did robot_pose = pose() you created an object of pose() message. since msg.pose.pose and pose() are both same you are equating them in the callback and updating the robot_pose. since any variable defined inside a function cannot be accessed globally, you are using the concepts of object oriented programming are doing as shown in the code. hope I
made sense. cheers!.

@viswadeepkopalli2000
Thank you very much for the understandable and detailed explanation. Makes Sense ;). I have now been able to apply and understand it in another task!

Best regards
Sebastian

1 Like

Great explanation @viswadeepkopalli2000 ! Many thanks for helping out answering this question.

1 Like