I am in the process of designing an obstacle avoidance mobile robot controlled by fuzzy logic , the idea of this work is that the robot should moves straight in an desired angle given by the user and if it faces an obstacle in his way , it should avoid that obstacle and then re-correct its heading angle to the desired angle .
My mobile robot is Rover 5 with two DC motors and Encoders and three ultrasonic sensors , one of sensors is in front side and two others on two sides of robot with 45 degree .
But I face a problem and I will explain it in the figures below because I couldn't to snapshot my real robot .
In figure below the initial heading angle of robot is zero with X-axis and desired angle (for example) is 45 degree .
so the fuzzy control will increase right motor and decease left to point or steer robot with angle 45 , and when the heading angle of robot is equaled to desired angle "45" , the robot moves straight and until now everything is OK .
but the problem started when the robot faces an obstacle in his way .
so to avoid that obstacle , fuzzy control will increase right motor and decrease left to make robot change its heading to avoid it , as shown in figure below
In the state above , instead that the robot move a little forward , It suddenly change its heading angle by increasing left motor and decrease right and that happens because one of fuzzy rule is triggered which is telling robot to re-correct its heading to desired angle when no sensor sense an obstacles . So the robot will return to old state as in picture below
now robot again tries to avoid obstacle and change its direction and then re-correct its heading to desired angle
and it stacked in these two states , switching between them and don't move , so any help / idea about how to solve this problem
From what you have described (very nicely) I suggest that the robot should be obliged to move a certain distance when it gets a clear path before it reconsiders its direction. If the obstacle is large that may still mean the the robot makes a few false moves before it gets past the object. But each time it sees the obstacle it will turn aside and move a distance. Eventually when it returns to its route there will be no obstacle in front of it.
Surely when it rotates towards the left, it should then move forwards until the sensors on the right tell it that the path is now clear to return to the original heading.
From what you have described (very nicely) I suggest that the robot should be obliged to move a certain distance when it gets a clear path before it reconsiders its direction. If the obstacle is large that may still mean the the robot makes a few false moves before it gets past the object. But each time it sees the obstacle it will turn aside and move a distance. Eventually when it returns to its route there will be no obstacle in front of it.
...R
Surely when it rotates towards the left, it should then move forwards until the sensors on the right tell it that the path is now clear to return to the original heading.
Thanks a lot Robin2 & KenF
so could please give more about how to do that , is that by adding a specific rule base ? and what is the scheme of these rule ?
Actually my fuzzy controller is with four inputs (Front sensor reading , Right sensor reading , Left sensor reading , Desired angle ) and two outputs (Right Wheel Speed , Left Wheel Speed ) and simply the rules base scheme as follow :
If Front Sensor triggered Turn Left
If Left Sensor triggered Turn Right
If Right Sensor triggered Turn Left
If No Sensor triggered Re-correct Heading Angle to Desired angle and move Forward .
I meant if "right sensor" or "both right and front sensors" sense an obstacle so to avoid it, the robot should turn left by increasing right wheel speed and decease left one .
Robin2:
I think both @KenF and I envisage logic like this
if road ahead is clear
move forward x distance
check position and direction
repeat
The distance to move will depend on the exact project - it might be 1 cm, 10cm or 100cm. It is unlikely to be as small as 1mm.
I think that logic is equally valid whether the robot is moving on its desired course or navigating round an obstacle.
...R
thanks , so you advice me to use this type of rule scheme , OK , but I do not completely understand this type ,
I think for this line "if road ahead is clear" , with my fuzzy parameters (if I am right ) will be just like
If Front is Far & Right is Far & Left is Far then Wr is Fast & Wl is Fast
but what about
move forward x distance
check position and direction
Why the robot should move for a specific distance ? Why don't to make him move continuously till it face an obstacle ?
What do you mean by "check position and direction" ?
RoboTemad: If Front is Far & Right is Far & Left is Far then Wr is Fast & Wl is Fast
I don't understand this - especially the bits about FAST
but what about
move forward x distance
check position and direction
Why the robot should move for a specific distance ? Why don't to make him move continuously till it face an obstacle ?
What do you mean by "check position and direction" ?
The reason for not "moving continuously until it detects an obstacle" is because you have already said that doesn't work.
You haven't posted your code and it may be very long and I am very lazy and probably would not read it all. However I would be very surprised if there is not something in it that is equivalent to "where am I now, and where should I go next". Suppose, for example that it turned left and moved until it was clear of the obstacle - what would it do then? It should check its position and figure out what direction it needs to go to reach its destination.
I got the impression from your first post (with the diagrams) that you have code that can detect an obstacle and turn aside to avoid it. And that the problem was that it more or less immdiately realized it was pointing in the wrong direction and turned back to the desired direction just to find the obstacle was still there - not surprisingly.
I think the code should check if the way ahead is clear, if it is move forward (say) 1 cm, check again if the way ahead is clear etc.
Because the checking only takes a few microseconds it should appear as if the robot is moving steadily in the desired direction.
Everything you've been told so far is correct, but there's another way to think of the problem. Imagine that you're blind and out walking. Your white stick detects an obstacle in front of you. You turn left and keep walking, all the time checking with the stick on your right to see if you've reached the end of the obstacle. If you've reached the end of the obstacle, you can turn right and continue in your original direction. That's what your Robot should be doing.
Henry_Best:
Everything you've been told so far is correct, but there's another way to think of the problem. Imagine that you're blind and out walking. Your white stick detects an obstacle in front of you. You turn left and keep walking, all the time checking with the stick on your right to see if you've reached the end of the obstacle. If you've reached the end of the obstacle, you can turn right and continue in your original direction. That's what your Robot should be doing.
Very good analogy.
And if your robot cannot detect obstacles right beside it all it has to do is stop briefly and turn towards the obstacle to check if it is there, and if it is still there it will turn back and continue on its diversion.
Now , I realized that I should force a slight move forwards after the turn before returning to the heading . but the problem how could I make this force or modifier , should it be located inside rule base ? I tried to add or modify a rule in my rules base to perform this force but I failed to find right place to this force .
these are my rules and membership functions by Matlab , actually I converted MATLAB Fuzzy Inference System to Arduino C Converter by http://www.makeproto.com/
RoboTemad:
should it be located inside rule base ?
Maybe this is a question for a Matlab forum?
I haven't the faintest idea. I don't even know what a rule base is.
...R
It looks like 24 if, then, else statements to me. I'd use an array to hold the motor speeds, or squash the conditions, bitwise into a byte for each pair of speeds and use a switch-case.
surprise ! I think you do n't have any idea about fuzzy logic .
Fuzzy rules are linguistic IF-THEN- constructions that have the general form "IF A THEN B" where A and B are (collections of) propositions containing linguistic variables. A is called the premise and B is the consequence of the rule. In effect, the use of linguistic variables and fuzzy IF-THEN- rules exploits the tolerance for imprecision and uncertainty. In this respect, fuzzy logic mimics the crucial ability of the human mind to summarize data and focus on decision-relevant information.
I can't relate those IF statements to Fuzzy Logic.
I can't imagine anyone trying to write Arduino code in that way - so I assume it is not intended for an Arduino.
this the a familiar way to use Rules Base in fuzzy logic , and the rules in old post written in Matlab (i.e. .FIS) not for an Arduino but , lately I converted it to C++ code (check attachment ) to run for an Arduino kit .
Actually , I am thinking in an idea which is to add a specific condition out Fuzzy controller which check if any of sensors senses an obstacle and next check if none of sensors sense any obstacle , if that condition is verified that's mean the robot faced an obstacle and then turns aside and to prevent him from returning to the original heading it should move a distance.
the problem how can I verify from a such condition "check if any of sensors senses an obstacle and next none of sensors sense any obstacle " ?
RoboTemad:
the problem how can I verify from a such condition "check if any of sensors senses an obstacle and next none of sensors sense any obstacle " ?
My own personal view is that your problem does not lie in the area of interpreting sensors but, rather, in the area of what to when the sensor values have been looked at. In short "move forwards".
Perhaps the whole project would be easier, and the logic more obvious if you just write a simple Arduino program from scratch without Fuzzy logic.
What does fuzzy logic bring to this project? There is nothing fuzzy about an obstacle in the way. I can see the value of fuzzy logic for trying to predict shoppers' preferences on a wet Thursday - or even for weather forecasting, maybe even for horse-race forecasting.
Actually , that's what I am trying to do now , to give up fuzzy logic and try a simple logic . but I still need help how can I verify from a such condition "check if any of sensors senses an obstacle and next none of sensors sense any obstacle " ? I need for a simple example code .
What about something like this (obviously not tested)
void loop() {
readSensors();
checkForObstacle();
avoidObstacle();
moveForward();
checkDirection();
}
void readSensors() {
// read the various sensors and save the values
}
void checkForObstacle() {
// go through the saved sensor values and decide if
// whether it is safeToMove the preset distance
}
void avoidObstacle() {
// if safeToMove is false
// turn
}
void moveForward() {
// if safeToMove is true
// move forward the preset distance
}
void checkDirection() {
// if we are not pointing in the right direction turn
}