Skip to content

ROS2: memory leak #149

@keukenrol

Description

@keukenrol

Hi

when implementing the neopixel library in a ROS2 node, I get the following error:

Failed to create mailbox device
: Operation not permitted
Traceback (most recent call last):
  File "/home/ubuntu/turtlebot3_ws/src/install/test_nodes/lib/test_nodes/ledSub", line 11, in <module>
    load_entry_point('test-nodes==0.0.0', 'console_scripts', 'ledSub')()
  File "/home/ubuntu/turtlebot3_ws/src/install/test_nodes/lib/python3.8/site-packages/test_nodes/ledSub.py", line 82, in main
    pixel_node = pixelNode()
  File "/home/ubuntu/turtlebot3_ws/src/install/test_nodes/lib/python3.8/site-packages/test_nodes/ledSub.py", line 44, in __init__
    self.pixels.show()
  File "/usr/local/lib/python3.8/dist-packages/adafruit_pixelbuf.py", line 205, in show
    return self._transmit(self._post_brightness_buffer)
  File "/usr/local/lib/python3.8/dist-packages/neopixel.py", line 180, in _transmit
    neopixel_write(self.pin, buffer)
  File "/usr/local/lib/python3.8/dist-packages/neopixel_write.py", line 38, in neopixel_write
    return _neopixel.neopixel_write(gpio, buf)
  File "/usr/local/lib/python3.8/dist-packages/adafruit_blinka/microcontroller/bcm283x/neopixel.py", line 82, in neopixel_write
    raise RuntimeError(
RuntimeError: ws2811_init failed with code -9 (Failed to create mailbox device)
swig/python detected a memory leak of type 'ws2811_t *', no destructor found.

This is my node:

class pixelNode(Node):

    def __init__(self, pixel_pin = board.D18, num_pixels = 34, ORDER = neopixel.GRB):       
        super().__init__('pixel_node')

        self.subscription = self.create_subscription(
            String,
            'bot_state',
            self.listener_callback,
            10)
        self.subscription  # prevent unused variable warning
        self.pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.5, auto_write=False, pixel_order=ORDER)
        self.pixels.fill((255, 0, 0))
        self.pixels.show()
        
        # blue led blinker
        timer_period = 0.5  # 2Hz
        self.timer = self.create_timer(timer_period, self.timer_callback)

    def listener_callback(self, msg):        
        if msg.data == 'driving':
            self.pixels.fill((255, 255, 255))
            self.get_logger().info('LEDS: DRIVING')
            
        elif msg.data == 'detected':
            self.pixels.fill((255, 127, 0))
            self.get_logger().info('LEDS: DETECTED')
            
        elif msg.data == 'shoot':
            self.pixels.fill((255, 0, 255))
            self.get_logger().info('LEDS: SHOOT')

        else:
            self.pixels.fill((255, 0, 0))
            self.get_logger().info('LEDS: UNKNOWN')
        
        self.pixels.show()
        
    def timer_callback(self):
        global bluestate
        
        if bluestate == 0:
            GPIO.output(25, GPIO.HIGH)
            bluestate = 1
        else:
            GPIO.output(25, GPIO.LOW)
            bluestate = 0

This is triggered when calling the function self.pixels.show(), which is inside a subscriber callback of a node.
Any idea how to solve?

ROS2 Foxy Ubuntu 20.04
Raspberry Pi 4
Similar issues:
jgarff/rpi_ws281x#263
If I use the neopixel functions in a generic python script no issue arises. Thus the combination of ROS2 with neopixel is the issue
Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions