Why do you map analog reads of 0 to 5 onto 0 to 1023? Don't you expect analog reads of > 5? What happens if the read is 100?
If you want to test the hardware, show the raw data values, your translation to width is another place to get something wrong!
Have it check the read and if the last read was the same or very close don't print it. Get the data to scroll down Serial Monitor and when you stop measuring and the number don't change much (so no printing) you can scroll the data in Monitor and see if it looks good or there's a glitch in the measuring.
Speed up your Serial baud rate! 9600 is slow! 115200 is better, and make sure that Monitor is set for the same.
If it didn't have to be automatic.... suppose an operator could eyeball the board, find the narrowest spot(s) and clamp a measuring thing right across? Shortest distance from any point to a line will be at right angle to that line (algebra) and the line is that straight cut edge.
Ripcrow:
Thanks for the input. I’ll try to give a better explanation. The logs are cut into peices using a horizontal band saw. This produces a cant. The cant could potentially be any where from 40 inches wide down to 8 inches wide. The cant is fed directly into a frame saw which will cut the cant into 1 inch thick peices but because the log is not squared before the cant is produced the peices will have not be the same height. If you think of a semi citcle where it’s centre height is 7 inches you can see that some peices will make a 6 board and some will only make a 4 or 3 inch board. As the peices leave the frame saw they drop into a bin with a pickup feed chain that will feed the peices out to a conveyor one at a time and in any order.
This is where the arduino has to decide which resaw to direct the peices to so that maximum recovery is made.
As a sawyer, a cant is the squared 'timber' after the slabs are removed. Draw a rectangle inside a "round object" (circle, oval, egg, ellipse, whatever trees aren't perfectly round). The slabs are the four semi-circular pieces, the cant is the rectangle in the middle.
Sawmills stockpile cants of specialty woods and sizes. There are many critters that like to live just under the bark in the cambium of live, drying, and dried logs. Cutting the log into a cant, removes this problem. Storing the cant for later use allows boards to be cut on demand.
It sounds like you want to recover wood from the slabs. An admirable target. When I saw, I don't quite make the cant the full size. Typically I have 2-4 live edge boards that will need to be trimmed. This lessens the thickness (and weight) of the slabs.
A 40" diameter log will produce a 29" wide slab 6" thick (it is was a perfect circle). This sets the maximum width for the test jig (~30"). Since you know the back reference (slab is clamped against the back stops. Typically mills work with 1" increments, you will need 30 sensors 1" apart to span the board, with a reach of at least 8". More if you want to account for knots. But that can be remedied by take off a slab of useless back and cambium off first. Doing this turns the slab from semi-circle into trapezoid shape. Now you can run your sensor array along the slab to determine the width at each thickness. You should be looking to answer the question" How wide a board will I get 1" , 2", 3", 4" and 5" from the bed?
3 squared sides, a plank with a straight edge and a rough one is what I thought is to be measured. You can find the narrowest width with a square-head and scale but that takes time, suppose you could measure as the long cut is made right at the cut and save the least width to show at the end? The rough edge would move a finger/roller? This is why I say about point-line closest being square to the line, that is how the algebra works.
You were thinking microswitches below for a bunch of fingers the board width holds down? How are they about dust? With a Hall Switch (cheap) you can detect a regular/poor magnet close up no matter dust/dirt/water. You can make heavy fingers and springs that can bang stops instead of sensors that don't wear out.
In a dusty/dirty environment at lot of sensors are out of it sooner or later.
GoForSmoke:
3 squared sides, a plank with a straight edge and a rough one is what I thought is to be measured.
suppose you could measure as the long cut is made right at the cut and save the least width to show at the end? The rough edge would move a finger/roller?
I see the point right next to the blade as a fixed point in space
one point that might offer the ability to measure.
alas, with no photos of the set-up, the point is moot.
as for the sketch...
I did not see where the smallest point was saved in a measurement.
I have been playing with code and cant get it to work. Basically just trying to get the pot read when the microswitch is triggered and switch on an LED depending on switchstate and pot val . the arduiuno reads the pot regardless of switchstate and wont turn the Led on or off based on the pot value
[code]
int val (0,1023);
int val2 (LOW,HIGH);
int potpin = A0 ;
int ledpin = 8 ;
const int switchpin = 2 ;
void setup() {
Serial.begin (9600) ;
pinMode (2 ,INPUT_PULLUP);
pinMode (9 ,INPUT);
pinMode (A0 , INPUT);
pinMode (8,OUTPUT);
// put your setup code here, to run once:
}
void loop() {
val = analogRead (potpin) ;
val2 = digitalRead( switchpin);
digitalRead (2);
if (2,LOW ) analogRead (val);
else digitalRead (2);
if (2,HIGH) digitalWrite (8,HIGH);
else digitalWrite (8,LOW);
Serial.println (val);
Serial.println (val2);
if (val>500)digitalWrite ( 8,HIGH);
else (8,LOW);
delay (100);
// put your main code here, to run repeatedly:
}
Play with working examples some more. There's no way that compiles, you're missing some key concepts and try doing what I know you've never seen in working code.
if (val>500)digitalWrite ( 8,HIGH);
else (8,LOW);
Because how is that supposed to work? Emphasis on supposed. Is the else a part of digitalWrite?
You're not yet ready to write this code. You can't even declare variables right!
int val (0,1023);
int val2 (LOW,HIGH);
Hey! That looks neat! Makes sense! Why not? Oh it isn't? It doesn't? Well I don't know what it's supposed to MEAN, it just looks neat!
No, really, check everything. When you go writing false code, you reinforce wrong ideas that can be very hard to unlearn.
Be sure about every line you write, check with the Reference Page and examples wherever you're not sure the least bit.
question : what programming language are you trying to use ?
the format does not conform to the C++ we see for the Arduinos
lets talk about what you want.
if the switch goes HIGH
then you want to turn ON the LED
and also start using the reading from the POT.
if the switch goes LOW, you want to turn OFF the LED and do nothing.
if the switch goes HIGH and... the POT if over 500, THEN ..
write it out like that.
Here is my suggestion based on what I think I got from the thread.
put in 3 LEDs
one is for the switch
one is less than 500 and one is greater than 500
if the switch is HIGH
light the switch_LED
and the pot is over 500... light 500_LED this would represent a board under 6 inches
if the pot is over 750... light the 750_LED this would represent a board over 6 inches
if the switch is off
turn off all LED's
since the pot will return 0-1023 for the full range, you can easily find the vales for whatever inches you have.
It has taken a while and a few different structure approaches but I finally found a way to capture and act on an event if the board fails to meet specs. Originally I was going to measure the edge of each board and determine the smallest point but I settled on setting the pots to measure exactly on the 6 inch and four inch wide points. If I measure a 6 inch board at that point and it passes then it can go to the 6 inch saw if not it can be diverted to the 4 inch measuring station and onto the 4 inch saw if it then passed .
I settled on using an interrupt to capture any event outside of spec. I could not find how to trigger a software interrupt so I found a way to trigger a hardware interrupt using software.
As the board enters the measuring area it passes over a switch and between 2 rollers connected to the arms of the potentiometers. The board will be in between the rollers before the switch is activated. This flow ensures the pots should be reading above 500 before the switch is pressed.
[code]
int ledpin =(8);
int switchpin= (7);
int val = (LOW,HIGH);
int pot=A0;
volatile int val2=(0,1023);
int ledpin2=(9);
void setup() {
Serial.begin (9600);
pinMode (8,OUTPUT);
pinMode (7,INPUT_PULLUP);
pinMode (9,OUTPUT);
attachInterrupt(0,ISR1,HIGH);
// put your setup code here, to run once:
}
void loop() {int val =digitalRead(switchpin);
int val2= analogRead(pot);
if (val==0 && val2<=499)digitalWrite(ledpin2,HIGH);
Serial.println (val2);
Serial.println (val);
delay(500);
if (val==1){digitalWrite(ledpin2,LOW);
Serial.println("detach");
digitalWrite (ledpin,LOW);}
// put your main code here, to run repeatedly:
}
void ISR1(){
Serial.println("interupt");
digitalWrite(ledpin,HIGH);}
[/code] If the pots go below 500 while the switch is pressed a digitalwrite command is issued using ledpin which is connected back to interrupt pin 0 therefore triggering the interrupt. the interput simply send sends the board to the next smallest saw and the interrupt cannot exit until the board has cleared the first measuring area (stopped pressing on the microswitch ) as the switch changing its stae issues a digitalwrite low code to the ledpin .
this is only the trial code and I welcome any suggestions to improve on it.
I'll help you do better with the code, my father's side of the family cut timber in Maine.
You could slide the board down to a stop and read 6 pins simultaneous at 50-80K read-and-stores per second using direct Port reads instead of the 5x slower Arduino read to get 1 pin. This is no problem, example code level I even have a loopcounter function to show how fast it's running, a diagnostic tool.
Board at the stop, could the saw and fence adjust to proper width and then drop the board through? Figure out lengths to measure the next while the first one saws and some kind of down the line sorter, move the right bin in line with the chute... you could be busy for a time just feeding the line while one other watches for snags and clears the bins.. and get a pile of boards cut and sorted fast that way.
It would take a bit of roboting that can be modularized, the saw positioner and sort bin mover to custom cut and custom collect.
An Uno can read 6 pins at once in 1 cycle, bitmask the 2 "system bits" off in the next and compare to previous in the 3rd giving the changed bits is less than 1/4 of a microsecond. You don't need to resort to interrupts and multiple reads to get different board widths, I handle that with non-blocking code that uses the full power of the CPU.
Consider that delay(1) wastes 16000 cycles while automating the line might take 400-500 cycles to finish 1 loop(). If you put a delay(1) in an otherwise 400 cycle loop() the pins would only get read 500 times a second instead of 50000, a hundred times slower!
If yer interested, a Mega 2560 or 1284P board will let your read 8 pins at a time. I think you could use 2/4/6/8" at least.
The delay won’t be in the final code and it will be putting boards through as fast as I can feed it. It’s only a sample to get a feel for what works. The saws are positioned at set places. As the board enters it is measured first at 6 inches and passes through the saw. If it measured a complete length the interrupt is not activated so it passes to the 6 inch bin for stacking. If the board is not a full 6 inch width over its length the interrupt is activated and the board is sent to the 4 inch measuring area where it its measured and sawn to 4 inches. The same principle applies as the board passes from the 6 inch to 4 inch and 3 inch saw stations allowing non stop flow. The use of switches to activate when to measure and when to stop measuring means no encoders or any chance of missing board lengths or the system not coping with board lengths not being perfect. This code only measures the board widths and saws and sorts ready for stacking. Another code will run the length cutting and I’d expect cycle times to be about 1 second for a 1.2 metre board to be sized and cut. Board lengths will be 30 cm 50 cm 70 cm 90 cm and 1.2 metre so coding up the width cutting area with an encoder and sortIng length and widths any arduino board is impossible. I’d expect each area to utilise all pins on an Arduino Uno so I’m not sure how much harder an arduino can be run or expected to achieve. I’m looking for a unit that will be transportable and robust enough to work outdoors and can be easily fixed on site without a lot of electronic experience. Switches and pots are easy to replace and diagnose.
I was thinking of 1 sheet metal finger per sense pin, an inch or two apart dragging against the board looking to see if it raised before all the fingers raised (end of board). The board is at least as wide the biggest one that never raised. Very simple, can indicate size with leds. It does all that your last posted approach does.
You could measure the board (adding: with a roller) as it goes by with 100's of switches (adding: lined up across the board) using the SPI port, some number of input shift registers and a lot of wiring. The inputs all read at the same moment but the data reaches the Arduino (fix:) one 8 bit byte at a time 32 cycles apart, (fix: At) 512K byes per second it can read 64 8 bit registers 8192 times per second. adding: and with the last read in 64 bytes (512 switches) buffer, record only the changes.
Say the sketch maps boards as present or absent 1" wide x 4" long. 8" wide x 4" long only takes 1 byte to store as 8 bits. 3 bytes per foot, a 20 foot board only needs 60 bytes to map as 1x4's.
As the board gets read, any finger that goes up where board should be can turn the bit for where it is off which other pins may do, only if it stays on is that section solid.
Should a divvy routine look for length over width or v-v? The map is bit states in an array saying which board pixels are absent/present. One dimension is the bit number (8 wide) and the other is the byte number, board map areas can be checked for width x length all HIGH. Present the operator with choices for rips and clear the bits that represent cuts taken off the board. You could have a list of desired cuts and check for those width x length dimensions first.
Lots of things could be done. The overall plan is. If you can imagine a 6 metre long board being fed into the machine. It may be 7 inches wide for a start and finish at 3.5 inches wide due to log taper.
The board is fed into the docking machine where it wil travel until it hits a hard stop with a switch fitted. The switch will tell an arduino to stop the boards forwards travel and lower a saw fixed at 1.2 metres away from the hard stop cutting a 1.2 metre long board. When the saw has cut fully and is retracting from the cut an actuator is used to push the cut length sideways to the board width measuring area. The docking cycle could be controlled using time or microswitches for saw and actuator movement.
So as the cut length moves into the width measuring area we have a 1.2 metre length that could measure 7 inches at one end and 5 inches at the other. The pots read a line just in front of the 6 inch width saw blade. As this board is not a full 6 inches wide over its length the pots will fall below the set value while the board is pressing on the switch ( indicating to arduino it needs to read and act ). This fall in value will trip the interrupt which will allow the board to pass straight to the 4 inch board measurement and saw station. If it was a full 7 inch wide in total length the pots would show above or equal to set value and the board will be sent to the stacking area as it will have been trimmed to 6 inches already by the set saw it had to pass.
The use of set saws and not a moveable saw and fence system gives extra robustness to the transportable system as well as simplicity for coding and any operator to set it up after transport. It’s all just plug it in and start and no worries about vibration and movement that may mean a recalibration of servos and motors etc. Spare parts needed on site are also a few microswitches,pots and a spare actuator. If we go with a moveable saw and fence system we need encoders and sensors added to the spare parts list and perhaps more then a basic electronic experience to fit and diagnose.
A commercial docking saw costs $80,000 in Australia and can produce up to 300-400 cubic metres a day which is not bad value. It is made to be fixed in a shed and is driven by 3 phase electricity. A trimmer saw with moveable blades and or fence system is expensive but it does the volume to pay for itself.
My problem is I only have a small supply of timber that is not of a great quality so any boards that can be recovered will not have a great value. With a small volume of timber to process and only a low sale price being achievable I cannot pay commercial prices for docking saws and trimming saws. Finding a way to cut 20 cubic metres a day and survive in an industry where volume is key is not easy. No one builds equipment to cut 20 cube a day as no one wants it but in my case I can’t manually cut 20 cube a day with a mobile sawmill so I need to build the equipment I need. Commercial computer controlled sawmills are getting 40-45% recovery ( that is for every cubic metre of logs that are delivered they only recover .4-.45 of a cubic metre of boards ) which is a terrible recovery but they make it up with volume. A mobile hand operated sawmill can achieve up 70 % recovery and I’d like to achieve a good balance and aim for a 60% recovery using a mobile sawmill with simple computer controls to cut wages and keep the project viable. 20 cube a day at an average width of 4-6 inches is only 5333 boards in 8 hours or roughly 12 boards a minute or .2 of a board per second.
The system can run faster then this for sure but I’m not sure I need it to run faster.
You could map the whole 12 meter length as "pixel areas" and use rule-based software techniques to find listed sizes using that map. What rules however involve any cut changing the map into 2 maps. For sure a lot of work but it -is- possible to compute large usable board areas with Uno.