create sub/pub config respective
This commit is contained in:
@@ -28,14 +28,14 @@ class fakeGps():
|
||||
self.longitude = 20
|
||||
self.altitude = 30
|
||||
|
||||
class fake_hdg():
|
||||
def __init__(self):
|
||||
self.data = 40
|
||||
# class fake_hdg():
|
||||
# def __init__(self):
|
||||
# self.data = 40
|
||||
|
||||
class fake_formation():
|
||||
def __init__(self):
|
||||
self.velocity = 100
|
||||
self.type = 3
|
||||
# class fake_formation():
|
||||
# def __init__(self):
|
||||
# self.velocity = 100
|
||||
# self.type = 3
|
||||
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ def on_publish(self, userdata, mid):
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Read Config
|
||||
FilePath = os.path.join(os.path.dirname(__file__),"utils","mqttConfig.yml")
|
||||
FilePath = os.path.join(os.path.dirname(__file__),"utils","mqttConfig_PUB.yml")
|
||||
cfg = utils.MQTT_ROS_Config(FilePath)
|
||||
client = utils.MQTTClient(cfg.MQTTClientNamePub)
|
||||
print(cfg)
|
||||
@@ -102,20 +102,20 @@ if __name__ == '__main__':
|
||||
|
||||
#test proto
|
||||
gps = fakeGps()
|
||||
hdg = fake_hdg()
|
||||
formation = fake_formation()
|
||||
# hdg = fake_hdg()
|
||||
# formation = fake_formation()
|
||||
while True:
|
||||
#test proto
|
||||
|
||||
gps.latitude = random.uniform(0, 10)
|
||||
gps.longitude = random.uniform(0, 10)
|
||||
gps.altitude = random.uniform(0, 10)
|
||||
hdg.data = random.uniform(0, 10)
|
||||
formation.velocity = random.uniform(0, 10)
|
||||
# hdg.data = random.uniform(0, 10)
|
||||
# formation.velocity = random.uniform(0, 10)
|
||||
# test json
|
||||
utils.Json_msg_from_ros.callBack_gps(gps)
|
||||
utils.Json_msg_from_ros.callBack_compass_hdg(hdg)
|
||||
utils.Json_msg_from_ros.callBack_fly_formation(formation)
|
||||
# utils.Json_msg_from_ros.callBack_compass_hdg(hdg)
|
||||
# utils.Json_msg_from_ros.callBack_fly_formation(formation)
|
||||
time.sleep(0.25)
|
||||
'''
|
||||
utils.Proto_msg_from_ros.callBack_gps(gps)
|
||||
|
||||
@@ -39,6 +39,7 @@ def init_dataFormat(cfg):
|
||||
|
||||
def on_connect(self, userdata, flags, rc):
|
||||
print("Connected with result code " + str(rc))
|
||||
print(cfg.Flight_Information_topicToMqtt)
|
||||
client.subscribe(cfg.Flight_Information_topicToMqtt)
|
||||
client.subscribe(cfg.Fly_Formation_topicToMqtt)
|
||||
|
||||
@@ -48,7 +49,7 @@ def on_publish(self, userdata, mid):
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Read Config
|
||||
FilePath = os.path.join(os.path.dirname(__file__),"utils","mqttConfig.yml")
|
||||
FilePath = os.path.join(os.path.dirname(__file__),"utils","mqttConfig_SUB.yml")
|
||||
# Read Config
|
||||
cfg = utils.MQTT_ROS_Config(FilePath)
|
||||
print(cfg)
|
||||
|
||||
+7
-7
@@ -1,21 +1,21 @@
|
||||
MQTT_ROS:
|
||||
msg_format: Json
|
||||
MQTTClientNamePub: Drone650Pub
|
||||
MQTTClientNameSub: Drone650Sub
|
||||
MQTTClientNamePub: Drone550Pub
|
||||
MQTTClientNameSub: Drone550Sub
|
||||
host: 192.168.50.117
|
||||
port: 1883
|
||||
keepalive: 60
|
||||
willTopic: CheckDoneConnect
|
||||
willTopicQOS: 1
|
||||
lwt: Drone650 Gone Offline
|
||||
lwt: Dron550 Gone Offline
|
||||
willRetain: False
|
||||
# Mqtt topic
|
||||
Flight_Information_topicToMqtt: drone/leader/Flight_Information
|
||||
Fly_Formation_topicToMqtt: drone/leader/Formation
|
||||
Flight_Information_topicToMqtt: Drone550/Flight_Information
|
||||
Fly_Formation_topicToMqtt: Drone550/Formation
|
||||
# Change formate qos
|
||||
Fly_Formation_topicToMqtt_QOS: 2
|
||||
#ROS
|
||||
ROSClientNamePub: Drone650Pub
|
||||
ROSClientNameSub: Drone650Sub
|
||||
ROSClientNamePub: Drone550Pub
|
||||
ROSClientNameSub: Drone550Sub
|
||||
ROStopicName_Flight_Information: Flight_Information_reciver
|
||||
ROStopicName_Fly_Formation: Fly_Formation_reciver
|
||||
@@ -0,0 +1,21 @@
|
||||
MQTT_ROS:
|
||||
msg_format: Json
|
||||
MQTTClientNamePub: Drone550Pub
|
||||
MQTTClientNameSub: Drone550Sub
|
||||
host: 192.168.50.117
|
||||
port: 1883
|
||||
keepalive: 60
|
||||
willTopic: CheckDoneConnect
|
||||
willTopicQOS: 1
|
||||
lwt: Dron550 Gone Offline
|
||||
willRetain: False
|
||||
# Mqtt topic
|
||||
Flight_Information_topicToMqtt: Drone550/Flight_Information
|
||||
Fly_Formation_topicToMqtt: Drone550/Formation
|
||||
# Change formate qos
|
||||
Fly_Formation_topicToMqtt_QOS: 2
|
||||
#ROS
|
||||
ROSClientNamePub: Drone550Pub
|
||||
ROSClientNameSub: Drone550Sub
|
||||
ROStopicName_Flight_Information: Flight_Information_reciver
|
||||
ROStopicName_Fly_Formation: Fly_Formation_reciver
|
||||
@@ -84,8 +84,8 @@ class Json_msg_from_ros:
|
||||
alt=int(GPS.altitude*100)
|
||||
dataGpsUpdate = {"lat": lat, "lon": lon, "alt": alt}
|
||||
cls.GPS_Data.update(dataGpsUpdate)
|
||||
# dataJsonFormate = orjson.dumps(data)
|
||||
# mqtt_Pub(message=dataJsonFormate)
|
||||
dataJsonFormate = orjson.dumps(cls.GPS_Data)
|
||||
cls.mqtt_Pub(message=dataJsonFormate, topics=cls.Flight_Information_topicToMqtt)
|
||||
# print ('lat:'+lat+'\n'+'lon:'+lon+'\n')
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user