Finite State Glue Machine

Glue machine

I am having trouble writing the program for a machine I designed that applies glue on a wood veneer so that the amount of glue used will be consistent. It will essentially, through the use of compressed air and two moving axises, squeeze wood glue through a perforated PVC pipe onto a veneer leaving behind lines of glue that can be easily spread with paint rollers.

the machine consists of a table approximately 9 feet long(x-axis) by 4 feet wide(y-axis). There is an armature that spans across the y-axis and rolls forward and backward over the length of the table (x-axis). Mounted on the armature is a 12 inch PVC pipe with a single row of 12 equally spaced nozzles screwed into it that moves positively and negatively along the y-axis. Motion is made by two 12vdc motors. The x-axis motor makes the entire armature move along the x-axis and the y-axis motor makes the pvc pipe with the nozzles move along the y-axis.

To determine the position of the armature there are two instant on/off switches. One is permanently located at “zero” or “home” on the x-axis and the other can be moved to the appropriate distance depending on the length of the veneer being glued. On the y-axis there are 4 permanently mounted instant switches. These switches will be used in sequence depending on the width of the veneer being glued. The first switch is located at “zero” or “home”, the second is on the 12 inch mark along the y-axis, the third at the 24 inch mark and the fourth is at the 36 inch mark.

There are four possible programs for the glue operations. The operations are determined by the width of the piece of veneer being glued because each time the armature makes a pass along the x- axis it will leave behind a glued area 12 inches wide. If the piece of veneer is 48 inches wide the armature will have to make four passes. The length of the veneer doesn't really matter because the second stop switch on the x axis is movable and will be set to the needed distance depending on the veneer's length.

What I want to do in the case of a veneer 24 inches wide and 48 inches long is set the x-axis stop switch at 48 inches and press a button for “2 passes”. The machine will then turn on the air pressure to the PVC pipe containing the glue and turn on the x_axis motor in the positive direction until the x-axis switch is reached. At that time the air pressure would be turned off and the y-axis motor would be turned on in the positive direction until the the second y-axis position switch is reached. When that happens I want the air pressure to turn on and the x-axis motor to turn on in the negative direction until the x-axis home switch is reached. At that point the air pressure is turned off and the program is finished.

I guess a finite state machine would be the best way to go here but I am really unsure how to make that work because I have done a lot of coding with a test setup and haven't been able to make all the things I said work properly. Basically only one of the two motors will be on at any one time so at the time of that motion the machine is only looking for the input of a single switch. I can't seem to get the program to forget about the state of the other switches.

I'm sorry if this is a super long post, I tend to ramble on but I want to be as specific as possible so everyone can understand what I mean. Its really a pretty simple machine and any help you guys and gals could give would be very much appreciated.

Interesting project - how is it wired up and to which arduino? Certainly sounds like you'll need most of the Uno pins in use unless there's some cunning multiplexing going on. Also, it would help if you could post the code you have so far.

Sounds like a useful machine if you're doing a lot of veneering. One question though: how do you keep the veneer from curling once it's wet by the glue? It's standard practice to put the glue on the substrate.

the veneer is going to be taped down to the table then removed after the glue has been spread. the substrate is a very irregular surface and unless the ribbons of glue are close enough together that I don't need to spread the glue out at all my best bet would be to glue the veneer. You bring up a good point though. Maybe I can glue the substrate with this table design.

Thanks WildBill. I am using a Mega board. I copied a relay shield/board that can connect seven 12vdc automotive relays (sort of like an H-bridge). Something I should note about that; normally for two reversible motors you would need eight relays. In my design there are only six controlling those motors. I did that using two three way relays that are set to negative 12vdc in the normal condition. here is the code i have for the programmed moves, I'm sure it's a mess. and some pics of the button board and the inside of the computer case I'm using to hold everything.

const int startBtn = 1;
const int xHomeSw = 2;
const int yHomeSw = 3;
const int yPos2Sw = 4;
const int yPos3Sw = 5;
const int prog4Btn = 6;
const int xLimitSw = 7;

const int xFor1 = 8;
const int xRev1 = 9;
const int yFor1 = 10;
const int yRev1 = 11;
const int airOn = 12;

int xHomeSwState = 0;
int yHomeSwState = 0;
int yPos2SwState = 0;
int yPos3SwState = 0;
int prog4BtnState = 0;
int xLimitSwState = 0;
int startBtnState = 0;

void setup()
{
pinMode(startBtn,INPUT);
pinMode(xHomeSw,INPUT);
pinMode(yHomeSw,INPUT);
pinMode(yPos2Sw,INPUT);
pinMode(yPos3Sw,INPUT);
pinMode(prog4Btn,INPUT);
pinMode(xLimitSw,INPUT);

pinMode(xFor1,OUTPUT);
pinMode(xRev1,OUTPUT);
pinMode(yFor1,OUTPUT);
pinMode(yRev1,OUTPUT);
pinMode(airOn,OUTPUT);
}

void loop()
{

startBtnState = digitalRead(startBtn);
xHomeSwState = digitalRead(xHomeSw);
yHomeSwState = digitalRead(yHomeSw);
yPos2SwState = digitalRead(yPos2Sw);
yPos3SwState = digitalRead(yPos3Sw);
prog4BtnState = digitalRead(prog4Btn);
xLimitSwState = digitalRead(xLimitSw);

prog4Run ();

}

void prog4Run()

{
if (startBtnState == HIGH && prog4BtnState == HIGH)
{
pass1();pass2();
}

}

void pass1()

{
if (xLimitSwState == LOW)
{
digitalWrite(airOn, HIGH);
digitalWrite(xFor1, HIGH);
}
if (xLimitSwState == HIGH)
{
digitalWrite(airOn, LOW);
digitalWrite(xFor1, LOW);
}
}

void pass2()
{
if (yPos2SwState == LOW)
{
digitalWrite(yFor1, HIGH);
}
if (yPos2SwState == HIGH)
{
digitalWrite(yFor1, LOW);
}
}

void allStop()

{
digitalWrite(airOn, LOW);
digitalWrite(xFor1, LOW);
digitalWrite(xRev1,LOW);
digitalWrite(yFor1, LOW);
digitalWrite(yRev1, LOW);
}

inside view glue machine.jpg

buttons.jpg

I am basically using one of these circuits for each relay. I am using TIP 102's for the transistors but everything else is the same.

Is your focus getting the machine working or are you hoping to improve your coding skills with this project? In other words, how much assistance are you looking for here?

Is the machine constructed at this point (in which case I'd be interested to see a picture) or are you running your tests with the button box? Looking at the picture, I'm guessing that there are four buttons that represent the y-axis switches, two for those on the x-axis, three buttons that indicate 2, 3 or 4 passes, a start button & one other. Or are some of them lights that indicate the outputs for the motors & compressed air?

What does your existing code do? It looks as though it's going to turn on both motors and drive them until limitx and the first ylimit switches are hit, which I'd guess means it'll go diagonally for a while and then straight until it reaches the x-limit.

I'm just trying to get the machine functional. I don't really care how elegant the code as long as it does the job. The panel that I posted a picture of is the actual control panel for the machine. I have the relay circuit board and the button panel built but I have not been able to at this time make the actual table and gantry nor have I sourced the actual 12VDC motors that will move the gantry and the glue head assembly.

The only buttons I am looking for help programming are the 5 red buttons in the JPG i uploaded. They all do similar things its just the 4 pass button does it the most times. What I want the machine to do is this. I turn on the main power and the computer powers up as well as the relays and powersupply for the motors and switches. When I press the Home button the gantry should move in reverse until the X-Home Switch is HIGH. If the X-Limit Home switch is HIGH then the Glue Head should move in reverse until the Y-Home switch state is HIGH. If both the X-Home AND Y-Home Switches are HIGH then the program is done and it is returned to the loop. If the 4-Pass Button is pressed i want the air to turn on and the gantry to move forward until the X-Limit Switch State = HIGH. If X-Limit Switch State = HIGH digitalWrite airOn LOW. You see what I'm saying right? The glue head starts at the zero position on both axis, the glue turns on and the gantry moves forward leaving behind glue. When it gets to the end of the veneer which I will locate the X-Limit Switch at the x motor turns off and so does the air. The Y-Motor then turns on and the glue head moves over to the next closest place that hasnt been glued which is located at the y position 2 switch. When that happens the glue is turned back on and the x motor moves the gantry in reverse leaving behind two glued areas. when the gantry gets back to zero on the x axis and the glue head is still in position two the glue is turned of and the glue head moves over to position three and the glue is turned back on and the x motor moves the gantry forward until the x limit switch is hit again and so on until all 48 inches of the surface is glued.

That diagram makes it clearer, I didn't quite have the controller figured out. In any event, here's some code based on yours that may be adaptable - it's based on what I thought your controller was doing. It works off the limit switches as you require and will turn on the air for the glue, but the buttons aren't right, although it would be trivial to fix that but it's getting late. It uses two buttons: one starts the machine for a gluing pass, the other determines whether it's a single or double pass.

The actions performed are encoded into a couple of byte arrays, so you can build other sequences in additional arrays and assign them to your other multi-pass buttons. You can change the CheckForStart routine to invoke them.

I tested it with LEDs for motors and switches for your buttons and limit sensors. It doesn't seem to need key debouncing, though this may well not be true in a noisier environment.

I note that you're using Pin one - I was using an Uno and needed Serial for debugging, so my pinout is different. You may need to adapt the serial piece to use an appropriate UART on your device, or disable it.

I used typedef struct to define the ACT that holds the action config. This caused compilation errors which were solved by moving the typedef into a header file, putting it in a subdirectory under arduino/libraries and then importing the library. Annoying.

Hope this helps

gluecode (10.7 KB)

GlueMachine.h (534 Bytes)

hey man. Thanks a lot for the help. This is my first project and I really appreciate it. I'm looking into the code now. It will prob take me a week to figure it all out and implement it but I will let you know how it goes!