Charge.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
using Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DeviceLibrary
{
public class ChargeManager
{
/// <summary>
/// 充电站
/// </summary>
public Dictionary<string, string> Station;
public const string AutoCharge1 = "AutoCharge1";
public const string AutoCharge2 = "AutoCharge2";
/// <summary>
/// 充电最大电量,小于该值或大于等待指定时间去充电
/// </summary>
public int BatteryMax { get; set; } = 90;
/// <summary>
/// 充电最小电量,小于该值直接去充电
/// </summary>
public int BatteryMin { get; set; } = 20;
public ChargeManager()
{
Station = new Dictionary<string, string>();
Station.Add(AutoCharge1, "");
//Station.Add(AutoCharge2, "");
string s = AppConfigHelper.GetValue(SettingString.ChargeThreshold);
string[] arr = s.Split(',');
BatteryMin = Convert.ToInt32(arr[0]);
BatteryMax = Convert.ToInt32(arr[1]);
}
/// <summary>
/// 在空的充电桩添加占用小车
/// </summary>
/// <param name="chargeName">占用充电桩的名称</param>
/// <returns></returns>
public bool AddOccupyInfo(string chargeName,string agvName)
{
if (agvName.Equals(""))
return false;
if (Station.Keys.Contains(chargeName))
{
Station[chargeName] = agvName;
return true;
}
return false;
}
private static object loc = new object();
/// <summary>
/// 清除agv占用信息
/// </summary>
/// <param name="chargeName"></param>
/// <returns></returns>
public void DelOccupyInfo(Agv_Info agv)
{
lock(loc)
{
foreach (string item in Station.Keys)
{
if (Station[item].Equals(agv.Name))
{
Station[item] = "";
agv.IsInCharge = false;
break;
}
}
}
}
public void ClearAllOccupyInfo()
{
lock(loc)
{
if (Station != null && Station.Count > 0)
{
foreach (var item in Station.Keys)
{
Station[item] = "";
}
}
}
}
/// <summary>
/// 检查充电桩是否有小车占用
/// </summary>
/// <param name="agv"></param>
/// <returns></returns>
public bool HasEmptyChargeStation(Agv_Info agv)
{
//lock(loc)
//{
// if (SettingString.FixedCharge_AGV_IPs.Contains(agv.IP))//固定充电小车
// return true;
// else
// {
// if (Station[AutoCharge2].Equals(""))
// {
// return true;
// }
// }
//}
//return false;
return true;
}
/// <summary>
/// 开始充电任务
/// </summary>
/// <param name="agv"></param>
/// <returns>充电任务结果</returns>
public bool StartCharge(Agv_Info agv)
{
bool rtn;
string log;
agv.Place = "";
lock(loc)
{
foreach (string chargeStation in Station.Keys)
{
if (Station[chargeStation].Equals(""))
{
rtn = MissionSys.AssignMission(agv, chargeStation);
if (rtn)
{
Station[chargeStation] = agv.Name;
agv.Place = SettingString.AutoCharge;
log = string.Format("{0} {1}", agv.Name, chargeStation);
LogUtil.info(log);
MiR_API.State_Ready(agv);
agv.IsInCharge = true;
return true;
}
else
{
Station[chargeStation] = "";
log = string.Format("{0} {1}失败", agv.Name, chargeStation);
LogUtil.info(log);
}
return false;
}
}
}
return false;
}
}
}