add 5 bio_drones test
parent
01262ec88c
commit
6854584a5c
@ -0,0 +1,66 @@
|
||||
#include "class_model/FindLeader.h"
|
||||
#include "class_model/Leader.h"
|
||||
#include "class_model/follower.h"
|
||||
#include "yaml-cpp/yaml.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
// Init ROS node
|
||||
ros::init(argc, argv, "drone4_node");
|
||||
|
||||
// reate Assync spiner
|
||||
ros::AsyncSpinner spinner(0);
|
||||
spinner.start();
|
||||
// ros::Rate rate(5);
|
||||
|
||||
ModeClass mode_object;
|
||||
ControlClass control_object;
|
||||
RequestClass request_object;
|
||||
FollowerClass follower_object;
|
||||
LeaderClass leader_object;
|
||||
|
||||
// SelectionClass selection_object;
|
||||
|
||||
global_location target,self,M1,M2,M3,M4;
|
||||
int ref_ID,checkLeader;
|
||||
|
||||
YAML::Node config = YAML::LoadFile("/home/dodo/ardupilot_ws/src/class_model/src/config.yaml"); //reading yaml parameter(target point)
|
||||
target.lon = config["routh1"]["x"].as<float>()*1e7;
|
||||
target.lat = config["routh1"]["y"].as<float>()*1e7;
|
||||
|
||||
sleep(5);
|
||||
self = request_object.get_self_GPS();
|
||||
M1 = request_object.get_M1_GPS();
|
||||
M2 = request_object.get_M2_GPS();
|
||||
M3 = request_object.get_M3_GPS();
|
||||
M4 = request_object.get_M4_GPS();
|
||||
|
||||
// global_location pos[] = {target,self,M1,M2};
|
||||
// global_location member[] = {M1,M2};
|
||||
global_location pos[] = {target,self,M1,M2,M3,M4};
|
||||
global_location member[] = {M1,M2,M3,M4};
|
||||
size_t index = sizeof(pos)/sizeof(pos[0]);
|
||||
size_t m_index = sizeof(member)/sizeof(member[0]);
|
||||
|
||||
mode_object.set_Mode("GUIDED");
|
||||
control_object.arm();
|
||||
control_object.takeoff(2);
|
||||
|
||||
checkLeader = check_leader(pos,index).is_leader;
|
||||
if(checkLeader != 1){
|
||||
ref_ID = follower_object.find_ref_drone(pos,index,check_leader(pos,index).leader_ID); //find_ref_drone(pos,index,leader_ID);
|
||||
}
|
||||
|
||||
while(true){
|
||||
|
||||
if(checkLeader == 1){
|
||||
// leader_object.leader(target);
|
||||
}else{
|
||||
follower_object.follower(member,m_index,ref_ID); //follow reference drone position
|
||||
}
|
||||
}
|
||||
ros::waitForShutdown();
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
@ -0,0 +1,66 @@
|
||||
#include "class_model/FindLeader.h"
|
||||
#include "class_model/Leader.h"
|
||||
#include "class_model/follower.h"
|
||||
#include "yaml-cpp/yaml.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
// Init ROS node
|
||||
ros::init(argc, argv, "drone5_node");
|
||||
|
||||
// reate Assync spiner
|
||||
ros::AsyncSpinner spinner(0);
|
||||
spinner.start();
|
||||
// ros::Rate rate(5);
|
||||
|
||||
ModeClass mode_object;
|
||||
ControlClass control_object;
|
||||
RequestClass request_object;
|
||||
FollowerClass follower_object;
|
||||
LeaderClass leader_object;
|
||||
|
||||
// SelectionClass selection_object;
|
||||
|
||||
global_location target,self,M1,M2,M3,M4;
|
||||
int ref_ID,checkLeader;
|
||||
|
||||
YAML::Node config = YAML::LoadFile("/home/dodo/ardupilot_ws/src/class_model/src/config.yaml"); //reading yaml parameter(target point)
|
||||
target.lon = config["routh1"]["x"].as<float>()*1e7;
|
||||
target.lat = config["routh1"]["y"].as<float>()*1e7;
|
||||
|
||||
sleep(5);
|
||||
self = request_object.get_self_GPS();
|
||||
M1 = request_object.get_M1_GPS();
|
||||
M2 = request_object.get_M2_GPS();
|
||||
M3 = request_object.get_M3_GPS();
|
||||
M4 = request_object.get_M4_GPS();
|
||||
|
||||
// global_location pos[] = {target,self,M1,M2};
|
||||
// global_location member[] = {M1,M2};
|
||||
global_location pos[] = {target,self,M1,M2,M3,M4};
|
||||
global_location member[] = {M1,M2,M3,M4};
|
||||
size_t index = sizeof(pos)/sizeof(pos[0]);
|
||||
size_t m_index = sizeof(member)/sizeof(member[0]);
|
||||
|
||||
mode_object.set_Mode("GUIDED");
|
||||
control_object.arm();
|
||||
control_object.takeoff(2);
|
||||
|
||||
checkLeader = check_leader(pos,index).is_leader;
|
||||
if(checkLeader != 1){
|
||||
ref_ID = follower_object.find_ref_drone(pos,index,check_leader(pos,index).leader_ID); //find_ref_drone(pos,index,leader_ID);
|
||||
}
|
||||
|
||||
while(true){
|
||||
|
||||
if(checkLeader == 1){
|
||||
// leader_object.leader(target);
|
||||
}else{
|
||||
follower_object.follower(member,m_index,ref_ID); //follow reference drone position
|
||||
}
|
||||
}
|
||||
ros::waitForShutdown();
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
@ -0,0 +1,103 @@
|
||||
#!/usr/bin/env python3
|
||||
#coding:utf-8
|
||||
import paho.mqtt.client as mqtt
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import utils
|
||||
import proto.flight_information_pb2 as flight_information_pb2
|
||||
import proto.flyformatioln_pb2 as flyformatioln_pb2
|
||||
import logging
|
||||
|
||||
|
||||
import rospy
|
||||
from std_msgs.msg import String
|
||||
from std_msgs.msg import Float64
|
||||
from std_msgs.msg import Header
|
||||
from mavros_msgs.srv import ParamGet
|
||||
from sensor_msgs.msg import NavSatFix
|
||||
from sensor_msgs.msg import Imu
|
||||
from sensor_msgs.msg import Range
|
||||
from geometry_msgs.msg import Vector3
|
||||
|
||||
|
||||
|
||||
|
||||
def init_dataFormat(cfg:utils.Read_PUB_Config):
|
||||
ros_namespace="/drone4"
|
||||
if cfg.msg_format == "Proto":
|
||||
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.flyformatioln_msg = flyformatioln_pb2.fly_formation_message()
|
||||
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_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":
|
||||
utils.Json_msg_from_ros.client = client
|
||||
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_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:
|
||||
logging.debug("msg_format not found")
|
||||
|
||||
|
||||
def on_connect(self, userdata, flags, rc):
|
||||
logger.info("Connected with result code " + str(rc))
|
||||
|
||||
def on_publish(self, userdata, mid):
|
||||
logger.debug("pub success")
|
||||
|
||||
def on_disconnect(client, userdata, rc):
|
||||
logger.debug("disconnecting reason " +str(rc))
|
||||
client.connected_flag=False
|
||||
client.disconnect_flag=True
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Read Config
|
||||
FilePath = os.path.join(os.path.dirname(__file__),"utils","mqttConfig_PUB4.yml")
|
||||
cfg = utils.Read_PUB_Config(FilePath)
|
||||
client = utils.MQTTClient(cfg.MQTTClientNamePub)
|
||||
|
||||
# set log
|
||||
log_format = "%(asctime)s - %(levelname)s - %(message)s"
|
||||
formatter = logging.Formatter(log_format)
|
||||
|
||||
stream_handler = logging.StreamHandler()
|
||||
stream_handler.setFormatter(formatter)
|
||||
stream_handler.setLevel(logging.DEBUG)
|
||||
|
||||
file_handler = logging.FileHandler(cfg.logFileName)
|
||||
file_handler.setFormatter(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)
|
||||
|
||||
# Mqtt
|
||||
client.on_connect = on_connect
|
||||
client.on_publish = on_publish
|
||||
client.connect(host=cfg.host, port=cfg.port, keepalive=cfg.keepalive)
|
||||
client.will_set(cfg.willTopic, cfg.lwt, cfg.willTopicQOS, cfg.willRetain)
|
||||
client.loop_start()
|
||||
|
||||
# Ros
|
||||
rosClient = cfg.ROSClientNamePub
|
||||
rospy.init_node(rosClient)
|
||||
|
||||
# init data format
|
||||
init_dataFormat(cfg)
|
||||
|
||||
try:
|
||||
rospy.spin()
|
||||
except BaseException as error:
|
||||
client.disconnect()
|
||||
logger.info("End of program")
|
||||
sys.exit()
|
||||
|
||||
@ -0,0 +1,103 @@
|
||||
#!/usr/bin/env python3
|
||||
#coding:utf-8
|
||||
import paho.mqtt.client as mqtt
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import utils
|
||||
import proto.flight_information_pb2 as flight_information_pb2
|
||||
import proto.flyformatioln_pb2 as flyformatioln_pb2
|
||||
import logging
|
||||
|
||||
|
||||
import rospy
|
||||
from std_msgs.msg import String
|
||||
from std_msgs.msg import Float64
|
||||
from std_msgs.msg import Header
|
||||
from mavros_msgs.srv import ParamGet
|
||||
from sensor_msgs.msg import NavSatFix
|
||||
from sensor_msgs.msg import Imu
|
||||
from sensor_msgs.msg import Range
|
||||
from geometry_msgs.msg import Vector3
|
||||
|
||||
|
||||
|
||||
|
||||
def init_dataFormat(cfg:utils.Read_PUB_Config):
|
||||
ros_namespace="/drone5"
|
||||
if cfg.msg_format == "Proto":
|
||||
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.flyformatioln_msg = flyformatioln_pb2.fly_formation_message()
|
||||
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_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":
|
||||
utils.Json_msg_from_ros.client = client
|
||||
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_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:
|
||||
logging.debug("msg_format not found")
|
||||
|
||||
|
||||
def on_connect(self, userdata, flags, rc):
|
||||
logger.info("Connected with result code " + str(rc))
|
||||
|
||||
def on_publish(self, userdata, mid):
|
||||
logger.debug("pub success")
|
||||
|
||||
def on_disconnect(client, userdata, rc):
|
||||
logger.debug("disconnecting reason " +str(rc))
|
||||
client.connected_flag=False
|
||||
client.disconnect_flag=True
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Read Config
|
||||
FilePath = os.path.join(os.path.dirname(__file__),"utils","mqttConfig_PUB5.yml")
|
||||
cfg = utils.Read_PUB_Config(FilePath)
|
||||
client = utils.MQTTClient(cfg.MQTTClientNamePub)
|
||||
|
||||
# set log
|
||||
log_format = "%(asctime)s - %(levelname)s - %(message)s"
|
||||
formatter = logging.Formatter(log_format)
|
||||
|
||||
stream_handler = logging.StreamHandler()
|
||||
stream_handler.setFormatter(formatter)
|
||||
stream_handler.setLevel(logging.DEBUG)
|
||||
|
||||
file_handler = logging.FileHandler(cfg.logFileName)
|
||||
file_handler.setFormatter(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)
|
||||
|
||||
# Mqtt
|
||||
client.on_connect = on_connect
|
||||
client.on_publish = on_publish
|
||||
client.connect(host=cfg.host, port=cfg.port, keepalive=cfg.keepalive)
|
||||
client.will_set(cfg.willTopic, cfg.lwt, cfg.willTopicQOS, cfg.willRetain)
|
||||
client.loop_start()
|
||||
|
||||
# Ros
|
||||
rosClient = cfg.ROSClientNamePub
|
||||
rospy.init_node(rosClient)
|
||||
|
||||
# init data format
|
||||
init_dataFormat(cfg)
|
||||
|
||||
try:
|
||||
rospy.spin()
|
||||
except BaseException as error:
|
||||
client.disconnect()
|
||||
logger.info("End of program")
|
||||
sys.exit()
|
||||
|
||||
@ -0,0 +1,116 @@
|
||||
#!/usr/bin/env python3
|
||||
#coding:utf-8
|
||||
import paho.mqtt.client as mqtt
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import utils
|
||||
import proto.flight_information_pb2 as flight_information_pb2
|
||||
import proto.flyformatioln_pb2 as flyformatioln_pb2
|
||||
import rospy
|
||||
from std_msgs.msg import String
|
||||
import logging
|
||||
|
||||
|
||||
def init_dataFormat(cfg:utils.Read_SUB_Config):
|
||||
if cfg.msg_format == "Proto":
|
||||
utils.Proto_msg_to_ros.rate = rospy.Rate(10)
|
||||
utils.Proto_msg_to_ros.publisher_Flight_Information = rospy.Publisher(cfg.ROStopicName_Flight_Information,String,queue_size=10)
|
||||
utils.Proto_msg_to_ros.publisher_Fly_Formation = rospy.Publisher(cfg.ROStopicName_Fly_Formation,String,queue_size=10)
|
||||
|
||||
utils.Proto_msg_to_ros.flight_information_msg = flight_information_pb2.flight_information_message()
|
||||
utils.Proto_msg_to_ros.flyformatioln_msg = flyformatioln_pb2.fly_formation_message()
|
||||
|
||||
client.message_callback_add(cfg.Flight_Information_topicToMqtt, utils.Proto_msg_to_ros.on_message_Flight_Information)
|
||||
client.message_callback_add(cfg.Fly_Formation_topicToMqtt, utils.Proto_msg_to_ros.on_message_Fly_Formation)
|
||||
|
||||
utils.Proto_msg_to_ros.Flight_Information_topicToMqtt = cfg.Flight_Information_topicToMqtt
|
||||
utils.Proto_msg_to_ros.Fly_Formation_topicToMqtt = cfg.Fly_Formation_topicToMqtt
|
||||
elif cfg.msg_format == "Json":
|
||||
# set ros publisher
|
||||
utils.Json_msg_to_ros.rate = rospy.Rate(10)
|
||||
utils.Json_msg_to_ros.publisher_Fly_Formation = rospy.Publisher(cfg.ROStopicName_Fly_Formation,String,queue_size=10)
|
||||
utils.Json_msg_to_ros.Drone550_publisher_Flight_Information = rospy.Publisher(cfg.Dron550_ROStopicName_Flight_Information,String,queue_size=10)
|
||||
utils.Json_msg_to_ros.Drone380_publisher_Flight_Information = rospy.Publisher(cfg.Dron380_ROStopicName_Flight_Information,String,queue_size=10)
|
||||
utils.Json_msg_to_ros.Drone650_publisher_Flight_Information = rospy.Publisher(cfg.Dron650_ROStopicName_Flight_Information,String,queue_size=10)
|
||||
utils.Json_msg_to_ros.Drone555_publisher_Flight_Information = rospy.Publisher(cfg.Dron555_ROStopicName_Flight_Information,String,queue_size=10)
|
||||
utils.Json_msg_to_ros.Drone888_publisher_Flight_Information = rospy.Publisher(cfg.Dron888_ROStopicName_Flight_Information,String,queue_size=10)
|
||||
|
||||
# set callback to each topic
|
||||
client.message_callback_add(cfg.Fly_Formation_topicToMqtt, utils.Json_msg_to_ros.on_message_Fly_Formation)
|
||||
client.message_callback_add(cfg.Drone550_Flight_Information_topicToMqtt, utils.Json_msg_to_ros.Drone550_on_message_Flight_Information)
|
||||
client.message_callback_add(cfg.Drone380_Flight_Information_topicToMqtt, utils.Json_msg_to_ros.Drone380_on_message_Flight_Information)
|
||||
client.message_callback_add(cfg.Drone650_Flight_Information_topicToMqtt, utils.Json_msg_to_ros.Drone650_on_message_Flight_Information)
|
||||
|
||||
client.message_callback_add(cfg.Drone888_Flight_Information_topicToMqtt, utils.Json_msg_to_ros.Drone888_on_message_Flight_Information)
|
||||
client.message_callback_add(cfg.Drone555_Flight_Information_topicToMqtt, utils.Json_msg_to_ros.Drone555_on_message_Flight_Information)
|
||||
else:
|
||||
logger.debug("msg_format not found")
|
||||
|
||||
|
||||
def on_connect(self, userdata, flags, rc):
|
||||
logger.info("Connected with result code " + str(rc))
|
||||
client.subscribe(cfg.Fly_Formation_topicToMqtt)
|
||||
client.subscribe(cfg.Drone550_Flight_Information_topicToMqtt)
|
||||
client.subscribe(cfg.Drone380_Flight_Information_topicToMqtt)
|
||||
client.subscribe(cfg.Drone650_Flight_Information_topicToMqtt)
|
||||
|
||||
client.subscribe(cfg.Drone888_Flight_Information_topicToMqtt)
|
||||
client.subscribe(cfg.Drone555_Flight_Information_topicToMqtt)
|
||||
|
||||
def on_disconnect(client, userdata, rc):
|
||||
logger.info("disconnecting reason " +str(rc))
|
||||
client.connected_flag=False
|
||||
client.disconnect_flag=True
|
||||
|
||||
def on_publish(self, userdata, mid):
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Read Config
|
||||
FilePath = os.path.join(os.path.dirname(__file__),"utils","mqttConfig_SUB4.yml")
|
||||
cfg = utils.Read_SUB_Config(FilePath)
|
||||
client = utils.MQTTClient(cfg.MQTTClientNameSub)
|
||||
|
||||
# set log
|
||||
log_format = "%(asctime)s - %(levelname)s - %(message)s"
|
||||
formatter = logging.Formatter(log_format)
|
||||
|
||||
stream_handler = logging.StreamHandler()
|
||||
stream_handler.setFormatter(formatter)
|
||||
stream_handler.setLevel(logging.DEBUG)
|
||||
|
||||
|
||||
file_handler = logging.FileHandler(cfg.logFileName)
|
||||
file_handler.setFormatter(formatter)
|
||||
file_handler.setLevel(logging.INFO)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.setLevel(logging.DEBUG)
|
||||
logger.addHandler(file_handler)
|
||||
logger.addHandler(stream_handler)
|
||||
|
||||
logger.info(cfg)
|
||||
|
||||
# Mqtt
|
||||
client = utils.MQTTClient(cfg.MQTTClientNameSub)
|
||||
client.on_connect = on_connect
|
||||
client.on_publish = on_publish
|
||||
client.on_disconnect = on_disconnect
|
||||
client.connect(host=cfg.host, port=cfg.port, keepalive=cfg.keepalive)
|
||||
|
||||
|
||||
# Ros
|
||||
rospy.init_node(cfg.ROSClientNameSub)
|
||||
# initialize
|
||||
init_dataFormat(cfg)
|
||||
|
||||
try:
|
||||
client.loop_start()
|
||||
rospy.spin()
|
||||
except BaseException as error:
|
||||
client.loop_stop()
|
||||
client.disconnect()
|
||||
logger.info("End of program")
|
||||
sys.exit(0)
|
||||
@ -0,0 +1,116 @@
|
||||
#!/usr/bin/env python3
|
||||
#coding:utf-8
|
||||
import paho.mqtt.client as mqtt
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import utils
|
||||
import proto.flight_information_pb2 as flight_information_pb2
|
||||
import proto.flyformatioln_pb2 as flyformatioln_pb2
|
||||
import rospy
|
||||
from std_msgs.msg import String
|
||||
import logging
|
||||
|
||||
|
||||
def init_dataFormat(cfg:utils.Read_SUB_Config):
|
||||
if cfg.msg_format == "Proto":
|
||||
utils.Proto_msg_to_ros.rate = rospy.Rate(10)
|
||||
utils.Proto_msg_to_ros.publisher_Flight_Information = rospy.Publisher(cfg.ROStopicName_Flight_Information,String,queue_size=10)
|
||||
utils.Proto_msg_to_ros.publisher_Fly_Formation = rospy.Publisher(cfg.ROStopicName_Fly_Formation,String,queue_size=10)
|
||||
|
||||
utils.Proto_msg_to_ros.flight_information_msg = flight_information_pb2.flight_information_message()
|
||||
utils.Proto_msg_to_ros.flyformatioln_msg = flyformatioln_pb2.fly_formation_message()
|
||||
|
||||
client.message_callback_add(cfg.Flight_Information_topicToMqtt, utils.Proto_msg_to_ros.on_message_Flight_Information)
|
||||
client.message_callback_add(cfg.Fly_Formation_topicToMqtt, utils.Proto_msg_to_ros.on_message_Fly_Formation)
|
||||
|
||||
utils.Proto_msg_to_ros.Flight_Information_topicToMqtt = cfg.Flight_Information_topicToMqtt
|
||||
utils.Proto_msg_to_ros.Fly_Formation_topicToMqtt = cfg.Fly_Formation_topicToMqtt
|
||||
elif cfg.msg_format == "Json":
|
||||
# set ros publisher
|
||||
utils.Json_msg_to_ros.rate = rospy.Rate(10)
|
||||
utils.Json_msg_to_ros.publisher_Fly_Formation = rospy.Publisher(cfg.ROStopicName_Fly_Formation,String,queue_size=10)
|
||||
utils.Json_msg_to_ros.Drone550_publisher_Flight_Information = rospy.Publisher(cfg.Dron550_ROStopicName_Flight_Information,String,queue_size=10)
|
||||
utils.Json_msg_to_ros.Drone380_publisher_Flight_Information = rospy.Publisher(cfg.Dron380_ROStopicName_Flight_Information,String,queue_size=10)
|
||||
utils.Json_msg_to_ros.Drone650_publisher_Flight_Information = rospy.Publisher(cfg.Dron650_ROStopicName_Flight_Information,String,queue_size=10)
|
||||
utils.Json_msg_to_ros.Drone555_publisher_Flight_Information = rospy.Publisher(cfg.Dron555_ROStopicName_Flight_Information,String,queue_size=10)
|
||||
utils.Json_msg_to_ros.Drone888_publisher_Flight_Information = rospy.Publisher(cfg.Dron888_ROStopicName_Flight_Information,String,queue_size=10)
|
||||
|
||||
# set callback to each topic
|
||||
client.message_callback_add(cfg.Fly_Formation_topicToMqtt, utils.Json_msg_to_ros.on_message_Fly_Formation)
|
||||
client.message_callback_add(cfg.Drone550_Flight_Information_topicToMqtt, utils.Json_msg_to_ros.Drone550_on_message_Flight_Information)
|
||||
client.message_callback_add(cfg.Drone380_Flight_Information_topicToMqtt, utils.Json_msg_to_ros.Drone380_on_message_Flight_Information)
|
||||
client.message_callback_add(cfg.Drone650_Flight_Information_topicToMqtt, utils.Json_msg_to_ros.Drone650_on_message_Flight_Information)
|
||||
|
||||
client.message_callback_add(cfg.Drone888_Flight_Information_topicToMqtt, utils.Json_msg_to_ros.Drone888_on_message_Flight_Information)
|
||||
client.message_callback_add(cfg.Drone555_Flight_Information_topicToMqtt, utils.Json_msg_to_ros.Drone555_on_message_Flight_Information)
|
||||
else:
|
||||
logger.debug("msg_format not found")
|
||||
|
||||
|
||||
def on_connect(self, userdata, flags, rc):
|
||||
logger.info("Connected with result code " + str(rc))
|
||||
client.subscribe(cfg.Fly_Formation_topicToMqtt)
|
||||
client.subscribe(cfg.Drone550_Flight_Information_topicToMqtt)
|
||||
client.subscribe(cfg.Drone380_Flight_Information_topicToMqtt)
|
||||
client.subscribe(cfg.Drone650_Flight_Information_topicToMqtt)
|
||||
|
||||
client.subscribe(cfg.Drone888_Flight_Information_topicToMqtt)
|
||||
client.subscribe(cfg.Drone555_Flight_Information_topicToMqtt)
|
||||
|
||||
def on_disconnect(client, userdata, rc):
|
||||
logger.info("disconnecting reason " +str(rc))
|
||||
client.connected_flag=False
|
||||
client.disconnect_flag=True
|
||||
|
||||
def on_publish(self, userdata, mid):
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Read Config
|
||||
FilePath = os.path.join(os.path.dirname(__file__),"utils","mqttConfig_SUB5.yml")
|
||||
cfg = utils.Read_SUB_Config(FilePath)
|
||||
client = utils.MQTTClient(cfg.MQTTClientNameSub)
|
||||
|
||||
# set log
|
||||
log_format = "%(asctime)s - %(levelname)s - %(message)s"
|
||||
formatter = logging.Formatter(log_format)
|
||||
|
||||
stream_handler = logging.StreamHandler()
|
||||
stream_handler.setFormatter(formatter)
|
||||
stream_handler.setLevel(logging.DEBUG)
|
||||
|
||||
|
||||
file_handler = logging.FileHandler(cfg.logFileName)
|
||||
file_handler.setFormatter(formatter)
|
||||
file_handler.setLevel(logging.INFO)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.setLevel(logging.DEBUG)
|
||||
logger.addHandler(file_handler)
|
||||
logger.addHandler(stream_handler)
|
||||
|
||||
logger.info(cfg)
|
||||
|
||||
# Mqtt
|
||||
client = utils.MQTTClient(cfg.MQTTClientNameSub)
|
||||
client.on_connect = on_connect
|
||||
client.on_publish = on_publish
|
||||
client.on_disconnect = on_disconnect
|
||||
client.connect(host=cfg.host, port=cfg.port, keepalive=cfg.keepalive)
|
||||
|
||||
|
||||
# Ros
|
||||
rospy.init_node(cfg.ROSClientNameSub)
|
||||
# initialize
|
||||
init_dataFormat(cfg)
|
||||
|
||||
try:
|
||||
client.loop_start()
|
||||
rospy.spin()
|
||||
except BaseException as error:
|
||||
client.loop_stop()
|
||||
client.disconnect()
|
||||
logger.info("End of program")
|
||||
sys.exit(0)
|
||||
@ -0,0 +1,22 @@
|
||||
MQTT:
|
||||
msg_format: Json
|
||||
MQTTClientNamePub: Drone888Pub
|
||||
host: 140.120.31.133
|
||||
port: 1883
|
||||
keepalive: 60
|
||||
willTopic: CheckDoneConnect
|
||||
willTopicQOS: 1
|
||||
lwt: Drone888 Gone Offline
|
||||
willRetain: False
|
||||
# Mqtt topic
|
||||
Flight_Information_topicToMqtt: Drone888/Flight_Information
|
||||
Fly_Formation_topicToMqtt: Drone888/Formation
|
||||
# Change formate qos
|
||||
Fly_Formation_topicToMqtt_QOS: 2
|
||||
#ROS
|
||||
ROS:
|
||||
ROSClientNamePub: Drone888Pub
|
||||
ROStopicName_Flight_Information: Drone888_Flight_Information_reciver
|
||||
ROStopicName_Fly_Formation: Fly_Formation_reciver
|
||||
LOG:
|
||||
logFileName: pub.log
|
||||
@ -0,0 +1,22 @@
|
||||
MQTT:
|
||||
msg_format: Json
|
||||
MQTTClientNamePub: Drone555Pub
|
||||
host: 140.120.31.133
|
||||
port: 1883
|
||||
keepalive: 60
|
||||
willTopic: CheckDoneConnect
|
||||
willTopicQOS: 1
|
||||
lwt: Drone555 Gone Offline
|
||||
willRetain: False
|
||||
# Mqtt topic
|
||||
Flight_Information_topicToMqtt: Drone555/Flight_Information
|
||||
Fly_Formation_topicToMqtt: Drone555/Formation
|
||||
# Change formate qos
|
||||
Fly_Formation_topicToMqtt_QOS: 2
|
||||
#ROS
|
||||
ROS:
|
||||
ROSClientNamePub: Drone555Pub
|
||||
ROStopicName_Flight_Information: Drone555_Flight_Information_reciver
|
||||
ROStopicName_Fly_Formation: Fly_Formation_reciver
|
||||
LOG:
|
||||
logFileName: pub.log
|
||||
@ -0,0 +1,38 @@
|
||||
MQTT:
|
||||
msg_format: Json
|
||||
MQTTClientNameSub: Drone888Sub
|
||||
host: 140.120.31.133
|
||||
port: 1883
|
||||
keepalive: 60
|
||||
willTopic: CheckDoneConnect
|
||||
willTopicQOS: 1
|
||||
lwt: Drone888 Gone Offline
|
||||
willRetain: False
|
||||
# Mqtt topic
|
||||
Fly_Formation_topicToMqtt: Drone888/Formation
|
||||
Drone550_Flight_Information_topicToMqtt: Drone550/Flight_Information
|
||||
|
||||
Drone380_Flight_Information_topicToMqtt: Drone380/Flight_Information
|
||||
|
||||
Drone650_Flight_Information_topicToMqtt: Drone650/Flight_Information
|
||||
|
||||
Drone888_Flight_Information_topicToMqtt: Drone888/Flight_Information
|
||||
|
||||
Drone555_Flight_Information_topicToMqtt: Drone555/Flight_Information
|
||||
|
||||
# Change formate qos
|
||||
Fly_Formation_topicToMqtt_QOS: 2
|
||||
ROS:
|
||||
ROSClientNameSub: Drone888Sub
|
||||
ROStopicName_Fly_Formation: Fly_Formation_reciver
|
||||
Dron550_ROStopicName_Flight_Information: Dron550_Flight_Information_reciver
|
||||
|
||||
Dron380_ROStopicName_Flight_Information: Dron380_Flight_Information_reciver
|
||||
|
||||
Dron650_ROStopicName_Flight_Information: Dron650_Flight_Information_reciver
|
||||
|
||||
Dron888_ROStopicName_Flight_Information: Dron888_Flight_Information_reciver
|
||||
|
||||
Dron555_ROStopicName_Flight_Information: Dron555_Flight_Information_reciver
|
||||
LOG:
|
||||
logFileName: sub.log
|
||||
@ -0,0 +1,38 @@
|
||||
MQTT:
|
||||
msg_format: Json
|
||||
MQTTClientNameSub: Drone555Sub
|
||||
host: 140.120.31.133
|
||||
port: 1883
|
||||
keepalive: 60
|
||||
willTopic: CheckDoneConnect
|
||||
willTopicQOS: 1
|
||||
lwt: Drone555 Gone Offline
|
||||
willRetain: False
|
||||
# Mqtt topic
|
||||
Fly_Formation_topicToMqtt: Drone555/Formation
|
||||
Drone550_Flight_Information_topicToMqtt: Drone550/Flight_Information
|
||||
|
||||
Drone380_Flight_Information_topicToMqtt: Drone380/Flight_Information
|
||||
|
||||
Drone650_Flight_Information_topicToMqtt: Drone650/Flight_Information
|
||||
|
||||
Drone888_Flight_Information_topicToMqtt: Drone888/Flight_Information
|
||||
|
||||
Drone555_Flight_Information_topicToMqtt: Drone555/Flight_Information
|
||||
|
||||
# Change formate qos
|
||||
Fly_Formation_topicToMqtt_QOS: 2
|
||||
ROS:
|
||||
ROSClientNameSub: Drone555Sub
|
||||
ROStopicName_Fly_Formation: Fly_Formation_reciver
|
||||
Dron550_ROStopicName_Flight_Information: Dron550_Flight_Information_reciver
|
||||
|
||||
Dron380_ROStopicName_Flight_Information: Dron380_Flight_Information_reciver
|
||||
|
||||
Dron650_ROStopicName_Flight_Information: Dron650_Flight_Information_reciver
|
||||
|
||||
Dron888_ROStopicName_Flight_Information: Dron888_Flight_Information_reciver
|
||||
|
||||
Dron555_ROStopicName_Flight_Information: Dron555_Flight_Information_reciver
|
||||
LOG:
|
||||
logFileName: sub.log
|
||||
@ -1,7 +0,0 @@
|
||||
<launch>
|
||||
<!-- We resume the logic in empty_world.launch, changing only the name of the world to be launched -->
|
||||
<include file="$(find gazebo_ros)/launch/empty_world.launch">
|
||||
<arg name="world_name" value="$(find iq_sim)/worlds/multi_drone.world"/>
|
||||
<!-- more default parameters can be changed here -->
|
||||
</include>
|
||||
</launch>
|
||||
Loading…
Reference in New Issue