If (Check) {Do Something}... ?
Greetings,
Working of a program with Home Limit Input Bit 1034, Peddle for Go which is Input 1033, and Lower limit which is Input 1035.
This is for a simple punch machine control. Using Konnect board for I/O and three inputs.
When I push the peddle I want axis 2 to go down. When I let off the peddle it should stop.
This code below works... for this.
______________________________
Quote:
#include "KMotionDef.h"
main()
{
for(;;)
{
if (!ReadBit(1033))
{
while (!ReadBit(1033));
Jog(2,-100);
}
if (ReadBit(1033))
{
while (ReadBit(1033));
Jog(2,0);
}
}
}
_________________________________________
Now I need to to stop this motion also if the lower input (1034) comes on. Then home to the upper input (1034).
I have tried to do this, but have had little luck with the code... and trying to add the other monitoring... Think I am just missing something?
Thanks in advance for any help?
- Jeff
Re: If (Check) {Do Something}... ?
Hi Jeff,
Quote:
Now I need to to stop this motion also if the lower input (1034) comes on. The home to the upper input (1034).
Is that a typo? Can you explain more clearly?
1 Attachment(s)
Re: If (Check) {Do Something}... ?
Tom,
Yes that was a typo! Go figure!!
See here for what I want to accomplish to start. This will get more complicated later, with a fast and slow speed input. Not worried about that yet!
Attachment 502902
Re: If (Check) {Do Something}... ?
Hi Jeff,
A general way to handle multiple events using a single Thread is to use a State Machine, See the untested example below:
Code:
#include "KMotionDef.h"
// Press Brake control
enum { IDLE, JOG_DOWN, DELAY, HOME }; // states
#define BIT_PEDAL 1033
#define BIT_NEG_LIMIT 1035
#define BIT_TOP_LIMIT 1034
#define BIT_AUTO 46
#define ZAXIS 0
#define DWELL 2.0 // delay at bottom seconds
void main()
{
int state=IDLE;
double DelayTime;
for (;;)
{
switch (state)
{
case IDLE:
if (ReadBit(BIT_PEDAL))
{
Jog(ZAXIS, -100); // Jog down
state = JOG_DOWN;
}
break;
case JOG_DOWN:
// stop Jogging down if pedal released and not Auto mode
if (!ReadBit(BIT_PEDAL) && !ReadBit(BIT_AUTO))
{
Jog(ZAXIS, 0); // Stop
state = IDLE;
}
else
{
// hit negative limit?
if (ReadBit(BIT_NEG_LIMIT))
{
Jog(ZAXIS, 0); // Stop
DelayTime = Time_sec() + DWELL;
state = DELAY;
}
}
break;
case DELAY:
if (Time_sec() > DelayTime) // Dwell finished?
{
Jog(ZAXIS, 400); // Begin Homing
state = HOME;
}
break;
case HOME:
if (ReadBit(BIT_TOP_LIMIT)) // Homed?
{
Jog(ZAXIS, 0); // Stop
state = IDLE;
}
break;
}
}
}
Re: If (Check) {Do Something}... ?
Thanks so much!
I am getting something accomplished now! This is working!! Of course I will modify to the specifics according to the machine.
I will be using the the Kflop and Kanalog control boards to do this.
The program will have a couple of more inputs, for different modes or ways of operating the code sequencing.
The State Machine idea is a good thing. I like that.
Thanks - Jeff