Jogging A Machine Using Arrow Keys


tplcfan

Recommended Posts

Here is a little background since this is my first post. I am using DaqFactory to create an HMI for a small 4-axis pick-and-place type machine that uses a Tri-PLC F2424 to control PID loops, lighting, stepper motors and other general purpose I/O. It is coming along nicely, but I am struggling with a couple things which may or may not be related. I am not a very sophisticated programmer. I have done a fair amount of PLC programming, including some custom functions using TBasic, and a couple very basic VB programs. I am learning this stuff mainly from the DF user guide, this forum, the TPLC manuals, and their forum.

I am trying to use the keyboard arrow keys to jog (move) the machine axes. I use the onkeydown and onkeyup functions. It is working, but buggy. Sometimes the machine does not respond to an arrow key down, and worse, sometimes it misses the event for onkeyup and the machine keeps moving when the button is not pressed. I suspect Modbus port locked errors are the real problem. I have 570 channels, roughly 135 with timing ranging from 0.2 to 7.5 seconds. I have attached the channel list. Sometimes I get port locked errors constantly, and sometimes it's a few seconds in between errors, but I have not been able to eliminate them completely. I am looking for some advice on how to make this work reliably.

Right arrow jogs X+, Left Arrow jogs X-, Up Arrow jogs Y+, Dn Arrow jogs Y-

Shift+Right jogs 4th+, Shift+Left jogs 4th-, Shift+Up jogs Z+, Shift+Dn jogs Z-

Here is the onkeydown Sequence:

? "Key Down:" + Key

beginseq(JogHold)

if (jogging == 0)

If ((Key >= 37) && (Key <= 40))

global keydown = Key

Else

keydown = 0

return(0)

Endif

if ((key == 37) && (Shift == 0))

//Jog X Left

CmdWord1 = SetBit(CmdWord1,1)

hmiCMDWord = CmdWord1

jogging = 1

return(1)

endif

if ((key == 39) && (Shift == 0))

//Jog X Right

CmdWord1 = SetBit(CmdWord1,0)

hmiCMDWord = CmdWord1

jogging = 2

return(1)

endif

if ((key == 40) && (Shift == 0))

//Jog Y Fwd

CmdWord1 = SetBit(CmdWord1,3)

hmiCMDWord = CmdWord1

jogging = 3

return(1)

endif

if ((key == 38) && (Shift == 0))

//Jog Y Back

CmdWord1 = SetBit(CmdWord1,2)

hmiCMDWord = CmdWord1

jogging = 4

return(1)

endif

if ((key == 40) && (shift == 1))

//Jog Z Down

CmdWord1 = SetBit(CmdWord1,5)

hmiCMDWord = CmdWord1

jogging = 5

return(1)

endif

if ((key == 38) && (shift == 1))

//Jog Z Up

CmdWord1 = SetBit(CmdWord1,4)

hmiCMDWord = CmdWord1

jogging = 6

return(1)

endif

if ((key == 37) && (shift == 1))

//Jog Theta CW looking up

CmdWord1 = SetBit(CmdWord1,6)

hmiCMDWord = CmdWord1

jogging = 7

return(1)

endif

if ((key == 39) && (shift == 1))

//Jog Theta CCW

CmdWord1 = SetBit(CmdWord1,7)

hmiCMDWord = CmdWord1

jogging = 8

return(1)

endif

endif

return(0)

and the onkeyup sequence:

? "Key Up:" + Key

if (key == 37)

CmdWord1 = ClearBit(CmdWord1,1)

CmdWord1 = ClearBit(CmdWord1,6)

hmiCMDword = CmdWord1

jogging = 0

return(1)

endif

if (key == 39)

CmdWord1 = ClearBit(CmdWord1,0)

CmdWord1 = ClearBit(CmdWord1,7)

hmiCMDword = CmdWord1

jogging = 0

return(1)

endif

if (key == 40)

CmdWord1 = ClearBit(CmdWord1,3)

CmdWord1 = ClearBit(CmdWord1,5)

hmiCMDword = CmdWord1

jogging = 0

return(1)

endif

if (key == 38)

CmdWord1 = ClearBit(CmdWord1,2)

CmdWord1 = ClearBit(CmdWord1,4)

hmiCMDword = CmdWord1

jogging = 0

return(1)

endif

return(0)

channels.txt

Link to comment
Share on other sites

Well, first you need to figure out if its missing because its missing the key up event, or because when the key up event occurs, its not sending the command to the PLC because of a port locked issue. Its most likely the second, in which case you need to figure a way to ensure the output is changed. There are two ways to do this:

1) create a little loop that checks:


for (private count = 0, count < 5, count++)
out = 1
if (out[0] == 1)
break
endif
endfor

[/CODE]

That's just one way. I believe if you use device.myDevice.forceCoil() instead of a channel, it will actually throw an error if its not set, which makes things a little easier to detect.

Alternatively you could switch off using Timing for your channels and trigger all your reads from a single sequence (use channel.readGroup() to make it easier). Then you can have that sequence also set any output each iteration. This makes it so all the I/O is on one thread and keeps things from bumping into each other.

That all said, I would seriously consider an alternate method to onkeydown/Up. Actually two alternate methods. The problem with keyup/down is that its pretty much active all the time. That is just asking for someone to hit the arrow keys inadvertently. I am constantly typing things into the wrong application (because I have too many windows open I suppose!), and while its not a big deal with a word processor because I can just Undo the changes, it would be a big deal if you accidently moved the device. So:

1) use the 4 way hat component. This component, once it has focus (meaning clicked on once) will process arrow keys for the four directions. If you wanted the shift accelerator, you could still use onkeydown/Up to monitor for shift and set a flag. But at least now the only way you get keyboard control is to actually click on the 4 way hat once. You can see this in action by trying the Lunar fork lander sample.

2) don't do it in DAQFactory at all: go and buy 4 push button switches (or 8 if you want accelerated movement) and wire them into digital inputs on the PLC. Then do the job in the PLC instead of DAQFactory. You could, technically, run the inputs through the PLC to DAQFactory and let DAQFactory handle the logic, but you only have one PLC, so why not just let the PLC do the work. If you had multiple PLC's, a dumb DAQ device instead of a controller, or more advanced logic than a PLC could handle, then send it through DAQFactory. The reason for going this route isn't the software, but rather the fact that you are trying to use a generic input device (the keyboard) to act like buttons. There's a reason you don't just see a big keyboard on industrial control panels.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.