Robot.cs
4.8 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
167
168
using Common;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DeviceLib.Model.AGV
{
[Table("tbl_robots")]
public class Robot
{
/// <summary>
/// 机器人编号
/// </summary>
[Key]
public int id { set; get; }
/// <summary>
/// 机器人IP
/// </summary>
public string ip { set; get; }
/// <summary>
/// 机器人名称
/// </summary>
public string name { set; get; }
/// <summary>
/// 所在位置
/// </summary>
public string place { set; get; }
/// <summary>
/// 是否使用调度系统
/// </summary>
public bool use_fleet { get; set; } = false;
/// <summary>
/// 在调度系统中的id
/// </summary>
public int id_in_fleet { get; set; }
/// <summary>
/// 调度系统id
/// </summary>
public int fleet_id { get; set; }
[NotMapped]
public Fleet fleet { get; set; }
/// <summary>
/// 自动模式
/// </summary>
public bool auto { get; set; }
/// <summary>
/// 是否是调试状态,true时不执行新任务
/// </summary>
public bool is_debug { get; set; }
/// <summary>
/// 机器人类型,1是mir
/// </summary>
public int type { get; set; }
/// <summary>
/// 车间编号
/// </summary>
public int workshop_id { get; set; }
[NotMapped]
public Workshop workshop { get; set; }
/// <summary>
/// 任务组id
/// </summary>
public int group_id { get; set; }
[NotMapped]
public MissionGroup mission_group { get; set; }
/// <summary>
/// IO 模块的id,多个使用#号分隔
/// </summary>
public string io_module_ids { get; set; }
[NotMapped]
public List<IOModule> io_modules { get; set; }
[NotMapped]
/// <summary>
/// AGV状态
/// </summary>
public Status status { set; get; }
/// <summary>
/// AGV任务运行状态
/// </summary>
[NotMapped]
public MissionState mission_state { set; get; }
/// <summary>
/// 机器人自定义状态
/// </summary>
[NotMapped]
public RobotState state { set; get; } = RobotState.空闲;
[NotMapped]
public Job job { get; set; }
/// <summary>
/// 负载信息
/// </summary>
[NotMapped]
public List<LoadInfo> load_infos { get; set; }
[NotMapped]
public RobotOperation operation;
#region 方法
public Robot()
{
threadGetStatus = new System.Threading.Thread(getStatus);
threadGetStatus.IsBackground = true;
threadGetStatus.Start();
}
System.Threading.Thread threadGetStatus;
private void getStatus()
{
while (true)
{
try
{
if (operation?.Get_Status(out Status status) ?? false)
{
this.status = status;
logRobotOnline(this.status, true);
}
else
{
if(this.status==null)
{
this.status = new Status();
}
else
{
logRobotOnline(this.status,false);
}
}
operation?.Get_IO_Status();
System.Threading.Thread.Sleep(1000);
}
catch (Exception ex)
{
LogUtil.Error($"【{ip}】【{name}】getStatus 出错", ex);
}
}
}
private void logRobotOnline(Status status, bool online)
{
if (!status.is_online.Equals(online))
{
if (online)
{
LogUtil.Info($"【{name}】在线");
}
else
{
LogUtil.Info($"【{name}】离线");
}
status.is_online = online;
}
}
public override bool Equals(object obj)
{
if (obj == null)
return false;
Robot agv = obj as Robot;
if (agv == null)
return false;
else
{
if (this.id.Equals(agv.id))
return true;
}
return false;
}
#endregion
}
}