diff --git a/class_model/src/mqttPubMain.py b/class_model/src/mqttPubMain.py
index a40a234..29ab218 100755
--- a/class_model/src/mqttPubMain.py
+++ b/class_model/src/mqttPubMain.py
@@ -42,11 +42,11 @@ def init_dataFormat(cfg:utils.Read_PUB_Config):
rospy.Subscriber(ros_namespace+'/mavros/global_position/global', NavSatFix, utils.Json_msg_from_ros.callBack_gps)
rospy.Subscriber(ros_namespace+'/mavros/global_position/compass_hdg', Float64, utils.Json_msg_from_ros.callBack_compass_hdg)
else:
- logging.debug("msg_format not found")
+ logger.debug("msg_format not found")
def on_connect(self, userdata, flags, rc):
- logger.info("Connected with result code " + str(rc))
+ logger.debug("Connected with result code " + str(rc))
def on_publish(self, userdata, mid):
logger.debug("pub success")
@@ -63,22 +63,24 @@ if __name__ == '__main__':
client = utils.MQTTClient(cfg.MQTTClientNamePub)
# set log
- log_format = "%(asctime)s - %(levelname)s - %(message)s"
- formatter = logging.Formatter(log_format)
+ stream_log_format = "%(asctime)s - %(levelname)s - %(message)s"
+ file_log_format = "%(message)s"
+ file_formatter = logging.Formatter(file_log_format)
+ stream_formatter = logging.Formatter(stream_log_format)
stream_handler = logging.StreamHandler()
- stream_handler.setFormatter(formatter)
+ stream_handler.setFormatter(stream_formatter)
stream_handler.setLevel(logging.DEBUG)
file_handler = logging.FileHandler(cfg.logFileName)
- file_handler.setFormatter(formatter)
+ file_handler.setFormatter(file_formatter)
file_handler.setLevel(logging.INFO)
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logger.addHandler(file_handler)
logger.addHandler(stream_handler)
- logger.info(cfg)
+ logger.debug(cfg)
# Mqtt
client.on_connect = on_connect
@@ -98,6 +100,6 @@ if __name__ == '__main__':
rospy.spin()
except BaseException as error:
client.disconnect()
- logger.info("End of program")
+ logger.debug("End of program")
sys.exit()
\ No newline at end of file
diff --git a/class_model/src/uavlinkPubMain.py b/class_model/src/uavlinkPubMain.py
index 87f2e44..cb1b956 100644
--- a/class_model/src/uavlinkPubMain.py
+++ b/class_model/src/uavlinkPubMain.py
@@ -20,7 +20,7 @@ from sensor_msgs.msg import Range
from geometry_msgs.msg import Vector3
-def init_dataFormat(cfg:Read_PUB_Config):
+def init_dataFormat(cfg):
Proto_msg_from_ros.sel = serial.Serial(cfg.ttyport, cfg.baudrate, serial.EIGHTBITS, serial.PARITY_NONE, serial.STOPBITS_ONE)
Proto_msg_from_ros.flight_information_msg = flight_information_pb2.flight_information_message()
Proto_msg_from_ros.rate = rospy.Rate(5)
diff --git a/class_model/src/uavlinkSubMain.py b/class_model/src/uavlinkSubMain.py
index 4d95113..d0a19a4 100644
--- a/class_model/src/uavlinkSubMain.py
+++ b/class_model/src/uavlinkSubMain.py
@@ -23,7 +23,7 @@ from geometry_msgs.msg import Vector3
from class_model.msg import FlightInformation
-def init_dataFormat(cfg:Read_SUB_Config):
+def init_dataFormat(cfg):
Proto_msg_to_ros.flight_information_msg = flight_information_pb2.flight_information_message()
Proto_msg_to_ros.rate = rospy.Rate(10)
Proto_msg_to_ros.publisher_Flight_Information = rospy.Publisher(cfg.Dron550_ROStopicName_Flight_Information,FlightInformation,queue_size=10)
diff --git a/class_model/src/utils/.idea/.gitignore b/class_model/src/utils/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/class_model/src/utils/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/class_model/src/utils/.idea/inspectionProfiles/Project_Default.xml b/class_model/src/utils/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..e55ddbf
--- /dev/null
+++ b/class_model/src/utils/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,104 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/class_model/src/utils/.idea/inspectionProfiles/profiles_settings.xml b/class_model/src/utils/.idea/inspectionProfiles/profiles_settings.xml
new file mode 100644
index 0000000..105ce2d
--- /dev/null
+++ b/class_model/src/utils/.idea/inspectionProfiles/profiles_settings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/class_model/src/utils/.idea/misc.xml b/class_model/src/utils/.idea/misc.xml
new file mode 100644
index 0000000..c3334de
--- /dev/null
+++ b/class_model/src/utils/.idea/misc.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/class_model/src/utils/.idea/modules.xml b/class_model/src/utils/.idea/modules.xml
new file mode 100644
index 0000000..2213c52
--- /dev/null
+++ b/class_model/src/utils/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/class_model/src/utils/.idea/utils.iml b/class_model/src/utils/.idea/utils.iml
new file mode 100644
index 0000000..d0876a7
--- /dev/null
+++ b/class_model/src/utils/.idea/utils.iml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/class_model/src/utils/.idea/vcs.xml b/class_model/src/utils/.idea/vcs.xml
new file mode 100644
index 0000000..c2365ab
--- /dev/null
+++ b/class_model/src/utils/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/class_model/src/utils/mqttConfig_PUB.yml b/class_model/src/utils/mqttConfig_PUB.yml
index 5a084f3..ec13eba 100644
--- a/class_model/src/utils/mqttConfig_PUB.yml
+++ b/class_model/src/utils/mqttConfig_PUB.yml
@@ -19,5 +19,5 @@ ROS:
ROStopicName_Flight_Information: Dron650_Flight_Information_reciver
ROStopicName_Fly_Formation: Fly_Formation_reciver
LOG:
- logFileName: pub.log
+ logFileName: GPSDrone1.log
UAVLINK: "None"
\ No newline at end of file
diff --git a/class_model/src/utils/protoJson_mqtt_sub_data_from_ros.py b/class_model/src/utils/protoJson_mqtt_sub_data_from_ros.py
index 6953eb5..73012ca 100644
--- a/class_model/src/utils/protoJson_mqtt_sub_data_from_ros.py
+++ b/class_model/src/utils/protoJson_mqtt_sub_data_from_ros.py
@@ -1,5 +1,8 @@
import orjson
import time
+import logging
+
+logger = logging.getLogger(__name__)
class Proto_msg_from_ros:
#Protobuf
@@ -88,14 +91,17 @@ class Json_msg_from_ros:
dataGpsUpdate = {"heading": heading}
cls.GPS_Data.update(dataGpsUpdate)
dataJsonFormate = orjson.dumps(cls.GPS_Data)
+ cls.log()
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)
- print(flyFormationMsg)
+
+
@classmethod
def mqtt_Pub(cls, message:str, topics:str, waitForAck:bool=False, qos:int=0):
mid = cls.client.publish(topics, message, qos)[1]
@@ -104,3 +110,7 @@ class Json_msg_from_ros:
print("wait for ack")
time.sleep(0.25)
cls.client.topic_ack.remove(mid)
+ @classmethod
+ def log(cls):
+ unit = 1e7
+ logger.info("{},{},{},{}".format(cls.GPS_Data["lat"]/1e7, cls.GPS_Data["lon"]/1e7, cls.GPS_Data["alt"]/100, cls.GPS_Data["heading"]/100))
\ No newline at end of file
diff --git a/class_model/src/utils/proto_uavlink_sub_data_from_ros.py b/class_model/src/utils/proto_uavlink_sub_data_from_ros.py
index f8afdb6..74600f9 100644
--- a/class_model/src/utils/proto_uavlink_sub_data_from_ros.py
+++ b/class_model/src/utils/proto_uavlink_sub_data_from_ros.py
@@ -2,7 +2,7 @@ import orjson
import time
import logging
-logger = logging.getLogger("__UAVLINKSUBPUB__")
+logger = logging.getLogger(__name__)
class Proto_msg_from_ros:
#Protobuf
@@ -33,6 +33,7 @@ class Proto_msg_from_ros:
cls.flight_information_msg.heading = Compass.data
flightInformationMsg = cls.flight_information_msg.SerializeToString()
cls.sel.write(cls.f2_code + flightInformationMsg + cls.noEcho_code)
+ logger.info()
cls.rate.sleep()
diff --git a/class_model/src/utils/readConfig.py b/class_model/src/utils/readConfig.py
index 54386da..936ee20 100644
--- a/class_model/src/utils/readConfig.py
+++ b/class_model/src/utils/readConfig.py
@@ -21,13 +21,13 @@ class Config:
optval=ecfg[opt]
#verify parameter type
if type(optval) != self.options[opts][opt][0]:
- raise Exception("Parameter {} has wrong type".format(self.opt))
+ raise Exception("Parameter {} has wrong type".format(opt))
#create attributes on the fly
setattr(self,opt,optval)
else:
if self.options[opts][opt][1]:
- raise Exception("Missing mandatory parameter {}".format(self.opt))
+ raise Exception("Missing mandatory parameter {}".format(opt))
else:
setattr(self,opt,None)
@@ -99,7 +99,6 @@ class Read_SUB_Config(Config):
"ROSClientNameSub": (str,True),
"Dron550_ROStopicName_Flight_Information": (str,False),
"Dron380_ROStopicName_Flight_Information": (str,False),
- "Dron380_ROStopicName_Flight_Information": (str,False),
"Dron650_ROStopicName_Flight_Information": (str,False),
"Dron888_ROStopicName_Flight_Information": (str,False),
"Dron555_ROStopicName_Flight_Information": (str,False),
@@ -112,10 +111,6 @@ class Read_SUB_Config(Config):
"uav_id": (str,False),
"baudrate": (int,False),
"ttyport": (str,False)}}
- self.setAttribute()
-
- def __str__(self):
- return super().__str__()
class Read_CMD_Config(Config):
def setAttribute(self):
@@ -146,7 +141,7 @@ class Read_CMD_Config(Config):
return super().__str__()
if __name__ == "__main__":
- cfg=Read_CMD_Config("mqttConfig_CMD.yml")
+ cfg=Read_CMD_Config("uavlinkConfig_SUB.yml")
print(cfg)