1

I have a system where I use RS232 to control a lamp that takes an input given in float representing voltage (in the range 2.5 - 7.5). The control then gives a output in the range 0 to 6000 which is the brightness a sensor picks up.

What I want is to be able to balance the system so that I can specify a brightness value, and the system should balance in on a voltage value that achieves this.

Is there some standard algorithm or technique to find what the voltage input should be in order to get a specific output? I was thinking of an an algorithm which iteratively tries values and from each try it determines some new value which should be better in order to achieve the determined output value. (in my case that is 3000).

The voltage values required tend to vary between different systems and also over the lifespan of the lamp, so this should preferably be done completely automatic.

I am just looking for a name for a technique or algorithm, but pseudo code works just as well. :)

Jonas
  • 121,568
  • 97
  • 310
  • 388
Mozy
  • 31
  • 3

3 Answers3

1

Calibrate the system on initial run by trying all voltages between 2.5 and 7.5 in e.g. 0.1V increments, and record the sensor output.

Given e.g. 3000 as a desired brightness level, pick the voltage that gives the closest brightness then adjust up/down in small increments based on the sensor output until the desired brightness is achieved. From time to time (based on your calibrated values becoming less accurate) recalibrate.

Will A
  • 24,780
  • 5
  • 50
  • 61
  • This is the way we used to do it. Our problem is that it takes a bit too much time to check the range in such small increments. The solution I posted will adjust the voltage increment size depending on how close it is to the desired brightness value. – Mozy Jun 23 '11 at 06:33
  • Ah - hadn't figured on this being slow, but I guess there's a 'warm up' or 'cool down' period whilst waiting for the lamp brightness to stabilize that I hadn't considered would play a role. Nice solution above, Mozy - good ol' Wikipedia! – Will A Jun 24 '11 at 04:50
1

After some more wikipedia browsing I found this:

Control loop feedback mechanism:

previous_error = setpoint - actual_position
integral = 0
start:
  error = setpoint - actual_position
  integral = integral + (error*dt)
  derivative = (error - previous_error)/dt
  output = (Kp*error) + (Ki*integral) + (Kd*derivative)
  previous_error = error
  wait(dt)
goto start

[edit]

By removing the "integral" component and tweaking the weights (Ki and Kd), the loop works perfectly.

Mozy
  • 31
  • 3
1

I am not at all into physics, but if you can assume that the relationship between voltage and brightness is somewhat close to linear, you can use a standard binary search.

Other than that, this reminds me of the inverted pendulum, which is one of the standard examples for the use of fuzzy logic.

Björn Pollex
  • 75,346
  • 28
  • 201
  • 283