提高LED灯响应速度
This commit is contained in:
@@ -44,6 +44,7 @@ class LedCommand(Node):
|
||||
self.driver = TM512AC_RS485_Driver(port='/dev/ttyUSB0', num_ic=5)
|
||||
self.cur_color='green'
|
||||
self.cur_val=5
|
||||
self.update=0
|
||||
self.get_logger().info("led_dev_node will start....")
|
||||
self.th1=threading.Thread(target=self.com_task)
|
||||
self.th1.start()
|
||||
@@ -51,7 +52,9 @@ class LedCommand(Node):
|
||||
def com_task(self):
|
||||
idx=0
|
||||
while True:
|
||||
self.led_blink(self.cur_color,self.cur_val)
|
||||
#self.led_blink(self.cur_color,self.cur_val)
|
||||
self.all_color(self.cur_color, -self.cur_val)
|
||||
self.all_color(self.cur_color, self.cur_val)
|
||||
def wait_task(self):
|
||||
self.th1.join()
|
||||
def all_color(self,rgb_data,xnum):
|
||||
@@ -84,7 +87,10 @@ class LedCommand(Node):
|
||||
rgb = [val, val, val,0] * num_ic
|
||||
print(rgb)
|
||||
self.driver.send_frame(rgb)
|
||||
time.sleep(0.02)
|
||||
if self.update==1:
|
||||
self.update=0
|
||||
break
|
||||
time.sleep(0.01)
|
||||
def led_blink(self,color,val):
|
||||
self.all_color(color, -val)
|
||||
self.all_color(color, val)
|
||||
@@ -94,6 +100,7 @@ class LedCommand(Node):
|
||||
cmd,val=xcmd.split(',')
|
||||
self.cur_color=cmd
|
||||
self.cur_val=int(val)
|
||||
self.update=1
|
||||
###self.led_blink(cmd,int(val))
|
||||
def main():
|
||||
rclpy.init()
|
||||
|
||||
Reference in New Issue
Block a user