pref: 修改模块名称
This commit is contained in:
10
main.py
10
main.py
@@ -3,6 +3,7 @@ import queue
|
|||||||
import threading
|
import threading
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
import subtask as sb
|
import subtask as sb
|
||||||
|
import majtask as mj
|
||||||
|
|
||||||
# 读取配置
|
# 读取配置
|
||||||
cfg_main = toml.load('cfg_main.toml')
|
cfg_main = toml.load('cfg_main.toml')
|
||||||
@@ -10,8 +11,8 @@ cfg_main = toml.load('cfg_main.toml')
|
|||||||
# 配置日志输出
|
# 配置日志输出
|
||||||
logger.add(cfg_main['debug']['logger_filename'], format=cfg_main['debug']['logger_format'], retention = 5, level="INFO")
|
logger.add(cfg_main['debug']['logger_filename'], format=cfg_main['debug']['logger_format'], retention = 5, level="INFO")
|
||||||
|
|
||||||
|
# 向任务队列添加任务
|
||||||
task_queue = queue.Queue()
|
task_queue = queue.Queue()
|
||||||
|
|
||||||
task_queue.put(sb.task(sb.get_block.exec, sb.get_block.find, cfg_main['task']['GetBlock_enable']))
|
task_queue.put(sb.task(sb.get_block.exec, sb.get_block.find, cfg_main['task']['GetBlock_enable']))
|
||||||
task_queue.put(sb.task(sb.put_block.exec, sb.put_block.find, cfg_main['task']['PutBlock_enable']))
|
task_queue.put(sb.task(sb.put_block.exec, sb.put_block.find, cfg_main['task']['PutBlock_enable']))
|
||||||
task_queue.put(sb.task(sb.get_bball.exec, sb.get_bball.find, cfg_main['task']['GetBBall_enable']))
|
task_queue.put(sb.task(sb.get_bball.exec, sb.get_bball.find, cfg_main['task']['GetBBall_enable']))
|
||||||
@@ -22,15 +23,21 @@ task_queue.put(sb.task(sb.put_hanoi.exec, sb.put_hanoi.find, cfg_main['task']['P
|
|||||||
task_queue.put(sb.task(sb.move_area.exec, sb.move_area.find, cfg_main['task']['MoveArea_enable']))
|
task_queue.put(sb.task(sb.move_area.exec, sb.move_area.find, cfg_main['task']['MoveArea_enable']))
|
||||||
task_queue.put(sb.task(sb.kick_ass.exec, sb.kick_ass.find, cfg_main['task']['KickAss_enable']))
|
task_queue.put(sb.task(sb.kick_ass.exec, sb.kick_ass.find, cfg_main['task']['KickAss_enable']))
|
||||||
|
|
||||||
|
# 将任务队列传入调度模块中
|
||||||
task_queuem_t = sb.task_queuem(task_queue)
|
task_queuem_t = sb.task_queuem(task_queue)
|
||||||
|
|
||||||
|
# 创建任务队列的工作线程
|
||||||
def worker_thread():
|
def worker_thread():
|
||||||
while task_queuem_t.exec() is True:
|
while task_queuem_t.exec() is True:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# 启动工作线程
|
||||||
worker = threading.Thread(target=worker_thread, daemon=True)
|
worker = threading.Thread(target=worker_thread, daemon=True)
|
||||||
worker.start()
|
worker.start()
|
||||||
|
|
||||||
|
# 创建主任务
|
||||||
|
main_task_t = mj.main_task(None) # TODO 初始化时传入 zmq socket 对象
|
||||||
|
|
||||||
# 主线程仅在子线程搜索 (SEARCHING) 和 空闲 (IDLE) 状态下进行操作
|
# 主线程仅在子线程搜索 (SEARCHING) 和 空闲 (IDLE) 状态下进行操作
|
||||||
while task_queuem_t.busy is True:
|
while task_queuem_t.busy is True:
|
||||||
if task_queuem_t.status is sb.task_queuem_status.EXECUTING:
|
if task_queuem_t.status is sb.task_queuem_status.EXECUTING:
|
||||||
@@ -38,6 +45,7 @@ while task_queuem_t.busy is True:
|
|||||||
else:
|
else:
|
||||||
# 模拟执行回归任务
|
# 模拟执行回归任务
|
||||||
# logger.info("***** sim huigui task *****")
|
# logger.info("***** sim huigui task *****")
|
||||||
|
main_task_t.run()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
logger.info("Main thread exit")
|
logger.info("Main thread exit")
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from simple_pid import PID
|
from simple_pid import PID
|
||||||
|
# import queue
|
||||||
|
|
||||||
class PidWrap:
|
class PidWrap:
|
||||||
def __init__(self, kp, ki, kd, setpoint=0, output_limits=1):
|
def __init__(self, kp, ki, kd, setpoint=0, output_limits=1):
|
||||||
@@ -39,9 +40,11 @@ class main_task():
|
|||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
def run(self):
|
def run(self):
|
||||||
|
# TODO 请求和解析回归值待完成
|
||||||
try:
|
try:
|
||||||
data = self.queen.get_nowait()
|
# data = self.queue.get_nowait()
|
||||||
self.parse_data(data)
|
# self.parse_data(data)
|
||||||
|
pass
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
# 运行巡线任务
|
# 运行巡线任务
|
||||||
@@ -60,6 +63,7 @@ class main_task():
|
|||||||
self.pid1.set(0.7, 0, 0)
|
self.pid1.set(0.7, 0, 0)
|
||||||
else:
|
else:
|
||||||
self.pid1.set(0.5, 0, 0)
|
self.pid1.set(0.5, 0, 0)
|
||||||
|
# TODO 待引入控制接口
|
||||||
# self.by_cmd.send_speed_x(7)
|
# self.by_cmd.send_speed_x(7)
|
||||||
pid_out = self.pid1.get(self.lane_error)
|
pid_out = self.pid1.get(self.lane_error)
|
||||||
# self.by_cmd.send_speed_omega(pid_out)
|
# self.by_cmd.send_speed_omega(pid_out)
|
||||||
Reference in New Issue
Block a user