Miniature line follower, final strech

stan74

Senior Member
Cycling has similarities to walking ie continuous correction to stop you falling over but a bike will go some distance on it's own.
The 8 IR sensor array and 2 continuous rotation 9g servos just arrived so plenty to investigate. The sensors are 1cm apart and I'll go for a 2-3 mm black line on white. Maybe check is line in left 3-go left or right 3-go right. Or maybe use 6 sensors..will see. If the servos are suitable then differential steering else find a scrap little r/c car.
ps Edmunds. I bought an accelerometer module..it's still in the packet,haven't had time yet to try it out.
 

edmunds

Senior Member
Dear all,

Just in case somebody has more experience than me with this. How would you go about tuning the PID parameters? I feel like poking in the dark a little bit. Most of the literature, gives parameters around 1 or even between 1 and 0. However, if I make the parameters that small, the input from the steering system is dismal, since the input is actually a number of pulses to turn a stepper and 10 are needed per turn. 10 pulses or one full rotation moves the lever sideways about 0.3 mm. My error ranges from 0 to 8 and turning wheels from centre to one end requires about 160 pulses.

I could, of course, multiply the PID output with something before applying it and that would allow coefficients to go down, but how much is good?

The parameters that are giving the best experimental result so far are kind of strange - P = 2; I = 0.7; D = 18.

Feeling puzzled :confused:,

Edmunds
 
Last edited:

edmunds

Senior Member
I just realised why I cannot take or rather exit the turn! And the LED line indicator helped a great deal :). I noticed, that at the exit of the turn, the sensor 'released' the previous final position only very late to throw it over to the other final position. This means that no measurements where actually taken in between, which means that the car was stuck into trying to turn the wheels while they were long in their final position. When you think of it, it makes sense - it has been slightly off the line throughout the turn, so the error keeps mounting. This means only one thing and one only - the famous Integrator Windup. So, I need to cap the Integrator part at some value. Now it remains to figure out, or rather read from the car, what the crazy value is. This probably goes back to the thin serial wires and forward to tomorrow, because it is bedtime here :).

Edmunds
 

edmunds

Senior Member
I worked through the signed mathematics code. First attempt at running it was promising, but now I'm going backwards. I'm pretty sure my math par is correct, but I have a logical problem.

At first, I had a problem, where I apply coefficients that depending on resolution, need to be multiplied with a coefficient and divided back with a 100 or a 1000. That works fine with normal numbers, but if you have 3 and 65532 (-3), then obviously, not only you need to remember the sign, but also the order of the actions (multiply and then divide or divide and then multiply) would have to be taken into account not to overflow the variable. I think I have sorted that, too.

Now the remaining question, that I'm just posting here for the night, because it is 4 AM here, is that my line position is between 1 and 7 for negative values and 9 and 16 for positive. 8 and 9 are considered 0. I started out by adding (subtracting) line position to $8000 and was happy for a while. I even ran the car with this and it was not really tracking as good as with the old case statement code, but it was at least trying to. While looking for faults, I realised this is somewhat arbitrary idea, because 0 is where 0 is, not at $8000 and this should produce a very large output to one end and very small one to the other, which it kind of did.

Putting 0 where it should be throws me back at the first problem - applying same coefficients to 3 on one side and 65532 (-3) on the other side produce very different results.

Is there a more or less magic solution to the problem?


Thank you for your input,

Edmunds
 

AllyCat

Senior Member
Hi,

This thread is getting very confusing with two different interleaved topics using different hardware from two "OP"s. Also the original OP does currently have rather a lot of different threads on the same (or a very similar) topic. :confused:

but if you have 3 and 65532 (-3), then obviously, not only you need to remember the sign, but also the order of the actions (multiply and then divide or divide and then multiply) would have to be taken into account not to overflow the variable.
I think you may be misunderstanding how to use twos complement maths. The sign is within the number, which means that the maximum range of values that can be handled is -32768 to +32767 (i.e. 15 bits + the sign bit) . It's rather confusing to refer to a signed number as 65532, rather better as $FFFC, where the PICaxe Editor is not "happy" with -4 (note it's not -3) . Hint: Subtracting 1 from zero gives $FFFF (or -1) , etc.

You don't need to "remember" the sign you just need to ensure that all operations that you perform are "twos complement friendly". We've explained above (I think it was in this thread) that you just need to use a simple subroutine or macro for multiplication and division (the subroutine converts the $FFFC to +4 so an overflow is unlikely to occur if the other numbers are realistically scaled). But you do also need to be careful with comparisons, etc., for example IF w1 < 5 THEN ... will not follow the "true" path if w1 is negative.

Cheers, Alan.
 

stan74

Senior Member
Picaxe is the 1st Basic I've used since the 80's and no negative numbers was a surprise. I had to think about the sign. The sine function is strange. Converting other basic to picaxe isn't straight forward. eg if a<-b
This thread could be in the robots section of the forum but I digress :)
 

edmunds

Senior Member
This thread is getting very confusing with two different interleaved topics using different hardware from two "OP"s. Also the original OP does currently have rather a lot of different threads on the same (or a very similar) topic. :confused
Alan, I agree about this thread and I'm partly to blame as I should have tried to keep it on the topic. However, I have been trying to split up the topics as for the benefit of the forum. I feel it will be easier for someone (maybe even myself) to find things in the future, if they are called 'dealing with signed numbers' or 'reading a miniature photo diode array' rather than all mixed up in a never-ending 'edmunds' project' thread. In the light of that, I'm starting a new thread to deal with signed numbers.

I think you may be misunderstanding how to use twos complement maths.
Most likely I am, thus the cry for help. However it is not as bad as with the -3 vs -4 - that was just a typo :).


Thank you for your input,

Edmunds
 

lbenson

Senior Member
I agree with Allycat that the interleaved topics (or similar topic, line following, with different hardware) makes a fairly difficult (but very interesting) thread even harder to follow. If a moderator could take the trouble to extract the posts on the second piece of hardware to another thread, it would be a blessing.
 

hippy

Technical Support
Staff member
If a moderator could take the trouble to extract the posts on the second piece of hardware to another thread, it would be a blessing.
If someone can tell me which posts those are and suggest a title for the new thread I can do that.
 

lbenson

Senior Member
Perhaps leave in post 8 but also have it as the start of a new thread, "Line following with QTR-8RC Infra Red Reflectance Sensor Array"

Then along with post 8: 9,10,17, 49 (except the first line refers to edmonds' thread), 50, 51, 52, 53, 54,55,56,59.

The bicycling stuff is distracting too, but probably doesn't stand on its own.

But I don't wish to be arbiter (hippy probably didn't either), so any other suggestion would be fine with me.
 

AllyCat

Senior Member
Hi,

There will nearly always be some off-topic comments in most threads, but it gets difficult when there are two sets of "problem solving" on different hardware at the same time.

I agree with lbenson's title and the post numbers to be moved, but would add 58 (which like 49 changes tack after the first line). To keep the editing simple(r) I'd move 8-10 , 17 , 49-56 and 58-59 to the new thread.

Cheers, Alan.
 

erco

Senior Member
I must admit that I benefited heavily from the wild ride this thread took. While confusing at times, I was inspired by the creative maelstrom of suggestions and variety of technical diversions. I have a whole new toy concept based on this wild ride. Thanks to all who participated in the melee.
 
Top