Niryo robot led ring
This package is in charge of managing Ned robot’s led ring. It is composed of one node, receiving commands and the current robot status, and publishing LED Ring states.
It belongs to the ROS namespace: /niryo_robot_led_ring
.
The LED Ring is composed of 30 WS2811 RGB LEDs, controlled by using the rpi_ws281x library.
The LED Ring can either be controlled in:
Robot status mode: the LED ring is displaying the status of the robot.
User mode: the user can control the LED Ring with the several methods implemented:
Robot status mode
When displaying the robot status, the LED Ring has several states which represent different modes and error status.
Refer to the following table. The node subscribes to the ROS topic /niryo_robot_status/robot_status
, published by
the robot status package.
Animation and color |
Description |
Troubleshooting |
---|---|---|
White Breath |
Robot is booting |
N/A |
Blue Chase |
Calibration is needed |
Press the Custom button, or launch a calibration |
Blue Snake |
Calibration in progress |
N/A |
Blue Breath |
Free Motion enabled |
N/A |
3 Yellow Flashing |
Calibration start |
N/A |
Green Breath |
Free Motion disabled, torque enabled |
N/A |
Solid Green |
Program in progress |
N/A |
Green Chase |
Program paused |
Long press on the TOP button to cancel the program, short press to resume |
Orange Breath |
Program execution error |
Launch a new action to clear this state |
Flashing Orange |
Collision |
Launch a new action to clear this state |
Solid Orange |
Joint out of bounds |
Switch to Free Motion mode to bring the joints within limits. |
1 Purple Flashing |
New connection form Niryo Studio |
N/A |
2 Purple Flashing |
Save a robot positions from the ‘Save’ button |
N/A |
Flashing Red |
Motor error / Raspberry overheating |
Please check the error on Niryo Studio. |
Solid Red |
ROS Crash |
Please restart the robot. |
User mode
Several animations are implemented to allow the user different ways to control the LED Ring. Refer to the following
table. The node receives commands through the service /niryo_robot_led_ring/set_user_animation
.
Important
The robot must be in autonomous mode in order to allow the user to control the LED Ring.
Led ring API functions
Led ring ROS wrapper
In order to control the robot more easily than calling each topics & services one by one, a Python ROS Wrapper has been built on top of ROS.
For instance, a script turning on the LED Ring via Python ROS Wrapper will look like:
from niryo_robot_led_ring.api import LedRingRosWrapper
led_ring = LedRingRosWrapper()
led_ring.solid(color=[255, 255, 255])
API list
- class niryo_robot_led_ring.api.led_ring_ros_wrapper.LedRingRosWrapper(hardware_version='ned2', service_timeout=1)
Bases:
object
- alternate(color_list, period=0, iterations=0, wait=False)
Several colors are alternated one after the other.
Examples:
from std_msgs.msg import ColorRGBA color_list = [ ColorRGBA(r=15, g=50, b=255), [255, 0, 0], [0, 255, 0], ] led_ring.alternate(color_list) led_ring.alternate(color_list, 1, 100, True) led_ring.alternate(color_list, iterations=20, wait=True)
- Parameters:
color_list (list[list[float] or ColorRGBA]) – Led color list of lists of size 3[R, G, B] or ColorRGBA objects. 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.
- Returns:
status, message
- Return type:
(int, str)
- property animation_mode
Get the current animation mode of the Led Ring. :return: The current animation mode. One of LedRingAnimation values. :rtype: int
- breath(color, period=0, iterations=0, wait=False)
Variation of the light intensity of the LED ring, similar to human breathing.
Examples:
from std_msgs.msg import ColorRGBA led_ring.breath(ColorRGBA(r=15, g=50, b=255)) led_ring.breath([15, 50, 255], 1, 100, True) led_ring.breath(ColorRGBA(r=15, g=50, b=255), iterations=20, wait=True)
- Parameters:
color (list[float] or ColorRGBA) – Led color in a list of size 3[R, G, B] or in an ColorRGBA object. 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.
- Returns:
status, message
- Return type:
(int, str)
- chase(color, period=0, iterations=0, wait=False)
Movie theater light style chaser animation.
Examples:
from std_msgs.msg import ColorRGBA led_ring.chase(ColorRGBA(r=15, g=50, b=255)) led_ring.chase([15, 50, 255], 1, 100, True) led_ring.chase(ColorRGBA(r=15, g=50, b=255), iterations=20, wait=True)
- Parameters:
color (list or ColorRGBA) – Led color in a list of size 3[R, G, B] or in an ColorRGBA object. 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.
- Returns:
status, message
- Return type:
(int, str)
- property color
Get the current color of the Led Ring. :return: The current color of the Led Ring in RGB format. :rtype: list(int, int, int)
- custom(led_colors)
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)
- Parameters:
led_colors (list[list[float] or ColorRGBA]) – List of size 30 of led color in a list of size 3[R, G, B] or in an ColorRGBA object. RGB channels from 0 to 255.
- Returns:
status, message
- Return type:
(int, str)
- flashing(color, period=0, iterations=0, wait=False)
Flashes a color according to a frequency. The frequency is equal to 1 / period.
Examples:
from std_msgs.msg import ColorRGBA led_ring.flashing([15, 50, 255]) led_ring.flashing([15, 50, 255], 1, 100, True) led_ring.flashing([15, 50, 255], iterations=20, wait=True) frequency = 20 # Hz total_duration = 10 # seconds led_ring.flashing(ColorRGBA(r=15, g=50, b=255), 1./frequency, total_duration * frequency , True)
- Parameters:
color (list[float] or ColorRGBA) – Led color in a list of size 3[R, G, B] or in an ColorRGBA object. 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.
- Returns:
status, message
- Return type:
(int, str)
- go_up(color, period=0, iterations=0, wait=False)
LEDs turn on like a loading circle, and are then all turned off at once.
Examples:
from std_msgs.msg import ColorRGBA led_ring.go_up(ColorRGBA(r=15, g=50, b=255)) led_ring.go_up([15, 50, 255], 1, 100, True) led_ring.go_up(ColorRGBA(r=15, g=50, b=255), iterations=20, wait=True)
- Parameters:
color (list[float] or ColorRGBA) – Led color in a list of size 3[R, G, B] or in an ColorRGBA object. 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.
- Returns:
status, message
- Return type:
(int, str)
- go_up_down(color, period=0, iterations=0, wait=False)
LEDs turn on like a loading circle, and are turned off the same way.
Examples:
from std_msgs.msg import ColorRGBA led_ring.go_up_down(ColorRGBA(r=15, g=50, b=255)) led_ring.go_up_down([15, 50, 255], 1, 100, True) led_ring.go_up_down(ColorRGBA(r=15, g=50, b=255), iterations=20, wait=True)
- Parameters:
color (list[float] or ColorRGBA) – Led color in a list of size 3[R, G, B] or in an ColorRGBA object. 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.
- Returns:
status, message
- Return type:
(int, str)
- property hardware_version
- property is_autonomous
Return whether the led ring is in autonomous mode or not. :return: True if the led ring is in autonomous mode, False otherwise. :rtype: bool
- rainbow(period=0, iterations=0, wait=False)
Draws rainbow that fades across all LEDs at once.
Examples:
led_ring.rainbow() led_ring.rainbow(5, 2, True) led_ring.rainbow(wait=True)
- 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.
- Returns:
status, message
- Return type:
(int, str)
- rainbow_chase(period=0, iterations=0, wait=False)
Rainbow chase animation, like the led_ring_chase method.
Examples:
led_ring.rainbow_chase() led_ring.rainbow_chase(5, 2, True) led_ring.rainbow_chase(wait=True)
- 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.
- Returns:
status, message
- Return type:
(int, str)
- rainbow_cycle(period=0, iterations=0, wait=False)
Draws rainbow that uniformly distributes itself across all LEDs.
Examples:
led_ring.rainbow_cycle() led_ring.rainbow_cycle(5, 2, True) led_ring.rainbow_cycle(wait=True)
- 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.
- Returns:
status, message
- Return type:
(int, str)
- set_led_color(led_id, color)
Lights up an LED in one colour. RGB colour between 0 and 255.
Example:
from std_msgs.msg import ColorRGBA led_ring.set_led_color(5, [15, 50, 255]) led_ring.set_led_color(5, ColorRGBA(r=15, g=50, b=255))
- Parameters:
led_id (int) – Id of the led: between 0 and 29
color (list[float] or ColorRGBA) – Led color in a list of size 3[R, G, B] or in an ColorRGBA object. RGB channels from 0 to 255.
- Returns:
status, message
- Return type:
(int, str)
- set_user_animation(animation_mode, colors, period=0, iterations=0, wait_end=False)
Low level function to set an animation on the Led Ring. Prefer using the high level functions.
- Parameters:
animation_mode (int) – Animation mode to set. One of LedRingAnimation values.
colors (list[list[float] or ColorRGBA]) – List of colors for the animation. 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 animations. If 0, the animation continues endlessly.
wait_end (bool) – Wait for the end of the animation before exiting the function.
- Returns:
status, message
- Return type:
(int, str)
- snake(color, period=0, iterations=0, wait=False)
A small coloured snake (certainly a python :D ) runs around the LED ring.
Examples:
from std_msgs.msg import ColorRGBA led_ring.snake(ColorRGBA(r=15, g=50, b=255)) led_ring.snake([15, 50, 255], 1, 100, True) led_ring.snake(ColorRGBA(r=15, g=50, b=255), iterations=20, wait=True)
- Parameters:
color (list[float] or ColorRGBA) – Led color in a list of size 3[R, G, B] or in an ColorRGBA object. 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.
- Returns:
status, message
- Return type:
(int, str)
- solid(color, wait=False)
Sets the whole Led Ring to a fixed color.
Example:
from std_msgs.msg import ColorRGBA led_ring.solid([15, 50, 255]) led_ring.solid(ColorRGBA(r=15, g=50, b=255), True)
- Parameters:
color (list[float] or ColorRGBA) – Led color in a list of size 3[R, G, B] or in an ColorRGBA object. RGB channels from 0 to 255.
wait (bool) – The service wait for the animation to finish or not to answer. For this method, the action is quickly done, so waiting doesn’t take a lot of time.
- Returns:
status, message
- Return type:
(int, str)
- turn_off(wait=False)
Turns off all Leds
Example:
led_ring.turn_off()
- Parameters:
wait (bool) – The service wait for the animation to finish or not to answer. For this method, the action is quickly done, so waiting doesn’t take a lot of time.
- Returns:
status, message
- Return type:
(int, str)
- wipe(color, period=0, wait=False)
Wipes a color across the LED Ring, light a LED at a time.
Examples:
from std_msgs.msg import ColorRGBA led_ring.wipe(ColorRGBA(r=15, g=50, b=255)) led_ring.wipe([15, 50, 255], 1, True) led_ring.wipe(ColorRGBA(r=15, g=50, b=255), wait=True)
- Parameters:
color (list[float] or ColorRGBA) – Led color in a list of size 3[R, G, B] or in an ColorRGBA object. 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.
- Returns:
status, message
- Return type:
(int, str)
- exception niryo_robot_led_ring.api.led_ring_ros_wrapper.LedRingRosWrapperException
Bases:
Exception
- niryo_robot_led_ring.api.led_ring_ros_wrapper.check_ned2_version(func)
Decorator that check the robot version
Package Documentation
ROS topics
Publishers
Topic Name |
Type |
Description |
---|---|---|
/niryo_robot_led_ring/led_ring_status |
Publish the status of the LED ring |
|
/rosout |
N/A |
|
/visualization_marker_array |
Publish Led ring visual markers for Rviz |
Subscribers
Topic Name |
Type |
Description |
---|---|---|
/niryo_robot/blockly/save_current_point |
Save current robot pose in blockly block when user is in Blockly page in Niyro Studio |
|
/niryo_robot/hotspot_button_state |
niryo_robot_rpi/HotspotButtonStatus |
Publish the state of the hotspot button |
/niryo_robot_status/robot_status |
niryo_robot_status/RobotStatus |
Publish the robot, log, overheating and joints out of bounds status |
/niryo_robot_user_interface/niryo_studio_connection |
niryo_robot_user_interface/ConnectionState |
Notify that Niryo Studio is connected to the robot |
ROS Services
Service Name |
Type |
Description |
---|---|---|
/niryo_robot_led_ring/get_loggers |
roscpp/GetLoggers |
N/A |
/niryo_robot_led_ring/set_led_color |
Set the color of the LED ring |
|
/niryo_robot_led_ring/set_logger_level |
roscpp/SetLoggerLevel |
N/A |
/niryo_robot_led_ring/set_user_animation |
Set the user animation of the LED ring |
ROS Parameters
Parameter Name |
Default value |
Simulation value |
Unit |
Description |
---|---|---|---|---|
/niryo_robot_led_ring/default_alternate_period |
1 |
N/A |
seconds |
Default period of the alternate animation |
/niryo_robot_led_ring/default_breath_period |
4 |
N/A |
seconds |
Default period of the breath animation |
/niryo_robot_led_ring/default_chase_period |
4 |
N/A |
seconds |
Default period of the chase animation |
/niryo_robot_led_ring/default_colorwipe_period |
5 |
N/A |
seconds |
Default period of the colorwipe animation |
/niryo_robot_led_ring/default_flashing_period |
0.25 |
N/A |
seconds |
Default period of the flashing animation |
/niryo_robot_led_ring/default_goup_period |
5 |
N/A |
seconds |
Default period of the go up animation |
/niryo_robot_led_ring/default_goupanddown_period |
5 |
N/A |
seconds |
Default period of the go up and down animation |
/niryo_robot_led_ring/default_rainbow_period |
5 |
N/A |
seconds |
Default period of the rainbow animation |
/niryo_robot_led_ring/default_rainbowchase_period |
5 |
N/A |
seconds |
Default period of the rainbow chase animation |
/niryo_robot_led_ring/default_rainbowcycle_period |
5 |
N/A |
seconds |
Default period of the rainbow cycle animation |
/niryo_robot_led_ring/default_snake_period |
1.5 |
N/A |
seconds |
Default period of the snake animation |
/niryo_robot_led_ring/enable_led_ring_bcm_pin |
27 |
N/A |
int |
BCM pin number on the Raspberry Pi used for the LED ring |
/niryo_robot_led_ring/led_brightness |
255 |
N/A |
int |
Brightness of the LED ring (0 - 255) |
/niryo_robot_led_ring/led_channel |
1 |
N/A |
int |
Channel of the LED ring |
/niryo_robot_led_ring/led_count |
30 |
N/A |
int |
Number of LEDs in the ring |
/niryo_robot_led_ring/led_dma |
10 |
N/A |
int |
Direct Access Memory channel used for generating signal |
/niryo_robot_led_ring/led_freq_hs |
800000 |
N/A |
Hz |
Frequency of the LED signal |
/niryo_robot_led_ring/led_invert |
True |
N/A |
bool |
True to invert the signal (when using NPN transistor level shift) |
/niryo_robot_led_ring/led_offset |
8 |
N/A |
int |
Offset of the LED signal |
/niryo_robot_led_ring/led_pin |
13 |
N/A |
int |
Pin number on the Raspberry Pi used for the LED ring |
/niryo_robot_led_ring/led_ring_markers_publish_rate |
5 |
N/A |
Hz |
Rate at which the LED ring markers are published |
/niryo_robot_led_ring/log_level |
INFO |
N/A |
N/A |
N/A |
/niryo_robot_led_ring/simulation_led_mesh_path |
package://niryo_robot_description/meshes/led_ring/led.dae |
N/A |
string |
Path to the mesh file of the LED ring in simulation |
/niryo_robot_led_ring/simulation_led_ring_markers_publish_rate |
20 |
N/A |
Hz |
Rate at which the LED ring markers are published in simulation |
/niryo_robot_led_ring/simulation_mode |
True |
N/A |
bool |
Whether the LED ring node is in simulation mode or not |
/niryo_robot_led_ring/use_mesh |
False |
N/A |
bool |
Whether the LED ring should be displayed as a mesh in Rviz or not |
ROS Action
Namespace: None