RobotManager.cs
5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
using Common;
using DeviceLib.DB.Config;
using DeviceLib.Model.AGV;
using System;
using System.Collections.Generic;
namespace DeviceLib.BLL
{
public class RobotManager
{
static List<Robot> robots;
static int lowBattery = 30;
/// <summary>
/// 加载配置
/// </summary>
public static void Load()
{
//ConfigOperation.GetRobots();
robots = ConfigOperation.GetRobots() ?? new List<Robot>();
LogUtil.Info("机器人配置加载成功!");
}
/// <summary>
/// 获取所有机器人
/// </summary>
/// <returns></returns>
public static List<Robot> GetAllRobots()
{
return robots;
}
public static Robot GetRobot(int id)
{
return robots.Find(s => s.id == id);
}
public static Robot GetRobot(string ip)
{
return robots.Find(s => s.ip == ip);
}
/// <summary>
/// 查询机充电桩上是否有机器人
/// </summary>
/// <param name="nodeId"></param>
/// <returns>true:有机器人</returns>
public static bool CheckRobotInChargePile(int nodeId)
{
Robot robot = robots.Find(s => s.job != null && (s.job is ChargeJob && s.job.JobParam.CurDstNode.Id.Equals(nodeId)));
return robot != null;
}
/// <summary>
/// 查询机待机点上是否有机器人
/// </summary>
/// <param name="nodeId"></param>
/// <returns>true:有机器人</returns>
public static bool CheckRobotInStandbyPile(int nodeId)
{
Robot robot = robots.Find(s => s.job != null && s.job is StandbyJob && s.job.JobParam.CurDstNode.Id.Equals(nodeId));
return robot != null;
}
/// <summary>
/// 检查是否有机器人在当前节点
/// </summary>
/// <param name="nodename"></param>
/// <returns></returns>
public static bool RobotIsInNode(string nodename)
{
return robots.Find(s=>s?.mission_state?.node_name.Equals(nodename) ??false)!=null;
}
/// <summary>
/// 获取可执行任务的机器人
/// </summary>
/// <param name="workshop_id">车间编号:默认0,表示不区分车间</param>
/// <returns></returns>
public static Robot GetReadyRobot(int workshop_id = 0)
{
var finds = robots.FindAll(s => s.status.battery_percentage > lowBattery);
finds.FindAll(s => s.state.Equals(RobotState.待机中) || s.state.Equals(RobotState.充电中));
if (workshop_id > 0)
return finds.Find(s => s.workshop_id == workshop_id);
else if (finds.Count > 0)
return finds[0];
else
return null;
}
static Robot getRobot(int id)
{
return robots.Find(s => s.id.Equals(id));
}
public static void SetRobot(Robot robot)
{
ConfigOperation.SetRobot(robot);
}
public static void SetDebug(int id, bool debug)
{
Robot robot = getRobot(id);
if (robot != null)
{
robot.is_debug = debug;
SetRobot(robot);
LogUtil.Info($"设置【{robot.name}】调试模式={debug}");
}
}
public static void SetLoadInfo(int robotId, int pos, ShelfType type, string shelf_id = "")
{
Robot robot = getRobot(robotId);
if (robot != null)
{
LoadInfo loadInfo = robot.load_infos.Find(s => s.pos == pos);
if (loadInfo != null)
{
loadInfo.shelf_type = type;
loadInfo.shelf_id = shelf_id;
SetRobot(robot);
LogUtil.Info($"设置【{robot.name}】负载状态【{loadInfo}】");
}
else
{
LogUtil.Error($"设置【{robot.name}】负载状态失败【shelf_type={type.ToString()},shelf_id={shelf_id}】,因未找到pos={pos}");
}
}
}
public static void SetAuto(int id, bool auto)
{
Robot robot = getRobot(id);
if (robot != null)
{
robot.auto = auto;
SetRobot(robot);
LogUtil.Info($"设置【{robot.name}】自动模式={auto}");
}
}
public static void UploadState(Robot robot)
{
try
{
}
catch(Exception ex)
{
}
}
static MissionState getMissionState(int id)
{
Robot robot = getRobot(id);
if (robot != null)
{
return robot.mission_state;
}
return null;
}
static Job getJob(int id)
{
Robot robot = getRobot(id);
if (robot != null)
{
return robot.job;
}
return null;
}
public static void ClearBoxBind(Robot robot,string rfid)
{
HttpManager.ClearBoxBind(rfid,robot.name);
}
}
}