Signals

Signals are mainly used for communication between processes or with external systems.

The system has 256 built-in signals, indexed from 0 to 255. Each signal can store a 32-bit integer value, ranging from -2147483648 to 2147483647.

After the system restarts, all signals are reset to 0.

Set Signal

  • Function name: Method set_signal under [Robot]
  • Parameters:
    1. index: [int] Signal index
    2. value: [int] Signal value to set
  • Return: None

Example Program

lebai:set_signal(0, 1)
JSON-RPC
// Request:
{ "jsonrpc": "2.0", "method": "set_signal", "params": [{"key": 0, "value": 0}], "id": 1 }
// Response:
{ "jsonrpc": "2.0", "result": {}, "id": 1 }

Set Multiple Signals

Batch set signals starting from the specified index.

  • Function name: Method set_signals under [Robot]
  • Parameters:
    1. index: [int] Signal starting index
    2. values: [list[int]] Signal values to set
  • Return: None

Example Program

lebai:set_signals(1, {1,2,3})
JSON-RPC
// Request:
{ "jsonrpc": "2.0", "method": "set_signals", "params": [{"key": 0, "values": [1, 2, 3]}], "id": 1 }
// Response:
{ "jsonrpc": "2.0", "result": {}, "id": 1 }

Get Signal

  • Function name: Method get_signal under [Robot]
  • Parameters:
    1. index: [int] Signal index
  • Return: [int] Value of the corresponding signal

Example Program

value = lebai:get_signal(0)
print(value)
JSON-RPC
// Request:
{ "jsonrpc": "2.0", "method": "get_signal", "params": [{"key": 0}], "id": 1 }
// Response:
{ "jsonrpc": "2.0", "result": {"value": 0}, "id": 1 }

Get Multiple Signals

Get multiple continuous signals starting from the specified index.

  • Function name: Method get_signals under [Robot]
  • Parameters:
    1. index: [int] Signal starting index
    2. len: [int] Number of signals to get
  • Return: [list[int]] Values of the continuous multiple signals

Example Program

values = lebai:get_signals(0, 3)
print(values)
JSON-RPC
// Request:
{ "jsonrpc": "2.0", "method": "get_signals", "params": [{"key": 0, "len": 3}], "id": 1 }
// Response:
{ "jsonrpc": "2.0", "result": {"values": [1, 2, 3]}, "id": 1 }

Wait for Signal Condition

Block wait for the specified signal to meet the condition, returning immediately after satisfaction.

  • Function name: Method wait_signal under [Robot]

  • Parameters:

    1. index: [int] Signal index
    2. value: [int] Value to compare
    3. relation: [Relation] Comparison operator, optional, default EQ equal
  • Return: None

    • relation values:
      • EQ Equal
      • NEQ Not equal
      • LT Less than
      • LTE Less than or equal
      • GT Greater than
      • GTE Greater than or equal

Example Program

lebai:wait_signal(0, 1, "EQ")
JSON-RPC
// Request:
{ "jsonrpc": "2.0", "method": "wait_signal", "params": [{"key": 0, "value": 1, "relation": "EQ"}], "id": 1 }
// Response:
{ "jsonrpc": "2.0", "result": {}, "id": 1 }

Increment Signal Value

Increment the signal value at the specified index. Be careful of the value range, as overflow may occur.

  • Function name: Method add_signal under [Robot]
  • Parameters:
    1. index: [int] Signal index
    2. value: [int] Value to increment, can be negative
  • Return: None

Example Program

value = lebai:get_signal(0)
lebai:add_signal(0, 10)
value = lebai:get_signal(0)
JSON-RPC
// Request:
{ "jsonrpc": "2.0", "method": "add_signal", "params": [{"key": 0, "value": 0}], "id": 1 }
// Response:
{ "jsonrpc": "2.0", "result": {}, "id": 1 }