Walkthrough: Problem 15: Crane Game

Difficulty

Target behavior

Start a play with the Start button and move the arm left/right and back only while the buttons are held. When the button is released, the arm automatically grabs a prize, carries it to the drop chute, and releases it

What you will learn

  • JOG operation (moving an axis only while a button is held)
  • Combining JOG and point operation
  • Catching the moment a button is released with a falling edge (LDF)
  • Lighting a lamp for a set time with a pulse (LDP) and a timer

Problem

This time you run a crane game, like the ones in arcades, with three servo axes and an air gripper.

The key is combining JOG operation, which moves an axis only while a button is held, with automatic point positioning.


How to play (how the equipment works)

  1. When you switch to RUN, the three axes return to origin and wait. At the origin (all axes at 0 mm) the claw is right above the drop hole at the front left.
  2. The start button begins a play. Light the playing lamp during a play.
  3. While the left-right button (→) is held, JOG axis 1 to the right. When it is released the claw stops and can no longer move left-right.
  4. Then, while the depth button (↑) is held, JOG axis 2 toward the back. Each button can be pressed only once, left-right first, then depth.
  5. When the depth button is released, automatically: lower the claw (axis 3 point 2) → close the claw → raise it (point 1) → move axes 1 and 2 above the drop hole (point 1) → open the claw.
  6. A prize that falls into the drop hole is detected by the photoelectric sensor in the chute. When it is detected, light the prize lamp for 3 seconds. Prizes that land in the outlet disappear.
  7. The play ends 1 second after the claw opens. Then wait for the next start.

Signal tower and emergency stop

  • Light the signal tower green while playing, yellow while waiting, and red during an emergency stop.
  • The emergency stop force-stops the three axes and keeps the sequence from advancing (the claw keeps its state). After releasing it, press Reset to resume from where it stopped.

I/O assignment

InputDescriptionOutputDescription
X0Start buttonY0Claw (air gripper) close
X1Left-right button (→)Y1Playing lamp
X2Depth button (↑)Y2Prize lamp
X3Emergency stop (stays ON when pressed)Y3Signal tower green
X4Reset buttonY4Signal tower yellow
X5 / X6Claw open / closedY5Signal tower red
X7Photoelectric sensor: prize won

The following points are registered for the three servo motors. Left-right and depth move by JOG, so after homing they stop automatically at the ends of the stroke (software limits).

AxisPoint No.Position [mm]Speed [mm/s]Acceleration [mm/s²]Description
Axis 1 Left-right10200800Above the drop hole
Axis 2 Depth10150600Above the drop hole
Axis 3 Up-down10120500Raised end
2150120500Lowered end (claw tips 5 mm above the floor)

The relays used to control each of the three axes are as follows. Operation enable, forced stop, and operable are shared by all axes.

While a JOG forward / JOG reverse relay is ON, the axis moves that way at a constant speed; when it turns OFF the axis decelerates and stops (this works even before homing). As with point positioning, the unit must be operable, the servo ready, and the axis not in error.

Name (all axes)DirectionRelay
Operation enableOutputR0
Forced stopOutputR2
OperableInputR6600
NameDirectionAxis 1 Left-rightAxis 2 DepthAxis 3 Up-down
Servo ONOutputR305R705R1105
Servo readyInputR6905R7305R7705
Homing requestOutputR310R710R1110
Homing completeInputR6910R7310R7710
Positioning startOutputR200R600R1000
Positioning start acknowledgedInputR6800R7200R7600
Axis busyInputR6903R7303R7703
Positioning completeInputR6802R7202R7602
Positioning complete clearOutputR202R602R1002
Axis errorInputR6900R7300R7700
Axis error clearOutputR300R700R1100
JOG forwardOutputR206R606R1006
JOG reverseOutputR207R607R1007

Target behavior (video)

Approach

In earlier problems, point operation moved the axes to "fixed positions". In a crane game the player decides where the arm goes, so the ladder uses JOG operation, which moves an axis only while a button is held. The flow is "standby → left/right JOG → front/back JOG → lower → grab → raise → move above the chute → release". Only the first two steps are controlled by the player; the rest is the same automatic point-operation sequence as in problems 13 and 14.

Axes and points

AxisHow it movesPoints
Axis 1 Left/rightJOG (R206 forward) / point operationP1 above the chute (0 mm)
Axis 2 Front/backJOG (R606 forward) / point operationP1 above the chute (0 mm)
Axis 3 Up/downPoint operationP1 raised end / P2 lowered end

A JOG forward relay moves the axis forward at a constant speed only while it is ON, and the axis decelerates and stops when it turns OFF. It is not a rising-edge command like positioning start, so passing the button ON/OFF straight to the relay is enough to move the axis.

Process table (steps)

StepDescriptionCondition to advanceMain outputs
MR0PreparingR6600 ready, servo ready on 3 axes-
MR1HomingHoming complete on 3 axesR310/R710/R1110 ON
MR2StandbyX0 Start-
MR3Left/right JOGFalling edge of X1 (button released)R206 ON while X1
MR4Front/back JOGFalling edge of X2 (button released)R606 ON while X2
MR5LoweringAxis 3 start acknowledged and positioning completeAxis 3 → P2
MR6Close the armX5 open end OFF and T0 0.5 sY0 SET
MR7RaisingAxis 3 start acknowledged and positioning completeAxis 3 → P1
MR8Move above the chuteAxes 1 and 2 start acknowledged and positioning completeAxes 1 and 2 → P1
MR9Open the armX5 open end and T1 1 s → MR2Y0 RES

Based on this approach, try writing the ladder yourself first.
In the simulator, you can create the wiring and ladder and actually run the 3D equipment model.

Try it in the simulator
Show the sample ladder and explanation(click to open)

Devices used

DeviceComment
Inputs
X0Start
X1Left/right button (→)
X2Front/back button (↑)
X3Emergency stop
X4Reset
X5Arm open
X7Photoelectric prize won
Outputs
Y0Arm close
Y1Play lamp
Y2Prize lamp
Y3Tower light green
Y4Tower light yellow
Y5Tower light red
Internal relays
MR0Preparing
MR1Homing
MR2Standby
MR3Left/right JOG
MR4Front/back JOG
MR5Lowering
MR6Close the arm
MR7Raising
MR8Move above the chute
MR9Open the arm
MR20Prize won
MR30Playing
MR52Emergency stop active
Timers
T0Arm close wait
T1Arm open wait
T2Prize lamp on time
Positioning unit
R0Operation enable
R2Forced stop
R200Axis 1 Positioning start
R206Axis 1 JOG forward
R300Axis 1 Axis error clear
R305Axis 1 Servo ON
R310Axis 1 Homing request
R600Axis 2 Positioning start
R606Axis 2 JOG forward
R700Axis 2 Axis error clear
R705Axis 2 Servo ON
R710Axis 2 Homing request
R1000Axis 3 Positioning start
R1100Axis 3 Axis error clear
R1105Axis 3 Servo ON
R1110Axis 3 Homing request
R6600Ready
R6800Axis 1 Positioning start acknowledged
R6802Axis 1 Positioning complete
R6905Axis 1 Servo ready
R6910Axis 1 Homing complete
R7200Axis 2 Positioning start acknowledged
R7202Axis 2 Positioning complete
R7305Axis 2 Servo ready
R7310Axis 2 Homing complete
R7600Axis 3 Positioning start acknowledged
R7602Axis 3 Positioning complete
R7705Axis 3 Servo ready
R7710Axis 3 Homing complete
Special relays
CR2002Always ON
CR2008One pulse ON at start

Ladder explanation

The row numbers in the figures match the row numbers in the simulator's ladder window.

1InitializationRows 001–006

  • Row 002: CR2008 (one pulse at start) SETs the first step MR0 (preparing).
  • Rows 003–006: always ON, output operation enable R0 and servo ON for the 3 axes (R305/R705/R1105).

2Emergency stop and resetRows 007–013

  • Row 008: the emergency stop X3 SETs MR52 (emergency stop active)
  • Row 009: while the emergency stop is pressed, forced stop R2 turns ON and stops the 3 axes.
  • Rows 010–012: the reset button X4 clears the axis errors of the 3 axes
  • Row 013: when the reset button is released (LDF), RES MR52 if the emergency stop has been released

The transitions, JOG, and positioning start all have an N.C. contact of MR52, so during an emergency stop the axes do not move and the process does not advance. The arm Y0 does not, so a prize being held is not dropped.

3HomingRows 014–021

  • Rows 015–016: while preparing, if the unit is ready (R6600) and all 3 axes are servo ready, go to homing. In this problem homing starts as soon as the PLC is put in RUN (it does not wait for the Start button).
  • Rows 017–018: when all 3 axes have completed homing, go to standby MR2
  • Rows 019–021: during the homing step, turn ON the homing requests of the 3 axes

At the origin (0 mm on all 3 axes), the arm is directly above the chute at the raised end.

4StandbyRows 022–024

If Start X0 is pressed during standby MR2, go to left/right JOG MR3. After each play, the sequence comes back to this MR2.

5Left/right and front/back JOGRows 025–032

  • Row 026: in the left/right JOG step MR3, turn ON axis 1 JOG forward R206 only while the left/right button X1 is held
  • Rows 027–028: on the falling edge of X1 (LDF, the moment the button is released), go to front/back JOG MR4
  • Rows 030–032: in the same way, turn ON axis 2 JOG forward R606 only while X2 is held, and go to lowering MR5 when it is released

The JOG outputs use "step AND button", so once the step has moved on, pressing the same button no longer moves the axis. The rule "left/right then front/back, once each" is achieved just by the order of the steps.

The key is using LDF X1 as the transition condition, not LD X1 (while held). With LD X1, the step would advance the moment the button is pressed, and there would be no chance to JOG.

6Grab: lower → close the arm → raiseRows 033–039

  • MR5→MR6: axis 3 has reached the lowered end (P2) (R7600 and R7602)
  • MR6→MR7: when the arm open end X5 turns OFF and 0.5 s (T0) has passed since the close command, raise
  • MR7→MR8: axis 3 is back at the raised end (P1)

The arm is not confirmed with the closed end X6 because the claws stop against the prize and do not reach the closed end when they grab it (problem 7). To advance whether the arm grabbed a prize or missed, the condition is "left the open end AND a set time has passed".

7Return: move above the chute → open the armRows 040–044

  • MR8→MR9: both axis 1 and axis 2 have arrived above the chute (P1)
  • MR9→MR2: when the arm open end X5 turns ON and 1 s (T1) has passed since the open command, return to standby MR2 and end the play

Axes 1 and 2 move in the same step, so the arm returns to the chute in a straight diagonal line. Waiting 1 s after opening gives the prize time to fall.

8Point operation: axis 3 up/down, axes 1 and 2Rows 045–054

  • Rows 046–047: set the axis 3 point to P2 (lowered end) in lowering MR5 and P1 (raised end) in raising MR7
  • Rows 048–049: during these two steps, turn ON axis 3 positioning start R1000
  • Rows 051–054: in MR8, set the axis 1 and axis 2 points to P1 (above the chute) and turn ON positioning start R200 and R600

Wherever the JOG left the arm, point operation brings it back to P1 (0 mm) precisely. The program uses "JOG for positions the player decides" and "point operation for returning to a fixed position".

9Arm (air chuck)Rows 055–059

  • Rows 056–057: SET arm close Y0 in MR6 and count 0.5 s with T0
  • Rows 058–059: RES Y0 in MR9 and count 1 s with T1

Because SET/RES is used, the arm stays closed while it rises and moves.

10Prize lampRows 060–063

  • Row 061: SET MR20 (prize won) on the rising edge (LDP) of photoelectric sensor X7
  • Rows 062–063: count 3 s with T2 while MR20 is ON, then RES MR20

A prize passes the sensor in an instant, so lighting the lamp with LD X7 would turn it off right away. SETting MR20 on the rising edge and RESetting it with a timer "stretches a momentary signal into a fixed lighting time".

This circuit is independent of the play steps, so it detects a prize whenever it falls.

11Lamps and tower lightsRows 064–076

  • Rows 065–071: MR30 (playing) is ON while any of MR3 to MR9 is ON
  • Row 072: play lamp Y1 = MR30
  • Row 073: prize lamp Y2 = MR20
  • Rows 074–076: tower lights are green Y3 = playing, yellow Y4 = not playing (standby), red Y5 = emergency stop. Green and yellow have an N.C. contact of MR52, so only red lights during an emergency stop.

For a state that spans several steps, such as "playing", make one internal relay with the steps in parallel; then it can be reused by several outputs such as lamps.

The sample wiring and ladder data can be downloaded fromGitHuband loaded with "Load wiring" and "Load ladder" in the simulator.

Key points

  • A JOG relay is a "level" command that moves the axis only while it is ON; positioning start is a "rising-edge" command. Even on the same positioning unit, each relay may accept commands differently.
  • Catch "the moment a button is pressed" with LDP, "the moment it is released" with LDF, and "while it is held" with LD. Choose according to which moment you want as the condition.
  • Moving freely with JOG and then returning to a fixed position with point operation is a common combination (for example when setting up or aligning a machine).