try useing thread with each callback

protobuf
RangeOfGlitching 3 years ago
parent 02bff86b0e
commit 81cb1c9043

@ -4,6 +4,7 @@ import time
import proto.flight_information_pb2 as flight_information_pb2
import proto.flyformatioln_pb2 as flyformatioln_pb2
import google.protobuf.json_format as json_format
import threading
class Proto_msg_to_ros:
#Protobuf
@ -50,15 +51,29 @@ class Json_msg_to_ros:
@classmethod
def Drone550_on_message_Flight_Information(cls, client, userdata, msg):
cls.Drone550_publisher_Flight_Information.publish(msg.payload.decode("UTF-8"))
cls.rate.sleep()
# define a function for handling the data from mqtt
def thread_function():
cls.Drone550_publisher_Flight_Information.publish(msg.payload.decode("UTF-8"))
cls.rate.sleep()
# create a new thread to process the data
t = threading.Thread(target=thread_function)
t.start()
@classmethod
def Drone380_on_message_Flight_Information(cls, client, userdata, msg):
cls.Drone380_publisher_Flight_Information.publish(msg.payload.decode("UTF-8"))
cls.rate.sleep()
def thread_function():
cls.Drone380_publisher_Flight_Information.publish(msg.payload.decode("UTF-8"))
cls.rate.sleep()
t = threading.Thread(target=thread_function)
t.start()
@classmethod
def Drone650_on_message_Flight_Information(cls, client, userdata, msg):
cls.Drone650_publisher_Flight_Information.publish(msg.payload.decode("UTF-8"))
cls.rate.sleep()
def thread_function():
cls.Drone650_publisher_Flight_Information.publish(msg.payload.decode("UTF-8"))
cls.rate.sleep()
t = threading.Thread(target=thread_function)
t.start()

Loading…
Cancel
Save