In AnyLogic, how do I return a crane to automatic mode (idle state) after executing a CraneProgram?

Viewed 70

AnyLogic (version 8.7.5) OverheadCrane is working well in automatic mode. I use the moveByCrane logic blocks to move other agents from one location to another. But I'd like to modify the behaviour just a little. After the crane has finished its move, I'd like it to lift the hook up out of the way.

There is a facility for operating cranes manually: the CraneProgram. In the crane's "On bridge state change" action, I use the following code to lift the hook up.

traceln("crane.onStateChange() "+newState);
if (newState == OverheadCraneBridgeState.IDLE) {
    traceln("  Raising hook");
    CraneProgram cp = new CraneProgram();
    cp.moveHook(8, METER);
    bridge.moveByProgram(cp);
}

This works nicely, except that the crane proceeds through MOVING_UNLOADED state and ends up in the WAITING state, and in that state it will not automatically work on any agents that are subsequently available to be moved.

The documentation describes WAITING as:

The bridge is seized by the agent, but this agent is currently moving through any blocks that are not SeizeCrane, MoveByCrane, or ReleaseCrane blocks. Also includes cases where the bridge in manual mode remains at target, executes a programmed delay command, or has finished the program and waits for the next command.

Is there a way to tell the crane that there will be no "next command", and it should switch from manual mode back to automatic mode?

enter image description here

1 Answers

Advice from AnyLogic support, received with thanks:

In this case I advise you to use “moveTo(…)” function of a bridge instead of using “CraneProgram” class. This function has “remainsAsTarget” argument, that allows you to use the required behavior when it reaches the destination.

Essence of solution:

if (newState == OverheadCraneBridgeState.IDLE && !movedHookUp) {
    Point newPosition = new Point(endNode.getX(),endNode.getY(),endNode.getZ()+toPixels(8, LengthUnits.METER))
    bridge.moveTo(newPoint, //destination
                  8,        // safety height
                  false);   // remainsAtTarget - see documentation
    movedHookUp = true;
}

See moveTo function in the bridge documentation.

Related