Line follower and CCS compiler

Thread Starter

mik3

Joined Feb 4, 2008
4,843
Hello guys,

I am making a line following vehicle with inductive guidance.

Does anyone have an idea of a good algorithm to control the steering motor?


Also, if I assign a variable (x) as long (x) in C can this variable take decimal values (eg. 5.6) or only whole numbers?

I am using CCS compiler.
 

thatoneguy

Joined Feb 19, 2009
6,359
You can declare it as a float, but it slows things down if frequently accessed, read a 10bit ADC value, then convert reading it to an unsigned char or unsigned int as soon as practical (after comparisons). Not as large of concern if overall ground speed isn't high, below about 1ft/second. An int can only be an integer, no decimal.

I've used 5 sensors with great results, it allows auto-detection of light/dark line, keep center sensor "centered". Two more just away from line edge to sense gentle curves, and two more about 2 inches out from each line edge to detect hard corners, oblique crossings, and help to recover line on an overshoot.

"Remember" intersections at oblique angles by noting a line coming from outer sensor "inwards". Ignore a 90 degree crossing when all sensors "see a line" for a bit, unless the line cannot be recovered quickly continuing straight, then you ended up at a trick or a wall, in which case, you should have collision avoidance of some type, contact bumpers at the minimum. Lots of damage can happen quick.

I use PWM "tank" steering with a very freely turning rear wheel, like on an R/C airplane, but without the link to the rudder. Smoother turns can be made by slightly changing Duty Cycle on one side over trying to angle a steering wheel a fraction of a degree. The wheels will need to change speed anyway since one side has a shorter path than the other side in a turn.

Lots of IR LEDs illuminating area under sensors, phototransistors with black heat shrink shrouds to cut out all light except directly up from floor/reflected from LEDs.

Code it to "think", rather than follow a couple rules, as there are always some conditions missed, such as starting without a line, oblique lines coming from both directions, getting stuck in a circle, etc. Feedback for wheel speed is a great help so turns can be made without under/overshoot, self calibrating (until it is powered off...). Very useful for when two motors aren't running the same speed when trying to go in a straight line.
 

Thread Starter

mik3

Joined Feb 4, 2008
4,843
Thatoneguy,

Thanks a lot for your answer. I have though of all this stuff and I wrote a code. it didn't work very well and I asked here because someone might have a good idea. However, I think the code didn't work well because I didn't have time to check it properly.
 

thatoneguy

Joined Feb 19, 2009
6,359
How did it respond? Is there a thread or blog describing the quirks?

I've missed resetting a a variable to zero at one point, and the thing was insane, just randomly running around, hard to pin down stupid typos/forgotten thingies.
 

Thread Starter

mik3

Joined Feb 4, 2008
4,843
How did it respond? Is there a thread or blog describing the quirks?

I've missed resetting a a variable to zero at one point, and the thing was insane, just randomly running around, hard to pin down stupid typos/forgotten thingies.
Of course, a stupid mistake and the whole system can behave crazy. :p
 

thatoneguy

Joined Feb 19, 2009
6,359
I usually start from scratch each time, and re-use certain routines often.

First I get the platform to go straight forward/backward with collision detection.

Then I add bits on one step at a time.

I'm normally a neat freak programmer, but it turns into embarrassing spaghetti code after about hour number 4. This allows the errors to go up quickly.

I've tried re-writing one as a simple example, but it didn't work out quite right. Interrupts and delays and sampling are so interwoven at the time I wrote it (without comments, of course) that I had to laugh.

Here is a site with code in BASIC for a "get started" platform, I'm adding this for the benefit of people searching for the topic title, the code is simple and straightforward, and could be re-written in C without too much trouble:
http://www.robodyssey.com/resources/PICProject/index.htm
 
Top