Commit 32a70733 顾剑亮

upload

1 个父辈 cca55a28
...@@ -45,6 +45,9 @@ ...@@ -45,6 +45,9 @@
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Configuration" /> <Reference Include="System.Configuration" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.ServiceModel.Web" />
<Reference Include="System.Web" /> <Reference Include="System.Web" />
<Reference Include="System.Web.Extensions" /> <Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
...@@ -61,8 +64,8 @@ ...@@ -61,8 +64,8 @@
<Compile Include="BLL\Control.cs" /> <Compile Include="BLL\Control.cs" />
<Compile Include="BLL\Common.cs" /> <Compile Include="BLL\Common.cs" />
<Compile Include="Model\MiR_API.cs" /> <Compile Include="Model\MiR_API.cs" />
<Compile Include="Model\job\4CFlowJob.cs" /> <Compile Include="Model\job\TakeOldJob.cs" />
<Compile Include="Model\job\4DFlowJob.cs" /> <Compile Include="Model\job\SendNewJob.cs" />
<Compile Include="Model\job\ChargeJob.cs" /> <Compile Include="Model\job\ChargeJob.cs" />
<Compile Include="Model\AgvInfo.cs" /> <Compile Include="Model\AgvInfo.cs" />
<Compile Include="FrmMain.cs"> <Compile Include="FrmMain.cs">
...@@ -76,6 +79,7 @@ ...@@ -76,6 +79,7 @@
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Model\job\StandbyJob.cs" /> <Compile Include="Model\job\StandbyJob.cs" />
<Compile Include="BLL\WebService.cs" />
<EmbeddedResource Include="FrmMain.resx"> <EmbeddedResource Include="FrmMain.resx">
<DependentUpon>FrmMain.cs</DependentUpon> <DependentUpon>FrmMain.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
......
...@@ -38,5 +38,6 @@ ...@@ -38,5 +38,6 @@
</log4net> </log4net>
<appSettings> <appSettings>
<add key="FLEET_IP" value="10.85.199.3" /> <add key="FLEET_IP" value="10.85.199.3" />
<add key="WebService" value="http://10.85.196.40:8088/"/>
</appSettings> </appSettings>
</configuration> </configuration>
\ No newline at end of file \ No newline at end of file
...@@ -9,12 +9,147 @@ namespace AGVControl_Steel ...@@ -9,12 +9,147 @@ namespace AGVControl_Steel
public static class Common public static class Common
{ {
public static List<Model.AgvInfo> agvInfos; public static List<Model.AgvInfo> agvInfos;
public static Dictionary<string, string> agvMissions;
public static BLL.Control control; public static BLL.Control control;
public static Model.MiR_API mir; public static Model.MiR_API mir;
public static BLL.WebService service;
public static bool serverOpen;
public static System.Configuration.Configuration appConfig; public static System.Configuration.Configuration appConfig;
public static log4net.ILog log; public static log4net.ILog log;
public static readonly string CONFIG_AGV_NAME = Environment.CurrentDirectory + "\\Config\\AgvName.csv"; public const string MISSION_MOVE_4C_4D = "MoveDoor-4C-4D";
public static readonly string CONFIG_AGV_MISSION = Environment.CurrentDirectory + "\\Config\\AgvMission.csv"; public const string MISSION_MOVE_4D_4C = "MoveDoor-4D-4C";
public const string MISSION_CHARGE = "ChargeSteel";
public const string MISSION_MOVE_STANDBY = "MoveStandby";
public static readonly string PATH_AGV_NAME = Environment.CurrentDirectory + "\\Config\\AgvName.csv";
public static readonly string PATH_AGV_MISSION = Environment.CurrentDirectory + "\\Config\\AgvMission.csv";
public delegate void AgvChangedEvent(int agvIndex);
public static event AgvChangedEvent AgvChanged;
public static event AgvChangedEvent AgvOnline;
public static class WebService
{
private static System.ServiceModel.Web.WebServiceHost _serviceHost;
public static bool Open(string url)
{
try
{
service = new BLL.WebService();
_serviceHost = new System.ServiceModel.Web.WebServiceHost(service, new Uri(url));
_serviceHost.Open();
log.Info("Web服务已开启");
return true;
}
catch (Exception ex)
{
log.Error("WebService Open", ex);
return false;
}
}
public static void Close()
{
if (_serviceHost != null)
_serviceHost.Close();
log.Info("Web服务已关闭");
}
}
/// <summary>
/// 获取小车的状态
/// </summary>
/// <param name="info"></param>
public static void GetAgvState(ref Model.AgvInfo info)
{
bool rtn = CheckOnline(ref info);
if (!rtn) return;
rtn = mir.Get_State(info.IP, info.Authorization, out int stateID, out string stateText, out int battery, out string missionText);
log.Debug(string.Format("{0}[{1}] Get_State{6} stateID={2}, stateText={3}, battery={4}, missionText={5}", info.Name, info.IP, stateID, stateText, battery, missionText, rtn));
if (rtn)
{
info.StateID = stateID;
info.StateText = stateText;
info.Battery = battery;
info.MissionText = missionText;
string ip = info.IP;
int idx = agvInfos.FindIndex(s => s.IP == ip);
if (idx > -1) AgvChanged?.Invoke(idx);
}
}
private static bool CheckOnline(ref Model.AgvInfo info)
{
bool rtn = mir.CheckIP(info.IP);
if (rtn)
{
if (!info.IsOnline)
{
info.IsOnline = true;
string ip = info.IP;
int idx = agvInfos.FindIndex(s => s.IP == ip);
if (idx > -1) AgvOnline?.Invoke(idx);
rtn = mir.Get_IO_Modules(info.IP, info.Authorization, out string[] guid);
if (rtn) info.IOGuid = guid[0];
}
log.Debug(string.Format("{0}[{1}] 在线", info.Name, info.IP));
}
else
{
if (info.IsOnline)
{
info.IsOnline = false;
string ip = info.IP;
int idx = agvInfos.FindIndex(s => s.IP == ip);
if (idx > -1) AgvOnline?.Invoke(idx);
}
log.Debug(string.Format("{0}[{1}] 脱机", info.Name, info.IP));
}
return rtn;
}
}
/// <summary>
/// 任务执行的状态
/// </summary>
public enum MissionState
{
/// <summary>
/// 终止
/// </summary>
Aborted,
/// <summary>
/// 执行中
/// </summary>
Executing,
/// <summary>
/// 已完成
/// </summary>
Done
}
public enum StateID
{
None = 0,
Starting,
ShuttingDown,
Ready,
Pause,
Executing,
Aborted,
Completed,
Docked,
Docking,
EmergencyStop,
ManualControl,
Error
} }
} }
...@@ -11,38 +11,13 @@ namespace BLL ...@@ -11,38 +11,13 @@ namespace BLL
/// </summary> /// </summary>
public class Control public class Control
{ {
private Timer timerState;
private Timer timerCall; private Timer timerCall;
private bool[] agvState; //agv状态是否获取完成
public delegate void AgvChangedEvent(int agvIndex);
//public delegate void AgvMissionEvent();
public event AgvChangedEvent AgvChanged;
public event AgvChangedEvent AgvOnline;
//public event AgvMissionEvent AgvMissionChanged;
/// <summary> /// <summary>
/// 控制类 /// 控制类
/// </summary> /// </summary>
public Control() public Control()
{ {
Dictionary<string, string> mission = new Dictionary<string, string>();
string[] lines = System.IO.File.ReadAllLines(Common.CONFIG_AGV_MISSION, System.Text.Encoding.UTF8);
for (int i = 0; i < lines.Length; i++)
{
string[] str = lines[i].Split(',');
if (str.Length != 2) continue;
mission.Add(str[0], str[1]);
}
Common.log.Info("读取配置文件 " + Common.CONFIG_AGV_MISSION);
Common.mir = new MiR_API
{
FleetIP = Common.appConfig.AppSettings.Settings["FLEET_IP"].Value,
MissionList = mission
};
agvState = new bool[Common.agvInfos.Count];
ThreadPool.SetMaxThreads(5, 5); //线程池最大数量 ThreadPool.SetMaxThreads(5, 5); //线程池最大数量
} }
...@@ -51,9 +26,7 @@ namespace BLL ...@@ -51,9 +26,7 @@ namespace BLL
/// </summary> /// </summary>
public void Start() public void Start()
{ {
agvState = new bool[Common.agvInfos.Count]; timerCall = new Timer(CallProcess, null, 0, 2000);
timerState = new Timer(StateProcess, null, 0, 2000);
timerCall = new Timer(CallProcess, null, 0, 100);
} }
/// <summary> /// <summary>
...@@ -61,79 +34,41 @@ namespace BLL ...@@ -61,79 +34,41 @@ namespace BLL
/// </summary> /// </summary>
public void Stop() public void Stop()
{ {
timerState.Dispose();
timerCall.Dispose(); timerCall.Dispose();
} }
private void CallProcess(object obj)
private void StateProcess(object obj)
{ {
for (int i = 0; i < agvState.Length; i++) for (int i = 0; i < Common.agvInfos.Count; i++)
{ {
if (agvState[i]) continue;
agvState[i] = true;
AgvInfo info = Common.agvInfos[i]; AgvInfo info = Common.agvInfos[i];
bool rtn = CheckOnline(ref info); if (info.IsCall) continue;
if (!rtn) continue;
rtn = Common.mir.Get_State(info.IP, info.Authorization, out int stateID, out string stateText, out int battery, out string missionText); try
Common.log.Debug(string.Format("{0}[{1}] Get_State{6} stateID={2}, stateText={3}, battery={4}, missionText={5}", info.Name, info.IP, stateID, stateText, battery, missionText, rtn));
if (rtn)
{ {
info.StateID = stateID; info.IsCall = true;
info.StateText = stateText; if (!info.IsOnline) continue; //脱机
info.Battery = battery; if (!info.IsAuto) continue; //手动
info.MissionText = missionText;
AgvChanged?.Invoke(i);
}
agvState[i] = false;
}
}
private void CallProcess(object obj) if (info.CurrentJob == null)
{ {
info.CurrentJob = new StandbyJob();
} }
else
private bool CheckOnline(ref AgvInfo info)
{
bool rtn = Common.mir.CheckIP(info.IP);
if (rtn)
{
if (!info.IsOnline)
{ {
info.IsOnline = true; info.CurrentJob = info.CurrentJob.Execute(info);
string ip = info.IP;
int idx = Common.agvInfos.FindIndex(s => s.IP == ip);
if (idx > -1) AgvOnline?.Invoke(idx);
rtn = Common.mir.Get_IO_Modules(info.IP, info.Authorization, out string[] guid);
if (rtn) info.IOGuid = guid[0];
} }
Common.log.Debug(string.Format("{0}[{1}] 在线", info.Name, info.IP));
} }
else catch (Exception ex)
{ {
if (info.IsOnline) Common.log.Error("CallProcess " + info.FullName, ex);
}
finally
{ {
info.IsOnline = false; info.IsCall = false;
string ip = info.IP;
int idx = Common.agvInfos.FindIndex(s => s.IP == ip);
if (idx > -1) AgvOnline?.Invoke(idx);
} }
Common.log.Debug(string.Format("{0}[{1}] 脱机", info.Name, info.IP));
} }
return rtn;
} }
} }
} }
\ No newline at end of file \ No newline at end of file
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Runtime.Serialization;
using System.ServiceModel.Activation;
using System.IO;
using AGVControl_Steel;
namespace BLL
{
[ServiceContract(Name = "Services")]
internal interface IWebService
{
[OperationContract]
[WebGet(UriTemplate = "StealAgv/takeOld?from={place}", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
Result TakeOldGet(string from);
[OperationContract]
[WebGet(UriTemplate = "StealAgv/sendNew?from={from}&placeList={list}", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
Result SendNewGet(string from, string list);
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "StealAgv/takeOld", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
Result TakeOldPost(Stream info);
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "StealAgv/sendNew", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
Result SendNewPost(Stream info);
}
[DataContract]
public class Result
{
[DataMember]
public int Code { get; set; }
[DataMember]
public string Msg { get; set; }
}
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single, IncludeExceptionDetailInFaults = true)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class WebService : IWebService
{
//public delegate void UpdateLightEvent();
//public event UpdateLightEvent UpdateLight;
public WebService()
{
}
public Result TakeOldGet(string from)
{
Common.log.Info("钢网 takeOld[GET] from=" + from);
Result res = new Result();
res.Code = 0;
res.Msg = "OK";
return res;
}
public Result SendNewGet(string from, string list)
{
Common.log.Info("钢网 sendNew[GET] from=" + from + " placeList=" + list);
Result res = new Result();
res.Code = 0;
res.Msg = "OK";
return res;
}
public Result TakeOldPost(Stream info)
{
StreamReader sr = new StreamReader(info);
string s = sr.ReadToEnd();
Common.log.Info("钢网 takeOld[POST] " + s);
Result res = new Result();
res.Code = 0;
res.Msg = "OK";
return res;
}
public Result SendNewPost(Stream info)
{
StreamReader sr = new StreamReader(info);
string s = sr.ReadToEnd();
Common.log.Info("钢网 sendNew[POST]" + s);
Result res = new Result();
res.Code = 0;
res.Msg = "OK";
return res;
}
}
}
...@@ -38,8 +38,8 @@ namespace AGVControl_Steel ...@@ -38,8 +38,8 @@ namespace AGVControl_Steel
DgvName.Rows[i].HeaderCell.Value = (i + 1).ToString(); DgvName.Rows[i].HeaderCell.Value = (i + 1).ToString();
} }
Common.control.AgvChanged += Control_AgvChanged; Common.AgvChanged += Control_AgvChanged;
Common.control.AgvOnline += Control_AgvOnline; Common.AgvOnline += Control_AgvOnline;
Common.control.Start(); Common.control.Start();
} }
...@@ -50,12 +50,12 @@ namespace AGVControl_Steel ...@@ -50,12 +50,12 @@ namespace AGVControl_Steel
if (e.ColumnIndex == DgvName.Columns.Count - 1) //最后一列,自动/手动 if (e.ColumnIndex == DgvName.Columns.Count - 1) //最后一列,自动/手动
{ {
info.IsUse = !info.IsUse; info.IsAuto = !info.IsAuto;
DgvName.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = info.IsUse.ToString(); DgvName.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = info.IsAuto.ToString();
Common.appConfig.AppSettings.Settings[info.FleetID].Value = info.IsUse.ToString(); Common.appConfig.AppSettings.Settings[info.FleetID].Value = info.IsAuto.ToString();
Common.appConfig.Save(); Common.appConfig.Save();
System.Configuration.ConfigurationManager.RefreshSection("appSettings"); System.Configuration.ConfigurationManager.RefreshSection("appSettings");
Common.log.Info("手动修改 " + info.Name + " IsUse=" + info.IsUse); Common.log.Info("手动修改 " + info.Name + " IsUse=" + info.IsAuto);
} }
} }
} }
......
...@@ -20,6 +20,16 @@ namespace Model ...@@ -20,6 +20,16 @@ namespace Model
/// </summary> /// </summary>
public string IP { set; get; } = ""; public string IP { set; get; } = "";
/// <summary> /// <summary>
/// 带IP的完整名称
/// </summary>
public string FullName
{
get
{
return string.Format("{0}[{1}]", Name, IP);
}
}
/// <summary>
/// 授权码 /// 授权码
/// </summary> /// </summary>
public string Authorization { set; get; } = ""; public string Authorization { set; get; } = "";
...@@ -28,9 +38,9 @@ namespace Model ...@@ -28,9 +38,9 @@ namespace Model
/// </summary> /// </summary>
public string Place { set; get; } = ""; public string Place { set; get; } = "";
/// <summary> /// <summary>
/// 是否使用 /// 是否自动使用
/// </summary> /// </summary>
public bool IsUse { set; get; } = false; public bool IsAuto { set; get; } = false;
/// <summary> /// <summary>
/// 是否在线 /// 是否在线
/// </summary> /// </summary>
...@@ -60,9 +70,13 @@ namespace Model ...@@ -60,9 +70,13 @@ namespace Model
/// </summary> /// </summary>
public string IOGuid { set; get; } = ""; public string IOGuid { set; get; } = "";
/// <summary> /// <summary>
/// 是否正在被调用
/// </summary>
public bool IsCall { set; get; } = false;
/// <summary>
/// 当前的工作 /// 当前的工作
/// </summary> /// </summary>
public IJob CurrentJob { set; get; } public Job CurrentJob { set; get; } = null;
/// <summary> /// <summary>
/// 表格行显示 /// 表格行显示
...@@ -70,7 +84,7 @@ namespace Model ...@@ -70,7 +84,7 @@ namespace Model
/// <returns></returns> /// <returns></returns>
public string[] ToRow() public string[] ToRow()
{ {
string[] arr = new string[] { Name, Place, StateText, MissionText, Battery.ToString(), IsOnline.ToString(), IsUse.ToString() }; string[] arr = new string[] { Name, Place, StateText, MissionText, Battery.ToString(), IsOnline.ToString(), IsAuto.ToString() };
return arr; return arr;
} }
......
...@@ -6,155 +6,182 @@ namespace Model ...@@ -6,155 +6,182 @@ namespace Model
/// <summary> /// <summary>
/// 充电工作 /// 充电工作
/// </summary> /// </summary>
public class ChargeJob : IJob public class ChargeJob : Job
{ {
private bool _mayBreak;
private string id; private string id;
//private bool sendFailed; private JobStep<ChargeStep> chargeStep;
private JobStep<CHARGE_STEP> chargeStep = new JobStep<CHARGE_STEP>(CHARGE_STEP.NONE);
/// <summary> /// <summary>
/// 充电工作 /// 充电工作
/// </summary> /// </summary>
public ChargeJob() public ChargeJob()
{ {
_mayBreak = false; chargeStep = new JobStep<ChargeStep>(ChargeStep.None);
} }
/// <summary> /// <summary>
/// 任务是否执行 /// 任务执行
/// </summary>
public bool IsProcess { get; }
/// <summary>
/// 任务是否结束
/// </summary> /// </summary>
public bool IsEnd /// <param name="info"></param>
public override Job Execute(AgvInfo info)
{ {
get if (chargeStep.IsEqual(ChargeStep.None))
{ {
return chargeStep.IsEqual(CHARGE_STEP.END); None(info);
} }
else if (chargeStep.IsEqual(ChargeStep.WaitWorkshopDoor))
{
WorkshopDoor(info);
} }
else if (chargeStep.IsEqual(ChargeStep.WaitChargeStation))
/// <summary>
/// 任务运行信息
/// </summary>
public string RunInfo { get => throw new NotImplementedException(); }
/// <summary>
/// 任务能否中断
/// </summary>
public bool MayBreak
{ {
get ChargeStation(info);
}
else if (chargeStep.IsEqual(ChargeStep.Charging))
{
Charging(info);
}
else if (chargeStep.IsEqual(ChargeStep.End))
{ {
return _mayBreak; Common.log.Info(info.FullName + "ChargeJob结束,切换StandbyJob");
return new StandbyJob();
} }
return this;
} }
/// <summary>
/// 任务执行
/// </summary>
/// <param name="info"></param>
public void Execute(AgvInfo info)
{
bool rtn;
if (chargeStep.IsEqual(CHARGE_STEP.NONE))
{ private void None(AgvInfo info)
_mayBreak = false;
chargeStep.NextStep(CHARGE_STEP.SEND_MISSION);
}
else if (chargeStep.IsEqual(CHARGE_STEP.SEND_MISSION))
{ {
if (info.Place.StartsWith("4C")) //4C车间需要到4D车间充电 if (info.Place.StartsWith("4C")) //4C车间需要到4D车间充电
{ {
rtn = Common.mir.Add_Mission_Fleet(info.FleetID, info.Authorization, "MoveDoor-4C-4D", out id); rtn = Common.mir.Add_Mission_Fleet(info.FleetID, info.Authorization, Common.MISSION_MOVE_4C_4D, out id);
if (rtn) chargeStep.NextStep(CHARGE_STEP.MOVE_WORKSHOP_DOOR); if (rtn)
{
chargeStep.NextStep(ChargeStep.WaitWorkshopDoor);
chargeStep.Msg = info.FullName + "在4C车间,去充电位,先过4D门";
}
else
{
chargeStep.Msg = info.FullName + "发送" + Common.MISSION_MOVE_4C_4D + "任务失败";
}
} }
else if (info.Place.StartsWith("4D")) else if (info.Place.StartsWith("4D"))
{ {
rtn = Common.mir.Add_Mission_Fleet(info.FleetID, info.Authorization, "ChargeSteel", out id); rtn = Common.mir.Add_Mission_Fleet(info.FleetID, info.Authorization, Common.MISSION_CHARGE, out id);
if (rtn) chargeStep.NextStep(CHARGE_STEP.MOVE_CHARGE_STATION); if (rtn)
{
chargeStep.NextStep(ChargeStep.WaitChargeStation);
chargeStep.Msg = info.FullName + "在4D车间,去充电位";
}
else
{
chargeStep.Msg = info.FullName + "发送" + Common.MISSION_CHARGE + "任务失败";
}
} }
else else
{ {
Common.log.Error(string.Format("ChargeJob Error {0} Place={1}", info.Name, info.Place)); Common.log.Error(string.Format("ChargeJob Error {0} Place={1}", info.FullName, info.Place));
} }
} }
else if (chargeStep.IsEqual(CHARGE_STEP.MOVE_WORKSHOP_DOOR))
private void WorkshopDoor(AgvInfo info)
{ {
rtn = Common.mir.Get_MissionState_Fleet(info.Authorization, id, out string state); rtn = Common.mir.Get_MissionState_Fleet(info.Authorization, id, out string state);
if (rtn) if (rtn)
{ {
if (state == MissionState.Done.ToString()) if (state == MissionState.Done.ToString())
{ {
rtn = Common.mir.Add_Mission_Fleet(info.FleetID, info.Authorization, "ChargeSteel", out string value); rtn = Common.mir.Add_Mission_Fleet(info.FleetID, info.Authorization, Common.MISSION_CHARGE, out id);
if (rtn) if (rtn)
{ {
id = value; chargeStep.NextStep(ChargeStep.WaitChargeStation);
chargeStep.NextStep(CHARGE_STEP.MOVE_CHARGE_STATION); chargeStep.Msg = info.FullName + "在4D车间,去充电位";
} }
else
{
chargeStep.Msg = info.FullName + "发送" + Common.MISSION_CHARGE + "任务失败";
} }
} }
else if (state == MissionState.Aborted.ToString())
{
chargeStep.Msg = info.FullName + "任务状态" + MissionState.Aborted.ToString();
}
} }
else if (chargeStep.IsEqual(CHARGE_STEP.MOVE_CHARGE_STATION)) else
{ {
chargeStep.Msg = info.FullName + "获取任务状态id[" + id + "]失败";
}
} }
else if (chargeStep.IsEqual(CHARGE_STEP.CHARGING))
private void ChargeStation(AgvInfo info)
{
rtn = Common.mir.Get_Register(info.IP, info.Authorization, 20, out int value);
if (rtn)
{ {
if (value == 1)
{
chargeStep.NextStep(ChargeStep.Charging);
chargeStep.Msg = info.FullName + "到达充电位,准备充电";
}
} }
else if (chargeStep.IsEqual(CHARGE_STEP.MOVE_STANDBY)) else
{
chargeStep.Msg = info.FullName + "获取PLC20失败";
}
}
private void Charging(AgvInfo info)
{ {
Common.GetAgvState(ref info);
if (info.Battery == 100)
{
chargeStep.NextStep(ChargeStep.End);
chargeStep.Msg = info.FullName + "电量100%,充电工作结束";
} }
else if (chargeStep.IsEqual(CHARGE_STEP.END)) else if (info.Battery > 80)
{ {
} }
} }
/// <summary> /// <summary>
/// 充电步骤 /// 充电步骤
/// </summary> /// </summary>
private enum CHARGE_STEP private enum ChargeStep
{ {
/// <summary> /// <summary>
/// 无 /// 无
/// </summary> /// </summary>
NONE, None,
/// <summary> /// <summary>
/// 充电结束 /// 充电结束
/// </summary> /// </summary>
END, End,
/// <summary> /// <summary>
/// 移动到车间门口 /// 移动到车间门口
/// </summary> /// </summary>
MOVE_WORKSHOP_DOOR, WaitWorkshopDoor,
/// <summary> /// <summary>
/// 移动到充电位置 /// 移动到充电位置
/// </summary> /// </summary>
MOVE_CHARGE_STATION, WaitChargeStation,
/// <summary> /// <summary>
/// 移动到待机位 /// 移动到待机位
/// </summary> /// </summary>
MOVE_STANDBY, WaitStandby,
/// <summary> /// <summary>
/// 充电中 /// 充电中
/// </summary> /// </summary>
CHARGING, Charging,
/// <summary> /// <summary>
/// 发送任务 /// 发送任务
/// </summary> /// </summary>
SEND_MISSION SendMission
}
private enum MissionState
{
Aborted,
Executing,
Done
} }
} }
......
using System; 
namespace Model namespace Model
{ {
/// <summary> /// <summary>
/// 小车的工作 /// 小车的工作
/// </summary> /// </summary>
public interface IJob public abstract class Job
{ {
/// <summary> /// <summary>
/// 任务是否执行 /// 任务是否执行
/// </summary> /// </summary>
public bool IsProcess { get; } public bool IsProcess { set; get; }
/// <summary> /// <summary>
/// 任务是否结束 /// 任务是否结束
/// </summary> /// </summary>
public bool IsEnd { get; } public bool IsEnd { set; get; }
/// <summary>
/// 任务能否中断
/// </summary>
public bool MayBreak { get; }
/// <summary> /// <summary>
/// 任务运行信息 /// 任务运行信息
/// </summary> /// </summary>
public string RunInfo { get; } public string RunInfo { set; get; }
/// <summary> /// <summary>
/// 任务执行 /// 任务执行
/// </summary> /// </summary>
/// <param name="info"></param> /// <param name="info"></param>
public void Execute(AgvInfo info); public abstract Job Execute(AgvInfo info);
internal bool rtn;
} }
} }
...@@ -10,6 +10,7 @@ namespace Model ...@@ -10,6 +10,7 @@ namespace Model
{ {
private T _step; private T _step;
private DateTime _time; private DateTime _time;
private string _msg = "";
/// <summary> /// <summary>
/// 小车工作步骤 /// 小车工作步骤
...@@ -55,5 +56,28 @@ namespace Model ...@@ -55,5 +56,28 @@ namespace Model
_time = DateTime.Now; _time = DateTime.Now;
} }
/// <summary>
/// 当前信息
/// </summary>
public string Msg
{
get
{
return _msg;
}
set
{
if (!string.IsNullOrEmpty(value))
{
//与上一个消息不一样才打印
if (!value.Equals(_msg))
{
AGVControl_Steel.Common.log.Info(_step.ToString() + ":" + value);
}
}
_msg = value;
}
}
} }
} }
\ No newline at end of file \ No newline at end of file

\ No newline at end of file \ No newline at end of file
using AGVControl_Steel;
namespace Model
{
public class StandbyJob : Job
{
private string id;
private JobStep<StandbyStep> standbyStep;
public StandbyJob()
{
standbyStep = new JobStep<StandbyStep>(StandbyStep.None);
}
public override Job Execute(AgvInfo info)
{
if (standbyStep.IsEqual(StandbyStep.None))
{
rtn = Common.mir.Add_Mission_Fleet(info.FleetID, info.Authorization, Common.MISSION_MOVE_STANDBY, out id);
if (rtn)
{
standbyStep.NextStep(StandbyStep.Standby);
standbyStep.Msg = info.FullName + "回待机位";
}
else
{
standbyStep.Msg = info.FullName + "发送" + Common.MISSION_MOVE_STANDBY + "任务失败";
}
}
else if (standbyStep.IsEqual(StandbyStep.Standby))
{
rtn = Common.mir.Get_MissionState_Fleet(info.Authorization, id, out string state);
if (rtn)
{
if (state == MissionState.Done.ToString())
{
standbyStep.NextStep(StandbyStep.End);
standbyStep.Msg = info.FullName + "已在待机位";
}
else if (state == MissionState.Aborted.ToString())
{
standbyStep.Msg = info.FullName + "任务状态" + MissionState.Aborted.ToString();
}
}
else
{
standbyStep.Msg = info.FullName + "获取任务状态id[" + id + "]失败";
}
}
else if (standbyStep.IsEqual(StandbyStep.End))
{
}
return this;
}
private enum StandbyStep
{
None,
Standby,
End
}
}
}
\ No newline at end of file \ No newline at end of file
...@@ -20,7 +20,8 @@ namespace AGVControl_Steel ...@@ -20,7 +20,8 @@ namespace AGVControl_Steel
Common.log.Info("=====程序开始====="); Common.log.Info("=====程序开始=====");
ReadConfig(); ReadConfig();
Common.control = new BLL.Control(); Common.control = new BLL.Control();
Common.mir = new Model.MiR_API { FleetIP = Common.appConfig.AppSettings.Settings["FLEET_IP"].Value, MissionList = Common.agvMissions };
Common.serverOpen = Common.WebService.Open(Common.appConfig.AppSettings.Settings["WebService"].Value);
Application.Run(new FrmMain()); Application.Run(new FrmMain());
...@@ -34,7 +35,7 @@ namespace AGVControl_Steel ...@@ -34,7 +35,7 @@ namespace AGVControl_Steel
{ {
//AGV小车信息 //AGV小车信息
Common.agvInfos = new System.Collections.Generic.List<Model.AgvInfo>(); Common.agvInfos = new System.Collections.Generic.List<Model.AgvInfo>();
string[] lines = System.IO.File.ReadAllLines(Common.CONFIG_AGV_NAME, System.Text.Encoding.UTF8); string[] lines = System.IO.File.ReadAllLines(Common.PATH_AGV_NAME, System.Text.Encoding.UTF8);
for (int i = 0; i < lines.Length; i++) for (int i = 0; i < lines.Length; i++)
{ {
string[] str = lines[i].Split(','); string[] str = lines[i].Split(',');
...@@ -56,11 +57,21 @@ namespace AGVControl_Steel ...@@ -56,11 +57,21 @@ namespace AGVControl_Steel
Name = str[1], Name = str[1],
IP = str[2], IP = str[2],
Authorization = str[3], Authorization = str[3],
IsUse = Convert.ToBoolean(isUse) IsAuto = Convert.ToBoolean(isUse)
}; };
Common.agvInfos.Add(info); Common.agvInfos.Add(info);
} }
Common.log.Info("读取配置文件 " + Common.CONFIG_AGV_NAME); Common.log.Info("读取配置文件 " + Common.PATH_AGV_NAME);
Common.agvMissions = new System.Collections.Generic.Dictionary<string, string>();
lines = System.IO.File.ReadAllLines(Common.PATH_AGV_MISSION, System.Text.Encoding.UTF8);
for (int i = 0; i < lines.Length; i++)
{
string[] str = lines[i].Split(',');
if (str.Length != 2) continue;
Common.agvMissions.Add(str[0], str[1]);
}
Common.log.Info("读取配置文件 " + Common.PATH_AGV_MISSION);
} }
catch (Exception ex) catch (Exception ex)
......
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<configuration> <configuration>
<configSections> <configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
</log4net> </log4net>
<appSettings> <appSettings>
<add key="FLEET_IP" value="10.85.199.3" /> <add key="FLEET_IP" value="10.85.199.3" />
<add key="32" value="false" /> <add key="WebService" value="http://10.85.196.40:8088/"/>
<add key="25" value="false" />
</appSettings> </appSettings>
</configuration> </configuration>
\ No newline at end of file \ No newline at end of file
...@@ -29,6 +29,32 @@ ...@@ -29,6 +29,32 @@
公共类 公共类
</summary> </summary>
</member> </member>
<member name="M:AGVControl_Steel.Common.GetAgvState(Model.AgvInfo@)">
<summary>
获取小车的状态
</summary>
<param name="info"></param>
</member>
<member name="T:AGVControl_Steel.MissionState">
<summary>
任务执行的状态
</summary>
</member>
<member name="F:AGVControl_Steel.MissionState.Aborted">
<summary>
终止
</summary>
</member>
<member name="F:AGVControl_Steel.MissionState.Executing">
<summary>
执行中
</summary>
</member>
<member name="F:AGVControl_Steel.MissionState.Done">
<summary>
已完成
</summary>
</member>
<member name="F:AGVControl_Steel.FrmMain.components"> <member name="F:AGVControl_Steel.FrmMain.components">
<summary> <summary>
必需的设计器变量。 必需的设计器变量。
...@@ -214,68 +240,48 @@ ...@@ -214,68 +240,48 @@
充电工作 充电工作
</summary> </summary>
</member> </member>
<member name="P:Model.ChargeJob.IsProcess">
<summary>
任务是否执行
</summary>
</member>
<member name="P:Model.ChargeJob.IsEnd">
<summary>
任务是否结束
</summary>
</member>
<member name="P:Model.ChargeJob.RunInfo">
<summary>
任务运行信息
</summary>
</member>
<member name="P:Model.ChargeJob.MayBreak">
<summary>
任务能否中断
</summary>
</member>
<member name="M:Model.ChargeJob.Execute(Model.AgvInfo)"> <member name="M:Model.ChargeJob.Execute(Model.AgvInfo)">
<summary> <summary>
任务执行 任务执行
</summary> </summary>
<param name="info"></param> <param name="info"></param>
</member> </member>
<member name="T:Model.ChargeJob.CHARGE_STEP"> <member name="T:Model.ChargeJob.ChargeStep">
<summary> <summary>
充电步骤 充电步骤
</summary> </summary>
</member> </member>
<member name="F:Model.ChargeJob.CHARGE_STEP.NONE"> <member name="F:Model.ChargeJob.ChargeStep.None">
<summary> <summary>
</summary> </summary>
</member> </member>
<member name="F:Model.ChargeJob.CHARGE_STEP.END"> <member name="F:Model.ChargeJob.ChargeStep.End">
<summary> <summary>
充电结束 充电结束
</summary> </summary>
</member> </member>
<member name="F:Model.ChargeJob.CHARGE_STEP.MOVE_WORKSHOP_DOOR"> <member name="F:Model.ChargeJob.ChargeStep.WaitWorkshopDoor">
<summary> <summary>
移动到车间门口 移动到车间门口
</summary> </summary>
</member> </member>
<member name="F:Model.ChargeJob.CHARGE_STEP.MOVE_CHARGE_STATION"> <member name="F:Model.ChargeJob.ChargeStep.WaitChargeStation">
<summary> <summary>
移动到充电位置 移动到充电位置
</summary> </summary>
</member> </member>
<member name="F:Model.ChargeJob.CHARGE_STEP.MOVE_STANDBY"> <member name="F:Model.ChargeJob.ChargeStep.WaitStandby">
<summary> <summary>
移动到待机位 移动到待机位
</summary> </summary>
</member> </member>
<member name="F:Model.ChargeJob.CHARGE_STEP.CHARGING"> <member name="F:Model.ChargeJob.ChargeStep.Charging">
<summary> <summary>
充电中 充电中
</summary> </summary>
</member> </member>
<member name="F:Model.ChargeJob.CHARGE_STEP.SEND_MISSION"> <member name="F:Model.ChargeJob.ChargeStep.SendMission">
<summary> <summary>
发送任务 发送任务
</summary> </summary>
...@@ -300,6 +306,11 @@ ...@@ -300,6 +306,11 @@
小车IP地址 小车IP地址
</summary> </summary>
</member> </member>
<member name="P:Model.AgvInfo.FullName">
<summary>
带IP的完整名称
</summary>
</member>
<member name="P:Model.AgvInfo.Authorization"> <member name="P:Model.AgvInfo.Authorization">
<summary> <summary>
授权码 授权码
...@@ -310,9 +321,9 @@ ...@@ -310,9 +321,9 @@
地点 地点
</summary> </summary>
</member> </member>
<member name="P:Model.AgvInfo.IsUse"> <member name="P:Model.AgvInfo.IsAuto">
<summary> <summary>
是否使用 是否自动使用
</summary> </summary>
</member> </member>
<member name="P:Model.AgvInfo.IsOnline"> <member name="P:Model.AgvInfo.IsOnline">
...@@ -350,6 +361,11 @@ ...@@ -350,6 +361,11 @@
IO模块的guid IO模块的guid
</summary> </summary>
</member> </member>
<member name="P:Model.AgvInfo.IsCall">
<summary>
是否正在被调用
</summary>
</member>
<member name="P:Model.AgvInfo.CurrentJob"> <member name="P:Model.AgvInfo.CurrentJob">
<summary> <summary>
当前的工作 当前的工作
...@@ -393,32 +409,32 @@ ...@@ -393,32 +409,32 @@
</summary> </summary>
<param name="step"></param> <param name="step"></param>
</member> </member>
<member name="T:Model.IJob"> <member name="P:Model.JobStep`1.Msg">
<summary> <summary>
小车的工作 当前信息
</summary> </summary>
</member> </member>
<member name="P:Model.IJob.IsProcess"> <member name="T:Model.Job">
<summary> <summary>
任务是否执行 小车的工作
</summary> </summary>
</member> </member>
<member name="P:Model.IJob.IsEnd"> <member name="P:Model.Job.IsProcess">
<summary> <summary>
任务是否结束 任务是否执行
</summary> </summary>
</member> </member>
<member name="P:Model.IJob.MayBreak"> <member name="P:Model.Job.IsEnd">
<summary> <summary>
任务能否中断 任务是否结束
</summary> </summary>
</member> </member>
<member name="P:Model.IJob.RunInfo"> <member name="P:Model.Job.RunInfo">
<summary> <summary>
任务运行信息 任务运行信息
</summary> </summary>
</member> </member>
<member name="M:Model.IJob.Execute(Model.AgvInfo)"> <member name="M:Model.Job.Execute(Model.AgvInfo)">
<summary> <summary>
任务执行 任务执行
</summary> </summary>
......
615451de38fcb548d6bfbffa678814c7b4e35376 f043318a8d986121056db453b28d27892cd2232a
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!