Beispiel #1
0
 def __init__(self, *args, **kwargs):
     super(TestMqttSendGet, self).__init__(*args, **kwargs)
     self.src_point = [114.4314, 30.523558]
     # obj = ServerData()
     self.logger_ = log.LogHandler('server_data_test')
     self.mqtt_obj = server_data.MqttSendGet(self.logger_)
     self.data_define_obj = server_data.DataDefine()
Beispiel #2
0
    def __init__(self):
        self.logger = log.LogHandler('mian')
        self.com_logger = log.LogHandler('com_logger')

        # 湖泊像素轮廓点
        self.pix_cnts = None

        # 当前接收到的船号,
        self.online_ship_list = []

        # 手动控制状态
        self.ship_control_dict = {}

        # 像素位置与经纬度
        self.ship_pix_position_dict = {}
        self.ship_lng_lat_position_dict = {}

        # 用户点击像素点
        self.click_pix_points_dict = {}
        # 船配置航点
        self.config_ship_lng_lats_dict = {}
        # 船剩余电量
        self.ship_dump_energy_dict = {}
        # 船速度
        self.ship_speed_dict = {}
        # 船朝向
        self.ship_direction_dict = {}

        # 是否发送所有路径到船
        self.b_send_path = False
        self.b_send_control = False
        # 采集点经纬度
        self.lng_lats_list = []

        # 记录当前存在的串口
        self.serial_obj = None
Beispiel #3
0
        else:
            self.mqtt_client.publish(topic, payload=data, qos=qos)

    # 订阅消息
    def subscribe_topic(self, topic='qqq', qos=0):
        """
        :param topic 订阅的话题
        :param qos  发布质量
        """
        self.logger.info({'topic': topic, 'qos': qos})
        self.mqtt_client.subscribe(topic, qos)


if __name__ == '__main__':
    # obj = ServerData()
    logger = log.LogHandler('server_data_test')
    mqtt_obj = MqttSendGet(logger)
    data_define_obj = DataDefine()
    # 启动后自动订阅话题
    for topic, qos in data_define_obj.topics:
        logger.info(topic + '    ' + str(qos))
        mqtt_obj.subscribe_topic(topic=topic, qos=qos)
    # http发送检测数据给服务器
    while True:
        mqtt_obj.publish_topic(topic='status_data_%s' % (config.ship_code),
                               data=data_define.init_ststus_data,
                               qos=1)
        mqtt_obj.publish_topic(topic='detect_data_%s' % (config.ship_code),
                               data=data_define.init_detect_data,
                               qos=1)
        time.sleep(config.pi2mqtt_interval)
Beispiel #4
0
import copy
import numpy as np
from numpy import e
from utils import log
import config

logger = log.LogHandler('pi_log')


class SimplePid:
    def __init__(self):
        self.errorSum = 0
        self.currentError = 0
        self.previousError = 0
        # 左右侧超声波距离,没有返回None  -1 表示距离过近
        self.left_distance = None
        self.right_distance = None
        # 调节p数组
        self.adjust_p_size = 10
        self.adjust_p_list = []

    def distance_p(self, distance, theta_error):
        # motor_forward = int(config.motor_forward * (180-abs(theta_error))/(180*1.4))
        motor_forward = int(config.motor_forward)
        pwm = int((distance * (motor_forward / config.full_speed_meter)))
        if pwm >= config.motor_forward:
            pwm = config.motor_forward
        pwm = int(pwm * (180 - abs(theta_error)) / 180)
        return pwm

    def update_steer_pid(self, theta_error):
Beispiel #5
0
    os.path.join(
        os.path.dirname(
            os.path.abspath(__file__)),
        'statics'))
sys.path.append(
    os.path.join(
        os.path.dirname(
            os.path.abspath(__file__)),
        'storage'))
sys.path.append(
    os.path.join(
        os.path.dirname(
            os.path.abspath(__file__)),
        'utils'))

logger = log.LogHandler('main_log')


def main():
    config.update_setting()
    if config.b_play_audio:
        audios_manager.play_audio(audio_index=audios_manager.AudioType.start)
    # 数据处理对象
    data_manager_obj = data_manager.DataManager()
    # 查询改船是否注册 若未注册直接退出
    try:
        binding_data = data_manager_obj.send(
            method='http', data="", url=config.http_binding, http_type='GET')
        if int(binding_data['flag']) != 1:
            if config.b_play_audio:
                audios_manager.play_audio('register.mp3')
Beispiel #6
0
"""
串口数据收发
"""
import serial
import binascii
import time
import copy
from threading import Thread

from utils import log

logger = log.LogHandler('test_com')


class SerialData:
    def __init__(self, com, baud, timeout, logger=None):
        if logger is None:
            import logging
            logging.basicConfig(
                format=
                '%(asctime)s - %(pathname)s[line:%(lineno)d] - %(levelname)s: %(message)s',
                level=logging.DEBUG)
            self.logger = logging
        else:
            self.logger = logger
        self.port = com
        self.baud = baud
        self.timeout = timeout
        try:
            # 打开串口,并得到串口对象
            self.uart = serial.Serial(self.port,
Beispiel #7
0
app = Flask(__name__,
            template_folder=resource_path('templates'),
            static_folder=resource_path('statics'))
CORS(app, resources=r'/*')
#测试使用
b_test = False


# 接收第一次点击经纬都找湖
@app.route('/')
def index():
    return render_template('map3.html')


logger = log.LogHandler('main')


# 湖轮廓像素位置
@app.route('/pool_cnts', methods=['GET', 'POST'])
def pool_cnts():
    print(request)
    print("request.url", request.url)
    print("request.data", request.data)
    if b_test:
        return json.dumps({
            'data':
            '391,599 745,539 872,379 896,254 745,150 999,63 499,0 217,51  66,181 0,470'
        })
    else:
        # 失败返回提示信息