should be both together at the end of callback and for self.distance_to_velocity_interpolator the assignment should be done from a local variable, so it should be first calculated to a local variable.
The problem here is that path_callback runs very rarely, but it might take longer than one cycle of current_pose_callback and then the self.path_linestring and self.distance_to_velocity_interpolator might not be in sync any more.
It would be even better to use threading.lock (not strictly necessary here, but you can try)
And threading lock should be used also at the beginning of the callback that needs to use the global variables, but then the global variables need to be assigned to local variables.
import threading
# inside class init
self.lock = threading.Lock()
# in the callback
with self.lock:
self.path_linestring = path_linestring
self.distance_to_velocity_interpolator = distance_to_velocity_interpolator
There is a possibility that after checking that the global variable is not None it will be changed to None just before assignment to a local variable.
You should check (if it is not None) and later use in the callback the same variable.
So I would assign global variables to local ones, then check if the local ones are not None, and if they are not None, you can use them in the callback.
Please fix the following:
Just a matter of taste, but I would move this group below the
#Parameters
and add an explanatory title, like global variables or similar. Parameters are the first because the values come from outside and they determine the node behaviour. Global variables are internal to that node. https://github.com/jaak-peterson/autoware_mini_practice/blob/0377df857d517db02bcb1db841aabd2f651e890c/practice_3/nodes/control/pure_pursuit_follower.py#L15-L16You have exactly the same for loop over msg.waypoints two times. Reorganize the code that the loop is done only once. https://github.com/jaak-peterson/autoware_mini_practice/blob/0377df857d517db02bcb1db841aabd2f651e890c/practice_3/nodes/control/pure_pursuit_follower.py#L31-L32
As discussed in the lecture, these two assignments:
self.distance_to_velocity_interpolator
the assignment should be done from a local variable, so it should be first calculated to a local variable.path_callback
runs very rarely, but it might take longer than one cycle ofcurrent_pose_callback
and then theself.path_linestring
andself.distance_to_velocity_interpolator
might not be in sync any more.