Skip to content

get_digital_input

Runs at once Any mode Open to every client

Return whether one of the control box's isolated inputs is on. The robot reads every input once per control tick (4 ms) and takes a change only after five equal reads in a row (20 ms), so a short glitch is ignored. The call returns the level it read last. Inputs 1, 2 and 3 are on terminals 11, 10 and 9 of the control box. An input with no signal on it reads False.

Each call asks the robot and waits for its answer. To wait for an input, call it in a loop.

Syntax

robot.get_digital_input(pin)

Arguments

Name Type Default Description
pin int required The input: 1, 2 or 3. A number with a fraction is cut to a whole number first.

Returns

bool

True while the input is on, False while it is off.

Examples

robot.get_digital_input(1)
import time
deadline = time.monotonic() + 10
while not robot.get_digital_input(2) and time.monotonic() < deadline:
    time.sleep(0.05)
Usage restrictions 3 codes

This command runs at once; it is not queued. The robot accepts it in any mode and state, from every client.

It answers with one of these codes when it does not carry the command out:

  • [6003] Invalid arguments — no pin was given (only a raw client can send that)
  • [6008] Invalid I/O pin — pin is not 1, 2 or 3
  • [6025] RTI not running or not answering — the control loop (RTI) has not run for over 0.5 s, or the robot is in flashing mode: the level would be old

In Python, a code above raises CommandRejected; its number is the code. The call raises:

  • CommandRejected: The robot refused it: pin is not 1, 2 or 3, or its control loop is not running.
  • RobotTimeout: The robot did not answer within 5 s.
  • RobotConnectionError: The client is not connected.
  • ValueError: pin cannot be read as a whole number, for example "one". Nothing is sent.
  • TypeError: pin is None or another type that is no number. Nothing is sent.

If the connection drops while the call waits for the robot's answer, it raises CommandRejected with the code CONNECTION_LOST (DISCONNECTED after disconnect()); while it waits for the robot's status, RobotConnectionError.

Like every immediate command, it also answers BAD_ARGS when a raw client sends a value the robot cannot read at all, and INTERNAL when it fails inside the robot.

Protocol

A client that does not use robotclient sends this over the TCP command protocol (port 29000) for the example above:

{"id": "c1", "cmd": "get_digital_input", "args": [1]}

See also