|
|
@@ -12,7 +12,7 @@ import settings
|
|
|
from .ProgramItem import ProgramItem
|
|
|
from .capture.module_digicam import DigiCam
|
|
|
from databases import insert_photo_records
|
|
|
-
|
|
|
+from .McuDeviationSet import McuDeviationSet
|
|
|
# mcu命令
|
|
|
class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
lock = threading.Lock()
|
|
|
@@ -20,6 +20,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
def __init__(self, websocket_manager: ConnectionManager):
|
|
|
super().__init__(websocket_manager)
|
|
|
self.msg_type = "mcu"
|
|
|
+ self.mcu_deviation_set = McuDeviationSet(self)
|
|
|
self.m_t = 1
|
|
|
# 0未开始 1进行中 2已结束 99异常
|
|
|
self.action_state = 2
|
|
|
@@ -198,7 +199,8 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
)
|
|
|
self.add_send_data_queue(buf)
|
|
|
|
|
|
- def get_deviation(self):
|
|
|
+ async def get_deviation(self):
|
|
|
+ await asyncio.sleep(0.01)
|
|
|
# 发送获取偏移量
|
|
|
data = [self.command["get_deviation"], 1]
|
|
|
self.add_send_data_queue(data)
|
|
|
@@ -206,6 +208,59 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
# self.serial_ins.write_cmd(data)
|
|
|
print("发送获取偏移量")
|
|
|
|
|
|
+ def set_deviation(self, device_name, _type=0, deviation=0):
|
|
|
+ # turntable----0 angle_ratio 1 turntable_steering_deviation
|
|
|
+ # overturn ----0 middle 1 high
|
|
|
+ if device_name == "camera_high_motor":
|
|
|
+ deviation = deviation / 10 # deviation 原单位为mm
|
|
|
+ if device_name == "turntable_position_motor":
|
|
|
+ deviation = deviation / 10 # deviation 原单位为mm
|
|
|
+ if device_name == "camera_steering":
|
|
|
+ pass
|
|
|
+ if device_name == "turntable_steering":
|
|
|
+ pass
|
|
|
+ if device_name == "overturn_steering":
|
|
|
+ pass
|
|
|
+
|
|
|
+ device_id = self.device_name_dict[device_name]
|
|
|
+ _dir = 1 if deviation >= 0 else 0
|
|
|
+ deviation = int(abs(deviation * 10))
|
|
|
+ data = [
|
|
|
+ self.command["set_deviation"],
|
|
|
+ device_id,
|
|
|
+ _type,
|
|
|
+ _dir,
|
|
|
+ 0xFF & deviation >> 8,
|
|
|
+ 0xFF & deviation,
|
|
|
+ ]
|
|
|
+ self.add_send_data_queue(data)
|
|
|
+ # self.controlDevice(device_name, deviation)
|
|
|
+
|
|
|
+ async def set_deviation_cmd(self,value,action_name,type):
|
|
|
+ await asyncio.sleep(0.01)
|
|
|
+ name_sets = [
|
|
|
+ "相机电机", # min 0 max 400,步长1
|
|
|
+ "相机舵机", # min -40 max 40,步长0.1
|
|
|
+ "转盘舵机", # min -720 max 720,步长1
|
|
|
+ "转盘前后电机", # min 0 max 950,步长1
|
|
|
+ "翻板舵机中位", # min 0 max 180,步长0.5
|
|
|
+ "翻板舵机高位", # min 0 max 180,步长0.5
|
|
|
+ "翻板舵机上升速度", # min 1 max 10,步长1
|
|
|
+ "翻板舵机下降速度", # min 1 max 10,步长1
|
|
|
+ ]
|
|
|
+ if action_name not in name_sets:
|
|
|
+ self.msg_type = f"{type}_deviation"
|
|
|
+ self.sendSocketMessage(msg="设置参数有误,请检查", device_status=0,code=1)
|
|
|
+ self.msg_type = "mcu"
|
|
|
+ return
|
|
|
+ # 发送获取偏移量
|
|
|
+ if type == "move":
|
|
|
+ self.mcu_deviation_set.change_value(value, action_name)
|
|
|
+ elif type == "set":
|
|
|
+ self.mcu_deviation_set.set_deviation(action_name)
|
|
|
+ self.msg_type = f"{type}_deviation"
|
|
|
+ self.sendSocketMessage(msg=f"{action_name} 设置成功", device_status=2,code=0)
|
|
|
+ self.msg_type = "mcu"
|
|
|
def get_other_info(self):
|
|
|
# 发送获取偏移量
|
|
|
data = [self.command["get_other_info"], 1]
|
|
|
@@ -215,7 +270,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
def add_send_data_queue(self, data):
|
|
|
self.lock.acquire()
|
|
|
if self.serial_ins:
|
|
|
- # print("send_data_queue append :{}".format(data))
|
|
|
+ print("send_data_queue append :{}".format(data))
|
|
|
self.send_data_queue.append(data)
|
|
|
self.lock.release()
|
|
|
def send_all_cmd(self):
|
|
|
@@ -402,23 +457,57 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
# },
|
|
|
# }
|
|
|
# )
|
|
|
- message = {
|
|
|
- "_type": "get_deviation_data",
|
|
|
- "plugins_mode": "mcu",
|
|
|
- "data": {
|
|
|
- "camera_high_motor_deviation": camera_high_motor_deviation,
|
|
|
- "camera_steering_deviation": camera_steering_deviation,
|
|
|
- "turntable_steering_deviation": turntable_steering_deviation,
|
|
|
- "overturn_steering_middle": overturn_steering_middle,
|
|
|
- "overturn_steering_high": overturn_steering_high,
|
|
|
- "overturn_steering_up_speed": overturn_steering_up_speed,
|
|
|
- "overturn_steering_down_speed": overturn_steering_down_speed,
|
|
|
- },
|
|
|
+ # message = {
|
|
|
+ # "_type": "get_deviation_data",
|
|
|
+ # "plugins_mode": "mcu",
|
|
|
+ # "data": {
|
|
|
+ # "camera_high_motor_deviation": camera_high_motor_deviation,
|
|
|
+ # "camera_steering_deviation": camera_steering_deviation,
|
|
|
+ # "turntable_steering_deviation": turntable_steering_deviation,
|
|
|
+ # "overturn_steering_middle": overturn_steering_middle,
|
|
|
+ # "overturn_steering_high": overturn_steering_high,
|
|
|
+ # "overturn_steering_up_speed": overturn_steering_up_speed,
|
|
|
+ # "overturn_steering_down_speed": overturn_steering_down_speed,
|
|
|
+ # },
|
|
|
+ # }
|
|
|
+ get_deviation_data = {
|
|
|
+ "camera_high_motor_deviation": camera_high_motor_deviation,
|
|
|
+ "camera_steering_deviation": camera_steering_deviation,
|
|
|
+ "turntable_steering_deviation": turntable_steering_deviation,
|
|
|
+ "turntable_front_end_deviation": 300,
|
|
|
+ "overturn_steering_middle": overturn_steering_middle,
|
|
|
+ "overturn_steering_high": overturn_steering_high,
|
|
|
+ "overturn_steering_up_speed": overturn_steering_up_speed,
|
|
|
+ "overturn_steering_down_speed": overturn_steering_down_speed,
|
|
|
}
|
|
|
- self.sendSocketMessage(msg="接收偏移量信息", data=message)
|
|
|
+ self.initDeviationInfo(get_deviation_data)
|
|
|
+ self.msg_type = "get_deviation_data"
|
|
|
+ self.sendSocketMessage(msg="接收偏移量信息", data=get_deviation_data)
|
|
|
+ self.msg_type = "mcu"
|
|
|
print("接收偏移量信息")
|
|
|
return
|
|
|
|
|
|
+ def initDeviationInfo(self, get_deviation_data):
|
|
|
+ # 初始化偏移量信息
|
|
|
+ camera_high_motor_deviation = get_deviation_data["camera_high_motor_deviation"]
|
|
|
+ camera_steering_deviation = get_deviation_data["camera_steering_deviation"]
|
|
|
+ turntable_steering_deviation = get_deviation_data["turntable_steering_deviation"]
|
|
|
+ overturn_steering_middle=get_deviation_data["overturn_steering_middle"]
|
|
|
+ overturn_steering_high = get_deviation_data["overturn_steering_high"]
|
|
|
+ overturn_steering_up_speed = get_deviation_data["overturn_steering_up_speed"]
|
|
|
+ overturn_steering_down_speed = get_deviation_data["overturn_steering_down_speed"]
|
|
|
+ self.mcu_deviation_set.last_value["相机电机"] = camera_high_motor_deviation
|
|
|
+ self.mcu_deviation_set.last_value["相机舵机"] = camera_steering_deviation
|
|
|
+ self.mcu_deviation_set.last_value["转盘舵机"] = turntable_steering_deviation
|
|
|
+ self.mcu_deviation_set.last_value["翻板舵机中位"] = overturn_steering_middle
|
|
|
+ self.mcu_deviation_set.last_value["翻板舵机高位"] = overturn_steering_high
|
|
|
+ self.mcu_deviation_set.last_value["翻板舵机上升速度"] = (
|
|
|
+ overturn_steering_up_speed
|
|
|
+ )
|
|
|
+ self.mcu_deviation_set.last_value["翻板舵机下降速度"] = (
|
|
|
+ overturn_steering_down_speed
|
|
|
+ )
|
|
|
+
|
|
|
# 获取其他信息
|
|
|
def get_from_mcu_other_info(self, receive_data):
|
|
|
is_auto_send_base_info = self.get_data_from_receive_data(
|
|
|
@@ -740,9 +829,9 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
self.sendSocketMessage(
|
|
|
msg="MCU连接成功", data=message_data, device_status=2
|
|
|
)
|
|
|
- # time.sleep(2)
|
|
|
- # loop = asyncio.get_event_loop()
|
|
|
- # loop.create_task(self.initDevice(), name="init_mcu")
|
|
|
+ time.sleep(1)
|
|
|
+ loop = asyncio.get_event_loop()
|
|
|
+ loop.create_task(self.initDevice(), name="init_mcu")
|
|
|
# async def getBaseInfo():
|
|
|
# while True:
|
|
|
# await asyncio.sleep(1)
|
|
|
@@ -1271,8 +1360,8 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
# self.to_deal_device(device_name="buzzer", times=3)
|
|
|
# return
|
|
|
# else:
|
|
|
- program_item.run_only_mcu(1)
|
|
|
- # self.show_info("{}执行完成~".format(action.action_name))
|
|
|
+ program_item.run(3)
|
|
|
+ # self.show_info("{}执行完成~".format(action.action_name))
|
|
|
self.sendSocketMessage(
|
|
|
code=0,
|
|
|
msg="{} 执行完成~".format(program_item.action_name),
|
|
|
@@ -1280,14 +1369,14 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
|
|
|
device_status=2,
|
|
|
)
|
|
|
self.msg_type = "mcu"
|
|
|
- self.action_state = 2
|
|
|
- self.msg_type = "run_mcu_single_finish"
|
|
|
- self.sendSocketMessage(
|
|
|
- code=0,
|
|
|
- msg=f"执行完成",
|
|
|
- device_status=2,
|
|
|
- )
|
|
|
- self.msg_type = "mcu"
|
|
|
+ self.action_state = 2
|
|
|
+ self.msg_type = "run_mcu_single_finish"
|
|
|
+ self.sendSocketMessage(
|
|
|
+ code=0,
|
|
|
+ msg=f"执行完成",
|
|
|
+ device_status=2,
|
|
|
+ )
|
|
|
+ self.msg_type = "mcu"
|
|
|
|
|
|
|
|
|
async def checkMcuConnection(device_ctrl: DeviceControl):
|