adafruit / adafruit/Adafruit_CircuitPython_NeoPixel

ROS2: memory leak

Open
#149 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
329
Forks
96
PR merge metrics
No merged PRs in 30d

Description

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
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:

```python
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:
https://github.com/jgarff/rpi_ws281x/issues/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!

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with test_nodes/ledSub.py at self.pixels.show(), then compare the ROS2 node with the standalone script that reportedly works. Read adafruit_blinka/microcontroller/bcm283x/neopixel.py and neopixel_write.py, and reproduce the mailbox error; done means identifying and documenting a confirmed fix or incompatibility for ROS2 Foxy on the Raspberry Pi.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, raspberry-pi
Domain
embedded-iot
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.