I was hoping to get an explanation on how the “callback” function as defined in the solution actually works. I understand that it is used to pull the message data from the /kobuki/laser/scan topic, but how can it write to the pub.publish object before it is “created” in the program since this is on the following line? I believe my confusion is with the callback function itself.
Is there any way to have the msg.ranges accessible outside of the callback function? I assume we could use a class to do this, but I wasn’t sure if there was a better way.
Also how is this data accessible outside of the function itself. Are things written to objects essentially “global” variables in that sense?
Thank you for the help!