User Pause Or Interrupt To I/O Data During Process Control Inputs

New poster here...Hello!

I'm somewhat new to Arduino land, have a need for interfacing between the board and the world. I have a few questions regarding I/O control interfacing.

Current project:

I'm designing an XY pick and place table to stuff SMD parts on solder masked circuit boards with a manual Z axis for placement with a "jog" feature for XY precision placement using microscope camera. To do that I'll need to pause a loop first to pick the part needed with the vacuum tip on the manual Z axis, then let the X & Y steppers move to the current position noted in the arrays, then stop for the placement of the part held on the Z axis for placement, then return the Z head to the reference XY coordinates for the cycle to repeat.

The hardware is no problem. The 1st rev. has already been tested with LTSpice and currently employs the oscillator for the main speed stepper drive and the divided "jog" stepper drive with four(4) Enables for direction CW/CCW, Run/Rest, main Clk enable and Jog Clk enable.

All I need 'at the moment' :confused: is a way to invoke I/O stuff, e.g. pick & place the part and move on to the next X & Y data in the arrays, etc. I hope I've explained the issue with enough detail. Thanks in advance for your responses and advice.

Cheers!

It's a state machine. Think about the states:

  1. No part in gripper (travel to pick up part)
  2. Part in gripper, travelling to pre-programmed XY
  3. Part in gripper, waiting for user input
  4. Placing part
  5. Retracting/homing

Each of those states has a set of inputs which will cause it to move to the next state. For example, when it's in state 3 waiting for you to nudge the final position, the only way it leaves that state is if you hit the "OK" button. All other buttons (X, Y etc) just make it move but it stays waiting for the OK.

MervC:
To do that I'll need to pause a loop

I suspect you should not be in a loop in the first place - certainly not a FOR or WHILE loop.

Have a look at the code in Several Things at a Time. No function takes an appreciable amount of time and long running tasks are achieved through many calls to a function.

None of which is intended to take from @MorganS's good advice.

...R

The first time you think, "I need to pause this.." Your going down the WRONG path. Keep that one rule in mind and you'll be fine.

-jim lee

Thanks for the reply!

Yes, that is essentially how I see the process working with the pseudo-code in my head. What I can't see from the less than robust instruction set for the Arduino is how to get to the point to place the code for the user input itself to do those 5 discrete steps you outlined.

Is it possible, for instance with this just coming to me now, to use a while loop like this for use with keyboard input;

/ Z axis preset at 'Home', .000 x .000 XY

while (x = 0); // start to get part for Z
/ set x to 0;
/ fetch X coordinate from bin array for part in bin;
/ fetch Y " ;
/ enable main clock
/ drive to part bin for part;
/ increment x to leave loop

while (x = 0); //jog for part in bin and pick
/ set x to 0;
/ trap Enter key to return to home;
/ trap Arrow keys for DirectionX & DirectionY;
/ enable Jog Clock, Run/Rest & CW/CCW;
/ jog Z in X & Y axes with arrow keys
/ manually pick part depressing Z axis vacuum pick head;
/ increment x to leave loop;

while...
/ take part XY coordinates from arrays;
/ same basic process as above picking and placing

/When arrays empty return 0, Z drives to Home and asks for a raise!

Well that is how I have seen it in my head. Are the while loops going to fit the purpose and where can I find some info on trapping keys on the keyboard? Thanks again and I look forward to your reply

Ditch all the while() loops. Use the main loop() to do this for you. For example, just decoding a couple of the states and assuming you are using stepper motors:

void loop() {
  switch(state) {
    case STATE_NOPART:
      if(curentX == destinationX && currentY == destinationY) {
        //we've arrived at the pickup location for the part
        //move to the next state which will drive the gripper to pick up the part.
        state = STATE_PICKUP_PART;
      } else {
        //have not yet reached pickup location
        //move towards the pickup location
        moveMotorsOneStep();
     }
   break;
   case STATE_PICKUP_PART:
      if(gripperIsClosed()) {
        //we've closed around the part 
        //do we need to pick 'up'? That may need another state to drive Z up to the travelling position
        destinationX = partXLocation(currentPart);  
        destinationY = partYLocation(currentPart);  
        state = STATE_TRAVELLING;
      } else {
         gripperCloseOneStep();
      }
    break;
  } //end of big state machine switch
}

If you are using DC motors instead of steppers then it doesn't change much. Instead of "move one step" you will drive the motors in the desired direction and speed and then currentX and currentY will be functions that read encoders or whatever.

You would have to draw the state machine. It will look a little like a flowchart as your states are very linear. But there will be a lot more states than you think. You also have to consider emergency situations, such as if you accidentally drive backwards past zero: either put code in each state to handle this or an overrride that always checks if currentX and currentY are greater than zero and enter an "emergency stop" state if that ever comes true.

the less than robust instruction set for the Arduino

The instruction set is perfectly precise and repeatable. The lack of any robustness is down to your poor programming. The Arduino language is called C++ which is what perhaps the majority of programs are written in.

A while loop is not what you want because it will repeat until some condition occurs. This is exactly what you don't want to do. What you are calling loops are simply sections that you break down the required actions. What you have defined should be implemented as separate functions. It is these functions that have to be repeated in a loop until the job is done.

My advice to you would be to learn simple programming first because this project is way way over your head at the moment.

Robin2:
I suspect you should not be in a loop in the first place - certainly not a FOR or WHILE loop.

Have a look at the code in Several Things at a Time. No function takes an appreciable amount of time and long running tasks are achieved through many calls to a function.

None of which is intended to take from @MorganS's good advice.

...R

Robin2:
I suspect you should not be in a loop in the first place - certainly not a FOR or WHILE loop.

Have a look at the code in Several Things at a Time. No function takes an appreciable amount of time and long running tasks are achieved through many calls to a function.

None of which is intended to take from @MorganS's good advice.

...R

Thanks for your reply!

Using a loop just seemed natural given the repetitive task of picking a part from one set of XY coordinates and placing it on its correct pads of a PCB doing the same thing over and over but with different locations drawn from the arrays. Several things at a time perhaps, but I have prototype designs with single boards holding 80-120 components, and I'm too old and shaky to stuff boards by hand :o, and not really into verbose code.

Even though I haven't done any coding for a very, very long time and was never an adept by any means, is there a compelling reason why one shouldn't use a loop of some type for redundant I/O tasks requiring User input using the Arduino? I skimmed the link you cited, but I didn't see the connection given the need for redundant User input throughout the objective of picking and placing.

Hey, I could well be wrong on that score so I look forward to your reply if i'm confused about something.

Cheers!

The reason you don't use a for() or while() loop is the Arduino needs to do many things at once. It needs to check all the limit switches and emergency-stop switches at least a hundred times per second. You can put that check into every loop and provide a way of breaking out of every loop and getting to the right place you needed to go after that loop or you can make it much simpler when you avoid using loops that take longer than 1/100th of a second.

If you had GOTOs then you could GOTO the correct emergency-stop code or 'motor arrived at destination' code but then you've got spaghetti that's difficult to read and understand.

You always want to read inputs and you always want the outputs to output a valid set of outputs. So just do this a few thousand times per second and it appears instantaneous to the bags of meat watching it work.

void loop() {
  readInputs();
  doCalculations();
  setOutputs();
}

Grumpy_Mike:
The instruction set is perfectly precise and repeatable. The lack of any robustness is down to your poor programming. The Arduino language is called C++ which is what perhaps the majority of programs are written in.

A while loop is not what you want because it will repeat until some condition occurs. This is exactly what you don't want to do. What you are calling loops are simply sections that you break down the required actions. What you have defined should be implemented as separate functions. It is these functions that have to be repeated in a loop until the job is done.

My advice to you would be to learn simple programming first because this project is way way over your head at the moment.

Thank you for your charming welcome and your helpful feedback. This forum is very lucky to have your mentoring skills, I'm sure!

BTW, with over 50 years of experience in the field of electronics, first as a tech and later as an engineer, my non-retired contemporaries at Intel might take exception with you regarding this project being over my head, but hey you could be right because even a blind squirrel can find an acorn from time to time. Now you have a nice day!

This forum is very lucky to have your mentoring skills, I'm sure!

Well not as lucky as it is to have folk like you so willing and eager to learn. All that with out touch of immodesty or an inflated idea of your own ability. Remember even a blind squirrel has a sense of smell. And any sense is better than none at all.

MervC:
is there a compelling reason why one shouldn't use a loop of some type for redundant I/O tasks requiring User input using the Arduino?

Yes. Your need, occasionally, to pause things.

I skimmed the link you cited, but I didn't see the connection given the need for redundant User input throughout the objective of picking and placing.

I suspect you are still thinking of the problem from the point of view of a human rather than a computer. Humans multi-task without being aware they are doing it. The key to writing a successful program is understanding how stupid a computer is. The computer won't care, or even be aware, that it is doing redundant checks.

...R