Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ROS2: memory leak #149

Open
keukenrol opened this issue Apr 22, 2023 · 2 comments
Open

ROS2: memory leak #149

keukenrol opened this issue Apr 22, 2023 · 2 comments

Comments

@keukenrol
Copy link

keukenrol commented Apr 22, 2023

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!

@ealaimo18
Copy link

Did you ever solve this? Running into the same issue now running that library on Ros2.

@keukenrol
Copy link
Author

Did you ever solve this? Running into the same issue now running that library on Ros2.

No, we ended up running the script separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants