Re: Algorithm for counting number of lines travelled over



<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


.



Relevant Pages

  • Re: New Ultrasonic Range Sensor
    ... designed to overcome the above mentioned problems and much more. ... It works to look down a hall or in my living room or in a robot contest. ... zero so I switched to just one sensor. ... have a blind spot in between the sensors as one gets closer. ...
    (sci.electronics.components)
  • Re: Any simple collision detection ideas?
    ... I am trying to build a foot touch sensor mechanism for my hexapod ... walking robot using force sense resistors. ... But i would like bump sensing as well... ...
    (comp.robotics.misc)
  • Re: New Sonar Range Sensor
    ... One of the reasons I completed this sensor was because my daughters ... robot was stuck on a wall during a contest. ... The next problem was that this dual sensor beam width was much too wide ... Again, thanks for your thumbs up on the design, but I really wanted to ...
    (comp.robotics.misc)
  • Reading barcodes using a laser scanner
    ... sensor to detect reflector targets that have barcodes on them. ... The barcode is to allow the robot to know which of the targets it has ... I see the scribbler robot has the ability to detect barcodes using its ...
    (comp.robotics.misc)