|
|
|
@ -18,7 +18,7 @@ from sensor_msgs.msg import NavSatFix
|
|
|
|
from sensor_msgs.msg import Imu
|
|
|
|
from sensor_msgs.msg import Imu
|
|
|
|
from sensor_msgs.msg import Range
|
|
|
|
from sensor_msgs.msg import Range
|
|
|
|
from geometry_msgs.msg import Vector3
|
|
|
|
from geometry_msgs.msg import Vector3
|
|
|
|
|
|
|
|
'''
|
|
|
|
# test proto
|
|
|
|
# test proto
|
|
|
|
import random
|
|
|
|
import random
|
|
|
|
|
|
|
|
|
|
|
|
@ -35,11 +35,13 @@ class fake_hdg():
|
|
|
|
class state():
|
|
|
|
class state():
|
|
|
|
def __init__(self):
|
|
|
|
def __init__(self):
|
|
|
|
self.mode = "test"
|
|
|
|
self.mode = "test"
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def init_dataFormat(cfg):
|
|
|
|
def init_dataFormat(cfg):
|
|
|
|
|
|
|
|
ros_namespace="/drone1"
|
|
|
|
if cfg.msg_format == "Proto":
|
|
|
|
if cfg.msg_format == "Proto":
|
|
|
|
utils.Proto_msg_from_ros.client = client
|
|
|
|
utils.Proto_msg_from_ros.client = client
|
|
|
|
utils.Proto_msg_from_ros.flight_information_msg = flight_information_pb2.flight_information_message()
|
|
|
|
utils.Proto_msg_from_ros.flight_information_msg = flight_information_pb2.flight_information_message()
|
|
|
|
@ -47,11 +49,15 @@ def init_dataFormat(cfg):
|
|
|
|
utils.Proto_msg_from_ros.Flight_Information_topicToMqtt = cfg.Flight_Information_topicToMqtt
|
|
|
|
utils.Proto_msg_from_ros.Flight_Information_topicToMqtt = cfg.Flight_Information_topicToMqtt
|
|
|
|
utils.Proto_msg_from_ros.Fly_Formation_topicToMqtt = cfg.Fly_Formation_topicToMqtt
|
|
|
|
utils.Proto_msg_from_ros.Fly_Formation_topicToMqtt = cfg.Fly_Formation_topicToMqtt
|
|
|
|
utils.Proto_msg_from_ros.Fly_Formation_topicToMqtt_QOS = cfg.Fly_Formation_topicToMqtt_QOS
|
|
|
|
utils.Proto_msg_from_ros.Fly_Formation_topicToMqtt_QOS = cfg.Fly_Formation_topicToMqtt_QOS
|
|
|
|
|
|
|
|
rospy.Subscriber(ros_namespace+'/mavros/global_position/global', NavSatFix, utils.Proto_msg_from_ros.callBack_gps)
|
|
|
|
|
|
|
|
rospy.Subscriber(ros_namespace+'/mavros/global_position/compass_hdg', Float64, utils.Proto_msg_from_ros.callBack_compass_hdg)
|
|
|
|
elif cfg.msg_format == "Json":
|
|
|
|
elif cfg.msg_format == "Json":
|
|
|
|
utils.Json_msg_from_ros.client = client
|
|
|
|
utils.Json_msg_from_ros.client = client
|
|
|
|
utils.Json_msg_from_ros.Flight_Information_topicToMqtt = cfg.Flight_Information_topicToMqtt
|
|
|
|
utils.Json_msg_from_ros.Flight_Information_topicToMqtt = cfg.Flight_Information_topicToMqtt
|
|
|
|
utils.Json_msg_from_ros.Fly_Formation_topicToMqtt = cfg.Fly_Formation_topicToMqtt
|
|
|
|
utils.Json_msg_from_ros.Fly_Formation_topicToMqtt = cfg.Fly_Formation_topicToMqtt
|
|
|
|
utils.Json_msg_from_ros.Fly_Formation_topicToMqtt_QOS = cfg.Fly_Formation_topicToMqtt_QOS
|
|
|
|
utils.Json_msg_from_ros.Fly_Formation_topicToMqtt_QOS = cfg.Fly_Formation_topicToMqtt_QOS
|
|
|
|
|
|
|
|
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:
|
|
|
|
else:
|
|
|
|
print("msg_format not found")
|
|
|
|
print("msg_format not found")
|
|
|
|
|
|
|
|
|
|
|
|
@ -62,16 +68,16 @@ def on_connect(self, userdata, flags, rc):
|
|
|
|
print("Connected with result code " + str(rc))
|
|
|
|
print("Connected with result code " + str(rc))
|
|
|
|
|
|
|
|
|
|
|
|
def on_publish(self, userdata, mid):
|
|
|
|
def on_publish(self, userdata, mid):
|
|
|
|
pass
|
|
|
|
print("pub ok")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if __name__ == '__main__':
|
|
|
|
# Read Config
|
|
|
|
# Read Config
|
|
|
|
cfg = utils.MQTT_ROS_Config("utils/mqttConfig.yml")
|
|
|
|
FilePath = os.path.join(os.path.dirname(__file__),"utils","mqttConfig.yml")
|
|
|
|
|
|
|
|
cfg = utils.MQTT_ROS_Config(FilePath)
|
|
|
|
client = utils.MQTTClient(cfg.MQTTClientNamePub)
|
|
|
|
client = utils.MQTTClient(cfg.MQTTClientNamePub)
|
|
|
|
|
|
|
|
print(cfg)
|
|
|
|
# Setting Config
|
|
|
|
# Setting Config
|
|
|
|
init_dataFormat(cfg)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Mqtt
|
|
|
|
# Mqtt
|
|
|
|
client.on_connect = on_connect
|
|
|
|
client.on_connect = on_connect
|
|
|
|
@ -81,12 +87,23 @@ if __name__ == '__main__':
|
|
|
|
client.will_set(cfg.willTopic, cfg.lwt, cfg.willTopicQOS, cfg.willRetain)
|
|
|
|
client.will_set(cfg.willTopic, cfg.lwt, cfg.willTopicQOS, cfg.willRetain)
|
|
|
|
client.loop_start()
|
|
|
|
client.loop_start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Ros
|
|
|
|
|
|
|
|
rosClient = cfg.ROSClientNamePub
|
|
|
|
|
|
|
|
rospy.init_node(rosClient)
|
|
|
|
|
|
|
|
init_dataFormat(cfg)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rospy.spin()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'''
|
|
|
|
#test proto
|
|
|
|
#test proto
|
|
|
|
gps = fakeGps()
|
|
|
|
gps = fakeGps()
|
|
|
|
hdg = fake_hdg()
|
|
|
|
hdg = fake_hdg()
|
|
|
|
state = state()
|
|
|
|
state = state()
|
|
|
|
while True:
|
|
|
|
while True:
|
|
|
|
#test proto
|
|
|
|
#test proto
|
|
|
|
|
|
|
|
|
|
|
|
gps.latitude = random.uniform(0, 10)
|
|
|
|
gps.latitude = random.uniform(0, 10)
|
|
|
|
gps.longitude = random.uniform(0, 10)
|
|
|
|
gps.longitude = random.uniform(0, 10)
|
|
|
|
gps.altitude = random.uniform(0, 10)
|
|
|
|
gps.altitude = random.uniform(0, 10)
|
|
|
|
@ -100,12 +117,4 @@ if __name__ == '__main__':
|
|
|
|
# utils.Json_msg_from_ros.callBack_compass_hdg(hdg)
|
|
|
|
# utils.Json_msg_from_ros.callBack_compass_hdg(hdg)
|
|
|
|
# utils.Json_msg_from_ros.callBack_state(state)
|
|
|
|
# utils.Json_msg_from_ros.callBack_state(state)
|
|
|
|
# time.sleep(1)
|
|
|
|
# time.sleep(1)
|
|
|
|
|
|
|
|
'''
|
|
|
|
# Ros
|
|
|
|
|
|
|
|
# rosClient = cfg.ROSClientNamePub
|
|
|
|
|
|
|
|
# rospy.init_node(rosClient)
|
|
|
|
|
|
|
|
# subscriber = rospy.Subscriber('/mavros/global_position/global', NavSatFix, utils.Json_msg_from_ros.callBack_gps)
|
|
|
|
|
|
|
|
# subscriber = rospy.Subscriber('/mavros/global_position/compass_hdg', Float64, utils.Json_msg_from_ros.callBack_compass_hdg)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# rospy.spin()
|
|
|
|
|
|
|
|
|