I am currently working on a robot. I use an EV3 lego brick. My goal is to travel from point A to B using a method travelTo(x,y) using the shortest path. This method is in a thread name Drive, which contains all the methods used to control the movements of my robot (turnTo(double angle), travel(double distance), travelTo(double x, double y), changeSpeed(int newSpeed)...). I have another thread called ObstacleAvoidance which is supposed to stop the thread Drive if there is an obstacle in front and start avoiding the obstacle using P Controller technique to follow the obstacle.
My problem is that my P Controller uses methods inside the Thread Drive. Therefore, when I see an obstacle I cannot do:
if (obstacle){
Drive.wait();
while(isAvoiding){
pControler();
}
}
Drive.Notify();
private void pController(){
//use methods inside the DriveThread
}
How can I go around this problem? In other words, how can I stop the current action of my robot, avoid the block and then continue what I was doing?