uavlink with ros no check
parent
6854584a5c
commit
d3059c3ac5
@ -0,0 +1,71 @@
|
|||||||
|
import serial
|
||||||
|
import time
|
||||||
|
import random
|
||||||
|
import utils
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import proto.flight_information_pb2 as flight_information_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="/drone1"
|
||||||
|
f1data = b'\xf1drone550..............\r\n'
|
||||||
|
sel = serial.Serial(cfg.port, cfg.baudrate, serial.EIGHTBITS, serial.PARITY_NONE, serial.STOPBITS_ONE)
|
||||||
|
sel.write(f1data)
|
||||||
|
utils.Proto_msg_from_ros.sel = sel
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
FilePath = os.path.join(os.path.dirname(__file__),"utils","mqttConfig_PUB.yml")
|
||||||
|
cfg = utils.Read_PUB_Config(FilePath)
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Ros
|
||||||
|
rosClient = cfg.ROSClientNamePub
|
||||||
|
rospy.init_node(rosClient)
|
||||||
|
|
||||||
|
# init data format
|
||||||
|
init_dataFormat(cfg)
|
||||||
|
|
||||||
|
try:
|
||||||
|
rospy.spin()
|
||||||
|
except BaseException as error:
|
||||||
|
logger.info("End of program")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
import orjson
|
||||||
|
import time
|
||||||
|
import logging
|
||||||
|
|
||||||
|
# logger = logging.getLogger("__PUB__")
|
||||||
|
|
||||||
|
class Proto_msg_from_ros:
|
||||||
|
#Protobuf
|
||||||
|
flight_information_msg = None
|
||||||
|
sel = None
|
||||||
|
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def callBack_gps(cls, GPS):
|
||||||
|
cls.flight_information_msg.gps.LAT = GPS.latitude
|
||||||
|
cls.flight_information_msg.gps.LON = GPS.longitude
|
||||||
|
cls.flight_information_msg.gps.ALT = GPS.altitude
|
||||||
|
# print ('lat:'+lat+'\n'+'lon:'+lon+'\n')
|
||||||
|
# print(cls.flight_information_msg)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def callBack_compass_hdg(cls, Compass):
|
||||||
|
cls.flight_information_msg.heading = Compass.data
|
||||||
|
flightInformationMsg = cls.flight_information_msg.SerializeToString()
|
||||||
|
cls.sel.write(b'\xf2' + flightInformationMsg + b'\r\n')
|
||||||
|
readTenByte = cls.sel.readline()
|
||||||
|
print(readTenByte)
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
UAVLINK:
|
||||||
|
msg_format: Proto
|
||||||
|
uav_id: \x01\x01
|
||||||
|
baudrate: 250000
|
||||||
|
port: /dev/ttyUSB2
|
||||||
|
MQTT: "None"
|
||||||
|
#ROS
|
||||||
|
ROS:
|
||||||
|
ROSClientNamePub: Drone550UAVLINKPub
|
||||||
|
ROStopicName_Flight_Information: Flight_Information_reciver
|
||||||
|
LOG:
|
||||||
|
logFileName: UAVLINKpub.log
|
||||||
Loading…
Reference in New Issue