Led Ring

This file presents the different functions, enums, topics and objects available with the Led Ring API

Led Ring - Command functions

This section reference all existing functions to control the Led Ring, which are several parameterizable animations. All functions are accessible via an instance of the class NiryoRobot

robot = NiryoRobot(<robot_ip_address>)

robot.led_ring.solid([255, 255, 255])
...

List of functions:

class LedRing(client)[source]

LedRing robot functions

Example:

ros_instance = NiryoRos("10.10.10.10") # Hotspot
led_ring_interface = LedRing(ros_instance)
Parameters

client (NiryoRos) – Niryo ROS client

status[source]

Returns the Led Ring status client which can be used synchronously or asynchronously to obtain the current Led Ring status (cf LedRingStatusObject).

Examples:

# Get last value
led_ring.status()
led_ring.status.value

# Subscribe a callback
def status_callback(msg):
    print([msg.r, msg.g, msg.b])

led_ring.status.subscribe(status_callback)
led_ring.status.unsubscribe()
Returns

Led Ring status topic.

Return type

NiryoTopic

get_status()[source]

Get Led Ring status.

Example:

status = led_ring.get_status()
print(status.animation)
Returns

Object with the current led ring mode, the animation played and the color used

Return type

LedRingStatusObject

solid(color)[source]

Set the whole Led Ring to a fixed color.

Example:

led_ring.solid([15, 50, 255])
Parameters

color (list[float]) – Led color in a list of size 3[R, G, B]. RGB channels from 0 to 255.

Return type

None

turn_off()[source]

Turn off all LEDs

Example:

led_ring.turn_off()
Return type

None

flash(color, period=0, iterations=0, wait=False, callback=None, timeout=None)[source]

Flashes a color according to a frequency. The frequency is equal to 1 / period.

Examples:

# Synchronous use
led_ring.flash([15, 50, 255])  # Non-blocking
led_ring.flash([15, 50, 255], 1, 100, False)  # Non-blocking
led_ring.flash([15, 50, 255], iterations=20, wait=True)  # Wait the end

frequency = 20  # Hz
total_duration = 10 # seconds
led_ring.flash([15, 50, 255], 1./frequency, total_duration * frequency , True)

# Asynchronous use
def led_ring_callback(result):
    if result["status"] < RobotErrors.SUCCESS.value:
        print("Failed")
    else:
        print("Completed with success")

led_ring.flash([15, 50, 255], iterations=20, wait=True, callback=calibration_callback)
Parameters
  • color (list[float]) – Led color in a list of size 3[R, G, B]. RGB channels from 0 to 255.

  • period (float) – Execution time for a pattern in seconds. If 0, the default time will be used.

  • iterations (int) – Number of consecutive flashes. If 0, the Led Ring flashes endlessly.

  • wait (bool) – The service wait for the animation to finish all iterations or not to answer. If iterations is 0, the service answers immediately.

  • callback (function) – Callback invoked on successful execution.

  • timeout (float) – Timeout for the operation, in seconds. Only used if blocking.

Return type

None

alternate(color_list, period=0, iterations=0, wait=False, callback=None, timeout=None)[source]

Several colors are alternated one after the other.

Examples:

# Synchronous use
color_list = [
    [15, 50, 255],
    [255, 0, 0],
    [0, 255, 0],
]

led_ring.alternate(color_list) # Non-blocking
led_ring.alternate(color_list, 1, 100, False) # Non-blocking
led_ring.alternate(color_list, iterations=20, wait=True) # Blocking

# Asynchronous use
def led_ring_callback(result):
    if result["status"] < RobotErrors.SUCCESS.value:
        print("Failed")
    else:
        print("Completed with success")

led_ring.alternate(color_list, iterations=20, wait=True, callback=calibration_callback)
Parameters
  • color_list (list[list[float]]) – Led color list of lists of size 3[R, G, B]. RGB channels from 0 to 255.

  • period (float) – Execution time for a pattern in seconds. If 0, the default time will be used.

  • iterations (int) – Number of consecutive alternations. If 0, the Led Ring alternates endlessly.

  • wait (bool) – The service wait for the animation to finish all iterations or not to answer. If iterations is 0, the service answers immediately.

  • callback (function) – Callback invoked on successful execution.

  • timeout (float) – Timeout for the operation, in seconds. Only used if blocking.

Return type

None

chase(color, period=0, iterations=0, wait=False, callback=None, timeout=None)[source]

Movie theater light style chaser animation.

Examples:

# Synchronous use
led_ring.chase([15, 50, 255]) # Non-blocking
led_ring.chase([15, 50, 255], 1, 100, False) # Non-blocking
led_ring.chase([15, 50, 255], iterations=20, wait=True) # Blocking

# Asynchronous use
def led_ring_callback(result):
    if result["status"] < RobotErrors.SUCCESS.value:
        print("Failed")
    else:
        print("Completed with success")

led_ring.chase([15, 50, 255], iterations=20, wait=True, callback=calibration_callback)
Parameters
  • color (list[float]) – Led color in a list of size 3[R, G, B]. RGB channels from 0 to 255.

  • period (float) – Execution time for a pattern in seconds. If 0, the default time will be used.

  • iterations (int) – Number of consecutive chase. If 0, the animation continues endlessly. One chase just lights one Led every 3 LEDs.

  • wait (bool) – The service wait for the animation to finish all iterations or not to answer. If iterations is 0, the service answers immediately.

  • callback (function) – Callback invoked on successful execution.

  • timeout (float) – Timeout for the operation, in seconds. Only used if blocking.

Return type

None

wipe(color, period=0, wait=False, callback=None, timeout=None)[source]

Wipe a color across the Led Ring, light a Led at a time.

Examples:

# Synchronous use
robot.wipe([15, 50, 255])  # Non-blocking
led_ring.wipe([15, 50, 255], 1, False)  # Non-blocking
led_ring.wipe([15, 50, 255], wait=True)  # Blocking

# Asynchronous use
def led_ring_callback(result):
    if result["status"] < RobotErrors.SUCCESS.value:
        print("Failed")
    else:
        print("Completed with success")

led_ring.wipe([15, 50, 255], wait=True, callback=calibration_callback)
Parameters
  • color (list[float]) – Led color in a list of size 3[R, G, B]. RGB channels from 0 to 255.

  • period (float) – Execution time for a pattern in seconds. If 0, the default time will be used.

  • wait (bool) – The service wait for the animation to finish or not to answer.

  • callback (function) – Callback invoked on successful execution.

  • timeout (float) – Timeout for the operation, in seconds. Only used if blocking.

Return type

None

go_up(color, period=0, iterations=0, wait=False, callback=None, timeout=None)[source]

LEDs turn on like a loading circle, and are then all turned off at once.

Examples:

# Synchronous use
led_ring.go_up([15, 50, 255])  # Non-blocking
led_ring.go_up([15, 50, 255], 1, 100, False)  # Non-blocking
led_ring.go_up([15, 50, 255], iterations=20, wait=True)  # Blocking

# Asynchronous use
def led_ring_callback(result):
    if result["status"] < RobotErrors.SUCCESS.value:
        print("Failed")
    else:
        print("Completed with success")

led_ring.go_up([15, 50, 255], period=2, iterations=20, wait=True, callback=calibration_callback)
Parameters
  • color (list[float]) – Led color in a list of size 3[R, G, B]. RGB channels from 0 to 255.

  • period (float) – Execution time for a pattern in seconds. If 0, the default time will be used.

  • iterations (int) – Number of consecutive turns around the Led Ring. If 0, the animation continues endlessly.

  • wait (bool) – The service wait for the animation to finish or not to answer. If iterations is 0, the service answers immediately.

  • callback (function) – Callback invoked on successful execution.

  • timeout (float) – Timeout for the operation, in seconds. Only used if blocking.

Return type

None

go_up_down(color, period=0, iterations=0, wait=False, callback=None, timeout=None)[source]

LEDs turn on like a loading circle, and are turned off the same way.

Examples:

# Synchronous use
led_ring.go_up_down([15, 50, 255])  # Non-blocking
led_ring.go_up_down([15, 50, 255], 1, 100, False)  # Non-blocking
led_ring.go_up_down([15, 50, 255], iterations=20, wait=True)  # Blocking

# Asynchronous use
def led_ring_callback(result):
    if result["status"] < RobotErrors.SUCCESS.value:
        print("Failed")
    else:
        print("Completed with success")

led_ring.go_up_down([15, 50, 255], period=2, iterations=20, wait=True, callback=calibration_callback)
Parameters
  • color (list[float]) – Led color in a list of size 3[R, G, B]. RGB channels from 0 to 255.

  • period (float) – Execution time for a pattern in seconds. If 0, the default time will be used.

  • iterations (int) – Number of consecutive turns around the Led Ring. If 0, the animation continues endlessly.

  • wait (bool) – The service wait for the animation to finish or not to answer. If iterations is 0, the service answers immediately.

  • callback (function) – Callback invoked on successful execution.

  • timeout (float) – Timeout for the operation, in seconds. Only used if blocking.

Return type

None

breath(color, period=0, iterations=0, wait=False, callback=None, timeout=None)[source]

Variation of the light intensity of the LED ring, similar to human breathing.

Examples:

# Synchronous use
led_ring.breath([15, 50, 255])  # Non-blocking
led_ring.breath([15, 50, 255], 1, 100, False)  # Non-blocking
led_ring.breath([15, 50, 255], iterations=20, wait=True)  # Blocking

# Asynchronous use
def led_ring_callback(result):
    if result["status"] < RobotErrors.SUCCESS.value:
        print("Failed")
    else:
        print("Completed with success")

led_ring.breath([15, 50, 255], period=2, iterations=20, wait=True,
    callback=calibration_callback)
Parameters
  • color (list[float]) – Led color in a list of size 3[R, G, B]. RGB channels from 0 to 255.

  • period (float) – Execution time for a pattern in seconds. If 0, the default time will be used.

  • iterations (int) – Number of consecutive turns around the Led Ring. If 0, the animation continues endlessly.

  • wait (bool) – The service wait for the animation to finish or not to answer. If iterations is 0, the service answers immediately.

  • callback (function) – Callback invoked on successful execution.

  • timeout (float) – Timeout for the operation, in seconds. Only used if blocking.

Return type

None

snake(color, period=0, iterations=0, wait=False, callback=None, timeout=None)[source]

A small coloured snake (certainly a python :D ) runs around the LED ring.

Examples:

# Synchronous use
led_ring.snake([15, 50, 255]) # Non-blocking
led_ring.snake([15, 50, 255], 1, 100, True) # Blocking

# Asynchronous use
def led_ring_callback(result):
    if result["status"] < RobotErrors.SUCCESS.value:
        print("Failed")
    else:
        print("Completed with success")

led_ring.snake([15, 50, 255], period=2, iterations=20, wait=True, callback=calibration_callback)
Parameters
  • color (list[float]) – Led color in a list of size 3[R, G, B]. RGB channels from 0 to 255.

  • period (float) – Execution time for a pattern in seconds. If 0, the default duration will be used.

  • iterations (int) – Number of consecutive turns around the Led Ring. If 0, the animation continues endlessly.

  • wait (bool) – The service wait for the animation to finish or not to answer. If iterations is 0, the service answers immediately.

  • callback (function) – Callback invoked on successful execution.

  • timeout (float) – Timeout for the operation, in seconds. Only used if blocking.

Return type

None

rainbow(period=0, iterations=0, wait=False, callback=None, timeout=None)[source]

Draw rainbow that fades across all LEDs at once.

Examples:

# Synchronous use
led_ring.rainbow()  # Non-blocking
led_ring.rainbow(5, 2, True)  # Blocking
led_ring.rainbow(wait=True)  # Blocking

# Asynchronous use
def led_ring_callback(result):
    if result["status"] < RobotErrors.SUCCESS.value:
        print("Failed")
    else:
        print("Completed with success")

led_ring.rainbow(period=2, iterations=20, wait=True, callback=calibration_callback)
Parameters
  • period (float) – Execution time for a pattern in seconds. If 0, the default time will be used.

  • iterations (int) – Number of consecutive rainbows. If 0, the animation continues endlessly.

  • wait (bool) – The service wait for the animation to finish or not to answer. If iterations is 0, the service answers immediately.

  • callback (function) – Callback invoked on successful execution.

  • timeout (float) – Timeout for the operation, in seconds. Only used if blocking.

Return type

None

rainbow_cycle(period=0, iterations=0, wait=False, callback=None, timeout=None)[source]

Draw rainbow that uniformly distributes itself across all LEDs.

Examples:

# Synchronous use
led_ring.rainbow_cycle()
led_ring.rainbow_cycle(5, 2, True)
led_ring.rainbow_cycle(wait=True)

# Asynchronous use
def led_ring_callback(result):
    if result["status"] < RobotErrors.SUCCESS.value:
        print("Failed")
    else:
        print("Completed with success")

led_ring.rainbow_cycle(period=2, iterations=20, wait=True, callback=calibration_callback)
Parameters
  • period (float) – Execution time for a pattern in seconds. If 0, the default time will be used.

  • iterations (int) – Number of consecutive rainbow cycles. If 0, the animation continues endlessly.

  • wait (bool) – The service wait for the animation to finish or not to answer. If iterations is 0, the service answers immediately.

  • callback (function) – Callback invoked on successful execution.

  • timeout (float) – Timeout for the operation, in seconds. Only used if blocking.

Return type

None

rainbow_chase(period=0, iterations=0, wait=False, callback=None, timeout=None)[source]

Rainbow chase animation, like the led_ring_chase method.

Examples:

# Synchronous use
led_ring.rainbow_chase()
led_ring.rainbow_chase(5, 2, True)
led_ring.rainbow_chase(wait=True)

# Asynchronous use
def led_ring_callback(result):
    if result["status"] < RobotErrors.SUCCESS.value:
        print("Failed")
    else:
        print("Completed with success")

led_ring.rainbow_chase(period=2, iterations=20, wait=True, callback=calibration_callback)
Parameters
  • period (float) – Execution time for a pattern in seconds. If 0, the default time will be used.

  • iterations (int) – Number of consecutive rainbow cycles. If 0, the animation continues endlessly.

  • wait (bool) – The service wait for the animation to finish or not to answer. If iterations is 0, the service answers immediately.

  • callback (function) – Callback invoked on successful execution.

  • timeout (float) – Timeout for the operation, in seconds. Only used if blocking.

Return type

None

custom(led_colors)[source]

Sends a colour command to all LEDs of the LED ring. The function expects a list of colours for the 30 LEDs of the robot.

Example:

led_list = [[i / 30. * 255 , 0, 255 - i / 30.] for i in range(30)]
led_ring.custom(led_list)

run_flag = True

def french_flag_moving():
    colors = []
    colors += [[255, 255, 255] for _ in range(2)]
    colors += [[0, 0, 255] for _ in range(11)]
    colors += [[255, 255, 255] for _ in range(4)]
    colors += [[255, 0, 0] for _ in range(11)]
    colors += [[255, 255, 255] for _ in range(2)]

    rate = 10
    while run_flag:
        for i in range(len(colors)):
            led_ring.custom(colors[i:] + colors[:i])
            time.sleep(1/rate)
            if not run_flag:
                return

french_flag_moving()
Parameters

led_colors (list[list[float]]) – List of size 30 of led color in a list of size 3[R, G, B]. RGB channels from 0 to 255.

Return type

None

set_led_color(led_id, color)[source]

Lights up an LED in one colour. RGB colour between 0 and 255.

Example:

robot.set_led_color(5, [15, 50, 255])
Parameters
  • led_id (int) – Id of the led: between 0 and 29

  • color (list[float]) – Led color in a list of size 3[R, G, B]. RGB channels from 0 to 255.

Return type

None

Led Ring - Niryo Topics

The use of these functions is explained in the NiryoTopics, section. They allow the acquisition of data in real time by callbacks or by direct call.

Led Ring’s Niryo Topics

Name

Function

Return type

/status

status

LedRingStatusObject

Led Ring - Enums

List of enums:

class AnimationMode(value)[source]

Enumeration of animations available for the user to control the Led Ring

NONE = -1
UNKNOWN = 0
SOLID = 1
FLASHING = 2
ALTERNATE = 3
CHASE = 4
COLOR_WIPE = 5
RAINBOW = 6
RAINBOW_CYLE = 7
RAINBOW_CHASE = 8
GO_UP = 9
GO_UP_AND_DOWN = 10
BREATH = 11
SNAKE = 12
CUSTOM = 13
class LedMode(value)[source]

Enumeration of available Led Mode

NONE = -1
UNKNOWN = 0
ROBOT_STATUS = 1
USER = 2

Led Ring - Objects

class LedRingStatusObject[source]

Object used to store Led Ring status