We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › model an array of automatic nightlights
Page Index Toggle Pages: 1
model an array of automatic nightlights (Read 1598 times)
model an array of automatic nightlights
Oct 23rd, 2009, 8:59pm
 
Hi,

I am trying to model an 10 x 10 (or greater) array of automatic nightlights. These are the kind that turn on when it is dark and off when it is light. I want to be able to individually rotate the nightlights so that the light sensor can face any direction I chose but otherwise be fixed in position (at least for now).

I actually have made this using real nightlights and I get interesting behavior but there are problems with the tremendous manufacturing variability in sensor threshold, etc. I made a microcontroller version and that helped but there are some variables I want to play with such as delay and hysteresis that can profoundly affect behavior but individually programming 100 micros is tedious. So I want to model it and then implement the rules in micros.

I am new to processing and not a big programmer either. I figured out how to create a nightlight class and a way to make a light with an inverse square fall-off in illuminence but am a bit stuck on how to model the light sensor.

I don't think I really want to do this in a cellular automata fashion as the lights are separated by some distance and the light is not binary but a gradient. Also, a sensor should be able to see beyond its immediate neighbors if there is a concentration of lights switched on creating a larger illuminence radius...

Hints towards an approach would be most greatly appreciated.

Thanks,
Chabo
Re: model an array of automatic nightlights
Reply #1 - Oct 24th, 2009, 1:25am
 
Wow, you don't seem so bad, at least at electronics and micro programming! Smiley

Quote:
how to model the light sensor

I have no idea... Wink Perhaps it was a question for Electronics section, or not. But I guess we need to know the light sensor better to help.
Perhaps you can describe more precisely/technically what the model must represent, what data it must hold, what methods it must have.
Doing this step of technical specification can actually make half of the job, and maybe you could be able to finish it! Grin
Re: model an array of automatic nightlights
Reply #2 - Oct 25th, 2009, 7:36am
 
Since every nightlight can potentially contribute to the light level at any sensor then effectively have a n2 problem. What it means is that for each sensor you have to measure the light contribution from every other nightlight so 100 nightlights then 100 x 100 calculations per step, double the nightlights and you quadruple the calculations.

Of course there are techniques to reduce the amount of 'runtime' computation for instance if the nightlight positions are fixed then then for each sensor we can predetermine which nightlights should be considered using the inverse square law.

This can be reduced further (possibly) since the sensor has a 'detection zone' so will not be pointing directly at some nightlights.

Quote:
I don't think I really want to do this in a cellular automata fashion as the lights are separated by some distance and the light is not binary but a gradient. Also, a sensor should be able to see beyond its immediate neighbors if there is a concentration of lights switched on creating a larger illuminence radius...


For the actual sensor you might consider a finite state machine approach where each sensor has a number of states unlike the true/false approach of cellular automata you can use an integer value to represent a state e.g.
  • waiting to switch off
  • waiting to switch on
  • turn on
  • turn off

You can then use System.currentTimeMillis() to get the current time in milliseconds. If you do this for each sensor update  then you know how long has passed since the last update and adjust the state accordingly.

Hope this is useful.


Hope this helps
Re: model an array of automatic nightlights
Reply #3 - Oct 28th, 2009, 7:22pm
 
Hi Quark,

Thanks for giving this some thought.

Quote:
This can be reduced further (possibly) since the sensor has a 'detection zone' so will not be pointing directly at some nightlights.

This is indeed the case, the sensor has something like a 60 degree acceptance angle and can be rotated around to face any 2-D direction.

I had been thinking about doing this by each on light drawing a series of concentric ellipses with a fading alpha as the distance from center increases and then having each sensor sample the pixels in an area of the screen. Now I am wondering about the pointLight command and somehow creating a spot that sees all the light that strikes it. I guess this would mean modeling it in 3-D...

I'm not sure what you are getting at with the timing suggestion. Perhaps you think the lights only stay on for a certain amount of time? They stay on as long as they do not sense light from other lights in their field of vision.

Thanks,
Chabo
Re: model an array of automatic nightlights
Reply #4 - Oct 28th, 2009, 10:18pm
 
Hi,
interesting project.  I am wondering if you couldn't do something much simpler in Processing, though: just determine the amount of light hitting a sensor by a function of its distance ( dist() ) to  each relevant lightsource.  

Or, with your current gradient technique, I'm not sure why you can't just grab the pixel at point (x,y) and test its brightness?
--Ben
Re: model an array of automatic nightlights
Reply #5 - Oct 29th, 2009, 1:01pm
 
Quote:
I'm not sure what you are getting at with the timing suggestion.


I mentioned this because you said

Quote:
I want to play with such as delay and hysteresis that can profoundly affect behavior ...


Code:
I had been thinking about doing this by each on light drawing a series of concentric ellipses with a fading alpha as the distance from center increases and then having each sensor sample the pixels in an area of the screen 



This is unlikely to give a realistic effect because the number of ellipses need to get a realistic inverse square fall-off would be high also there are only 256 different alpha values so not very sensitive.
Might look at http://www.processing.org/reference/tint_.html

Anyway best of luck with this project as I think the result could be very interesting to see the different behaiours.
Smiley
Re: model an array of automatic nightlights
Reply #6 - Oct 30th, 2009, 12:00pm
 
Thanks Ben,

Quote:
I am wondering if you couldn't do something much simpler in Processing, though: just determine the amount of light hitting a sensor by a function of its distance ( dist() ) to  each relevant lightsource.  


Duh, this seems so simple! I just need to sample a few lightsources within the sensor view, average them and compare to a threshold value. Not exactly sure what data structure to use to represent the lights. Is there some kind of array manipulation that would allow me to test only those lightsources that are a certain direction from the sensor?
hmmm... I'll keep searching. Thanks for everyone's help.

Chabo
Re: model an array of automatic nightlights
Reply #7 - Oct 30th, 2009, 12:04pm
 
Quark,
Quote:
Quote:
I'm not sure what you are getting at with the timing suggestion.


I mentioned this because you said

Quote:
I want to play with such as delay and hysteresis that can profoundly affect behavior ...


Oh, thanks. Sorry to not understand.
Re: model an array of automatic nightlights
Reply #8 - Oct 30th, 2009, 12:21pm
 
Quote:
Is there some kind of array manipulation that would allow me to test only those light sources that are a certain direction from the sensor?


Not quite but if you have two nightlights (n0, n1) at positions (x0, y0) and (x1, y1) then the code
Code:
degrees(atan2(y1 - y0, x1 - x0)); 


returns a value between -180.0 and 180.0 representing the angle of n1 with respect to n0, you could then compare this with the angle of the sensor on n0 to see how close they are.
Smiley
Re: model an array of automatic nightlights
Reply #9 - Nov 18th, 2009, 12:17am
 
I have made some progress, mostly on GUI that allows nightlights to be selected and rotated. Now what I need is a way to turn "on" the lights. I had been drawing successively larger ellipses with a decreasing alpha stroke value. This allowed overlapping "illumination" but is very slow when I have 100 lights. I am wondering if some kind of alpha image can be loaded and displayed for each on light? Can I use the above mentioned ellipse routine to generate such an image?
Page Index Toggle Pages: 1