Re: Algorithm for counting number of lines travelled over
- From: "Padu" <padu@xxxxxxxxxxxx>
- Date: Thu, 22 Dec 2005 10:07:41 -0800
<tastytoad@xxxxxxxxxxx> wrote in message
> I'm having a problem that I hope someone can see the logic I have
> possibly overlooked.
>
> The robot is to pass through, say, 5 white lines on a black surface
> and then come to a rest. I am trying to work out the general logic to
> the algorithm rather than the proper syntax of the programming
> language.
>
> I have written the program like so:
>
> initialize variable lines_to_count = 5
> initialize variable on_white_line = false
>
> turn motors on and stay on until otherwise turned off
>
> while (lines_to_count > 0)
>
> if (sensor detected white surface) then
> on_white_line = true
>
> if (on_white_line = true) and (sensor detected black surface) then
> lines_to_count = lines_to_count -1
> on_white_line = false
>
> loop while
>
> turn motors off
>
>
> All that does, however, if make the motors turn on momentarily and then
> immediately stop. It's as if the while loop is never entered or is
> executed so quickly followed by the turn motor off that it seems not to
> have run at all.
>
> Can anyone see a problem with the logic? I'm stumped....can't explain
> why the robot just stops immediately upon being activated.
>
> I would think the above program would make the robot move forward, stay
> in the WHILE loop as it keeps moving forward keepiing track of the
> number of lines it passeed by and, when the fifth line is passed, the
> robot stops.
>
> Notice the two IF statements in the WHILE loop are mutually exclusive
> because one is looking for a white surface, the other a black surface.
> Line counting is determined by finding a white surface (the first IF)
> followed some time later by detecting a transition to a black surface
> (the second IF). The second IF toggles on_white_line variable back to
> false so that it can be resued for the next white line the robot
> encounters. You can assume the sensors are working perfectly.
>
> Thanks.
>
You have a classic and simple FSM here, and the logic seems ok. So the
problem may likely be in the sintax of your program or getting the signal
out of the sensor. Remember that real world sensors are noisy, and if you
have not calibrated it correctly or taking the proper cautions to interpret
it, you may have problems.
>From the symptoms you describe, seems like the program is actually working,
but the sensors are giving spikes that are crossing your "sensor detected
white surface" threshold.
Have fun debugging ;-)
Cheers
Padu
.
- Follow-Ups:
- Re: FSM Algorithm for counting number of lines travelled over
- From: Randy M. Dumse
- Re: FSM Algorithm for counting number of lines travelled over
- References:
- Algorithm for counting number of lines travelled over
- From: tastytoad
- Algorithm for counting number of lines travelled over
- Prev by Date: Re: Machina Speculatrix and Emergent Behaviour
- Next by Date: Re: Machina Speculatrix and Emergent Behaviour
- Previous by thread: Re: Algorithm for counting number of lines travelled over
- Next by thread: Re: FSM Algorithm for counting number of lines travelled over
- Index(es):
Relevant Pages
|