Society of Robots - Robot Forum

Software => Software => Topic started by: machinegunmax on March 06, 2010, 01:42:49 AM

Title: new to programming PICs, need a little help
Post by: machinegunmax on March 06, 2010, 01:42:49 AM
Basically i have a line following robot.  The inputs are 2 signals coming between an LDR and a resistor acting as a voltage divider as outlined in http://www.societyofrobots.com/schematics_photoresistor.shtml (http://www.societyofrobots.com/schematics_photoresistor.shtml)
The output is a servo.  Here is some very rough pseudocode:

A = input1 - input2

servo pulse length = 1.5ms + k*A

here k is a constant.  1.5ms is the pulse length which lines up the servo so that the robot goes straight.  So if one side gets more light the signal will be larger, A will be +ve and therefore the servo will move one direction, if the other LDR gets more light, A will be -ve and the servo will move the opposite direction.  My question is: firstly would this sort of idea work ... and if it would, how would i find the value of K (or could you suggest any good starting values)
Title: Re: new to programming PICs, need a little help
Post by: little-c on March 07, 2010, 03:03:17 PM
idea works. its simple enough.



as for k, start with a value of 100, and multiply/divide by ten to find when it starts changing from too violent to too slow a reaction, then start splitting it in half.


so if 100 was too slow, and 1000 too fast, go for 500, and if thats too slow, go for 750, blah.

if the value is 750 and it behaves like that, I want a cookie! ;D