Working nepixel driver!

master
Drew Bednar 3 years ago
parent ee167b0742
commit e5537a2609

@ -11,25 +11,21 @@ class NeopixelDriverNode:
"""ROS Node for controllering NeoPixels.""" """ROS Node for controllering NeoPixels."""
def __init__(self): def __init__(self):
self._msg = Neopixels() self._msg = Neopixels
self.pixel_count = rospy.get_param('/simple_example/pixel_count', 1) self.pixel_count = rospy.get_param('/simple_example/pixel_count', 1)
self.port = rospy.get_param('/simple_example/port', "/dev/ttyUSB0") self.port = rospy.get_param('/simple_example/port', "/dev/ttyUSB0")
self.serial = Serial(self.port, 115200, timeout=1) self.serial = Serial(self.port, 115200, timeout=1)
def listen(self): def listen(self):
<<<<<<< HEAD
rospy.init_node("light_ctrl", anonymous=True) rospy.init_node("light_ctrl", anonymous=True)
rospy.Subscriber("/neopixel", self._msg, self.neopixel_ctrl_callback) rospy.Subscriber("/neopixel", self._msg, self.neopixel_ctrl_callback)
=======
rospy.init_node("light_ctrl", anonymous=True, log_level=rospy.INFO)
rospy.Subscriber("/neopixel", Neopixels, self.neopixel_ctrl_callback)
>>>>>>> 37b2adbedcf87e091d5ebd6efde78e86c64171d8
rate = rospy.spin() rate = rospy.spin()
def neopixel_ctrl_callback(self, data): def neopixel_ctrl_callback(self, data):
rospy.loginfo(f"Recieved: {data}") rospy.loginfo(f"Recieved: {data}")
#import pdb;pdb.set_trace()
cmds = "" cmds = ""
for i, pixel in data.pixels: for i, pixel in enumerate(data.pixels):
cmds += f"{i},{pixel.r},{pixel.g},{pixel.b};" cmds += f"{i},{pixel.r},{pixel.g},{pixel.b};"
cmds += "\n" cmds += "\n"
rospy.loginfo(f"Sending to ESP32: {cmds}") rospy.loginfo(f"Sending to ESP32: {cmds}")

@ -33,7 +33,7 @@ def broadcaster():
while not rospy.is_shutdown(): while not rospy.is_shutdown():
neo_pixel = pick_color() neo_pixel = pick_color()
pub.publish(Neopixel(pixels=[neo_pixel])) pub.publish(Neopixels(pixels=[neo_pixel]))
rospy.sleep(2) rospy.sleep(2)

Loading…
Cancel
Save