# Strategies for tuning with low sample rate

I’m designing an arduino robot that’s objective is to find and drive towards a light using a photo resistor mounted on a servo. I want to write my program with PID control to sweep the photo-resistor while moving.

Currently my logic flow is:

• powerMotors(0)
• Continuously sweep servo 180
• Continuously collect photoresistor
• If photoresitor>photoresistorMax
• photoresistorMax = photoresistor
• Angle to light = servo position
• Error = 90 - angle to light
• powerMotors(Error*Kp)

So at the moment it is adjusted with P control. It wobbles and does not always make it precisely. I believe a major problem with it is that the sampling time essentially is limited by the time to sweep 180°.

Is there any adjustments you could recommend to improve sampling time and overall increase accuracy of my system?

Thanks

To improve sampling time, you can usually avoid the full $$180^o$$ sweep, resorting to it only when the bot has no idea of where the light is. Otherwise the world has continuity you can use: the light is probably near where it was the last time you located it, and it's probably about as bright as it was then. So you can probably make a pretty good guess where to look.

For instance, if the bot just turned a little to the right, and the sensed light dropped off, the servo could look a little to the left and see if the light gets brighter again. It can stop the scan when it looks bright enough -- no need to hunt past the max every time just to make sure.

With all the "probably" and "assume" and "guess" of this approach, it will pay to be a little conservative about how to tell when it's confused. One sign is when you expect the light to be at one side but when you turn in that direction the detected level doesn't rise again. Even then, it could be smart about whether to turn toward full-left or full-right to begin the scan, and maybe even stop early if it sees the light bright enough again.

If it's necessary to cast it in terms of PID, I'd have to think about this harder.

I don't have full a solution for your problem, but I expect that this will improve performance...

I'll suggest that you decrease speed as the Absolute value of the Error increases.

something like...

speed = maxSpeed - abs(Error)

you would also need to ensure that speed never goes to zero, something like this...

speed = max(speed,minSpeed)