Hello! Great to hear it's mostly working for you 🙂
Those parts of pixel.ino haven't been changed for a long time (you can do a 'git blame' https://github.com/euphy/polargraph_server_a1/blame/master/pixel.ino to check the history) so everyone else has been using that exact code for at least a year and a half, so I believe it works.
Reading back through that code, it's a bit strange (could do with some comments!). The variable called density is given the value of the 4th parameter to the command that it is processing. A command looks something like:
C05,<distance from left motor>,<distance from right motor>,<pixel size>,<pixel brightness>,END
eg:
C05,3222,2864,181,95,END
To draw a pixel, at coordinates 3222, 2864, that is 181 steps wide and has a brightness of 95 (out of 255).
So initially density is brightness, but in pixel_scaleDensity(...), density is re-set to actually be darkness rather than brightness, using this formula:
// Map the brightness to the range available for the pixel
reducedDens = (brightness / 255) * maxWavesForThisPixelSize
// Then invert it
reducedDens = maxWavesForThisPixelSize-reducedDens;
So if brightness is 200 (pretty light), and we're using a big pixel with a small pen that can fit in a maximum of 40 waves,
brightness = 200;
maxWavesForThisPixelSize =40;
mappedBrightness = (brightness / 255) * maxWavesForThisPixelSize;
// mappedBrightness equal 31, which is still a BRIGHTNESS value.
// Drawing this many waves with black ink would result in a dark pixel
// rather than a light one.
// Now invert it so it becomes a darkness value
mappedDarkness = maxWavesForThisPixelSize - mappedBrightness;
// so mapped darkness is 40 - 31 = 9.
// Drawing 9 waves with black ink would result in a lighter pixel.
If you are consistently getting density set to 1 or 0, then it means either
- pixel_maxDensity(penWidth, size) is returning a very low value, or
- the density value in your command is very high.
You can check the density value easily by looking in your command queue. If you see a good range of numbers in the fourth parameter of your C05 commands, then that is not your problem. I'd guess that you haven't set the pen size correctly, or you are using very small grid size (very small pixels).
When you say the test works fine, do you mean the pen width test? (The patches of decreasing density?) That pen width test uses the same code as you've highlighted above, so it must be working ok there. Remember that the pen width test does not set the pen width automatically itself. You need to look at the output patch, and then send a "set pen tip size" command yourself. Also remember that pen tip size is volatile - it is NOT saved in the machine when you reset it, so you need to re-send it every time you reset.
good luck
sn
|