update josn's formation
This commit is contained in:
@@ -37,10 +37,7 @@ class fake_formation():
|
||||
self.velocity = 100
|
||||
self.type = 3
|
||||
|
||||
# test json
|
||||
class state():
|
||||
def __init__(self):
|
||||
self.mode = "test"
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -106,7 +103,6 @@ if __name__ == '__main__':
|
||||
#test proto
|
||||
gps = fakeGps()
|
||||
hdg = fake_hdg()
|
||||
state = state()
|
||||
formation = fake_formation()
|
||||
while True:
|
||||
#test proto
|
||||
@@ -116,13 +112,15 @@ if __name__ == '__main__':
|
||||
gps.altitude = 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)
|
||||
time.sleep(0.25)
|
||||
'''
|
||||
utils.Proto_msg_from_ros.callBack_gps(gps)
|
||||
utils.Proto_msg_from_ros.callBack_compass_hdg(hdg)
|
||||
utils.Proto_msg_from_ros.callBack_fly_formation(formation)
|
||||
time.sleep(0.25)
|
||||
#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_state(state)
|
||||
# time.sleep(1)
|
||||
'''
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"serialize":{"json":0.35475994200533023,"proto":1.0138140169947292},"deserializ":{"json":0.41626033899956383,"proto":0.4805599120008992}}
|
||||
{"serialize":{"json":0.3499185360000183,"proto":1.0996155560000034},"deserializ":{"json":0.4229183979999789,"proto":0.5481516849999934}}
|
||||
@@ -1,5 +1,5 @@
|
||||
MQTT_ROS:
|
||||
msg_format: Proto
|
||||
msg_format: Json
|
||||
MQTTClientNamePub: Drone650Pub
|
||||
MQTTClientNameSub: Drone650Sub
|
||||
host: 192.168.50.117
|
||||
|
||||
@@ -58,11 +58,13 @@ class Json_msg_to_ros:
|
||||
@classmethod
|
||||
def ros_pub(cls, dataJson):
|
||||
if dataJson.topic == cls.Flight_Information_topicToMqtt:
|
||||
cls.publisher_Flight_Information.publish(dataJson.payload.decode('utf-8'))
|
||||
cls.rate.sleep()
|
||||
print(dataJson.payload.decode('utf-8'))
|
||||
# cls.publisher_Flight_Information.publish(dataJson.payload.decode('utf-8'))
|
||||
# cls.rate.sleep()
|
||||
elif dataJson.topic == cls.Fly_Formation_topicToMqtt:
|
||||
cls.publisher_Fly_Formation.publish(dataJson.payload.decode('utf-8'))
|
||||
cls.rate.sleep()
|
||||
print(dataJson.payload.decode('utf-8'))
|
||||
# cls.publisher_Fly_Formation.publish(dataJson.payload.decode('utf-8'))
|
||||
# cls.rate.sleep()
|
||||
else:
|
||||
print("topic not found")
|
||||
|
||||
|
||||
@@ -54,7 +54,8 @@ class Proto_msg_from_ros:
|
||||
|
||||
|
||||
class Json_msg_from_ros:
|
||||
data = {}
|
||||
GPS_Data = {}
|
||||
Formation_Data = {}
|
||||
client = None
|
||||
#Mqtt
|
||||
Flight_Information_topicToMqtt = None
|
||||
@@ -82,26 +83,26 @@ class Json_msg_from_ros:
|
||||
lon=int(GPS.longitude*10000000)
|
||||
alt=int(GPS.altitude*100)
|
||||
dataGpsUpdate = {"lat": lat, "lon": lon, "alt": alt}
|
||||
cls.data.update(dataGpsUpdate)
|
||||
cls.GPS_Data.update(dataGpsUpdate)
|
||||
# dataJsonFormate = orjson.dumps(data)
|
||||
# mqtt_Pub(message=dataJsonFormate)
|
||||
# print ('lat:'+lat+'\n'+'lon:'+lon+'\n')
|
||||
|
||||
@classmethod
|
||||
def callBack_state(cls, state):
|
||||
mode = state.mode
|
||||
dataGpsUpdate = {"mode": mode}
|
||||
cls.data.update(dataGpsUpdate)
|
||||
|
||||
@classmethod
|
||||
def callBack_compass_hdg(cls, Compass):
|
||||
heading = int(Compass.data*100)
|
||||
dataGpsUpdate = {"heading": heading}
|
||||
cls.data.update(dataGpsUpdate)
|
||||
dataJsonFormate = orjson.dumps(cls.data).decode("UTF-8")
|
||||
cls.GPS_Data.update(dataGpsUpdate)
|
||||
dataJsonFormate = orjson.dumps(cls.GPS_Data)
|
||||
cls.mqtt_Pub(message=dataJsonFormate, topics=cls.Flight_Information_topicToMqtt)
|
||||
|
||||
|
||||
@classmethod
|
||||
def callBack_fly_formation(cls, Formation):
|
||||
Formation_data = {"velocity": Formation.velocity, "type": Formation.type}
|
||||
flyFormationMsg = orjson.dumps(Formation_data)
|
||||
cls.mqtt_Pub(message=flyFormationMsg, topics=cls.Fly_Formation_topicToMqtt, qos=cls.Fly_Formation_topicToMqtt_QOS)
|
||||
|
||||
@classmethod
|
||||
def mqtt_Pub(cls, message:str, topics:str, waitForAck:bool=False, qos:int=0):
|
||||
mid = cls.client.publish(topics, message, qos)[1]
|
||||
|
||||
Reference in New Issue
Block a user