Commit e002c0f5 authored by 潘栩锋's avatar 潘栩锋 🚴

优化 AD盒脉冲3秒不变化。 状态设置为手动停止

parent f64acccb
...@@ -348,14 +348,17 @@ namespace FlyADBase ...@@ -348,14 +348,17 @@ namespace FlyADBase
/// 用于检测当 为IsRunning时,脉冲是否停了很久。 /// 用于检测当 为IsRunning时,脉冲是否停了很久。
/// </summary> /// </summary>
int last_position = int.MinValue; int last_position = int.MinValue;
/// <summary>
/// 脉冲不变化次数
/// </summary>
int position_no_changed_cnt = 0;
TimeSpan NoTGridTimeOut = TimeSpan.FromSeconds(60); TimeSpan NoTGridTimeOut = TimeSpan.FromSeconds(60);
Stopwatch stopwatch_noTGrid = new Stopwatch(); Stopwatch stopwatch_noTGrid = new Stopwatch();
IsReadyContext isReadyContext = new IsReadyContext(); IsReadyContext isReadyContext = new IsReadyContext();
SysTickContext sysTickContext = new SysTickContext(); SysTickContext sysTickContext = new SysTickContext();
...@@ -366,7 +369,8 @@ namespace FlyADBase ...@@ -366,7 +369,8 @@ namespace FlyADBase
string jsonDbPath; string jsonDbPath;
DateTime lastTimeGridTime; DateTime lastTimeGridTime;
static FlyAD7() { static FlyAD7()
{
propertyName_save = FlyAD7JsonDb.GetMemberNames(); propertyName_save = FlyAD7JsonDb.GetMemberNames();
} }
/// <summary> /// <summary>
...@@ -456,17 +460,33 @@ namespace FlyADBase ...@@ -456,17 +460,33 @@ namespace FlyADBase
() => () =>
{ {
if (!IsConnected) if (!IsConnected)
{
position_no_changed_cnt = 0;
return; return;
}
if (DriveStatus != DRIVE_MAN_STATUS.RUNNING) if (DriveStatus != DRIVE_MAN_STATUS.RUNNING)
{
position_no_changed_cnt = 0;
return; return;
}
if (Position != last_position) if (Position != last_position)
{ {
last_position = Position; last_position = Position;
position_no_changed_cnt = 0;
return; return;
} }
position_no_changed_cnt++;
if (driveman_wait.CheckMark(TimeSpan.FromSeconds(3)))//每3秒检查一次 if (position_no_changed_cnt >= 3)
{
//连续3秒,脉冲一样
//异常
DriveStatus = DRIVE_MAN_STATUS.STOP_MANUAL;
position_no_changed_cnt = 0;
return;
}
if (driveman_wait.CheckMark(TimeSpan.FromSeconds(2)))//每2秒检查一次
{ {
driveman_wait.Mark(); driveman_wait.Mark();
CurrObjSys.GetValueEx( CurrObjSys.GetValueEx(
...@@ -593,7 +613,8 @@ namespace FlyADBase ...@@ -593,7 +613,8 @@ namespace FlyADBase
ID, ID,
FLYAD7_OBJ_INTERFACE.SYS_DATA_INTERFACE.GET_ZERO_POS); FLYAD7_OBJ_INTERFACE.SYS_DATA_INTERFACE.GET_ZERO_POS);
} }
else { else
{
//参数不保存在设备中, 保存在电脑。 //参数不保存在设备中, 保存在电脑。
//参数写入到设备。 //参数写入到设备。
NotifyPropertyChanged(nameof(MotorType)); NotifyPropertyChanged(nameof(MotorType));
...@@ -658,7 +679,7 @@ namespace FlyADBase ...@@ -658,7 +679,7 @@ namespace FlyADBase
ID, ID,
FLYAD7_OBJ_INTERFACE.FLYIO_OBJ_INTERFACE.GET_IO); FLYAD7_OBJ_INTERFACE.FLYIO_OBJ_INTERFACE.GET_IO);
NotifyPropertyChanged(nameof(Pos1LCShift));//写入到AD盒 NotifyPropertyChanged(nameof(Pos1LCShift));//写入到AD盒
NotifyPropertyChanged(nameof(Pos2LCShift));//写入到AD盒 NotifyPropertyChanged(nameof(Pos2LCShift));//写入到AD盒
...@@ -908,7 +929,7 @@ namespace FlyADBase ...@@ -908,7 +929,7 @@ namespace FlyADBase
Position = pack.pos1; Position = pack.pos1;
DateTime dt = sysTickContext.ToDateTime(pack.systick); DateTime dt = sysTickContext.ToDateTime(pack.systick);
Now = dt; Now = dt;
PositionChangedEvent?.Invoke(this, new PositionChangedEventArgs() { Time = dt, Position = Position }); PositionChangedEvent?.Invoke(this, new PositionChangedEventArgs() { Time = dt, Position = Position });
} }
calSpeed.SetPos1(Now, Position); calSpeed.SetPos1(Now, Position);
...@@ -933,7 +954,7 @@ namespace FlyADBase ...@@ -933,7 +954,7 @@ namespace FlyADBase
Position2 = pack.pos2; Position2 = pack.pos2;
DateTime dt = sysTickContext.ToDateTime(pack.systick); DateTime dt = sysTickContext.ToDateTime(pack.systick);
Now = dt; Now = dt;
Position2ChangedEvent?.Invoke(this, new PositionChangedEventArgs() { Time = dt, Position = Position }); Position2ChangedEvent?.Invoke(this, new PositionChangedEventArgs() { Time = dt, Position = Position });
} }
calSpeed.SetPos2(Now, Position2); calSpeed.SetPos2(Now, Position2);
...@@ -1158,7 +1179,7 @@ namespace FlyADBase ...@@ -1158,7 +1179,7 @@ namespace FlyADBase
} }
break; break;
} }
_end_push_info: _end_push_info:
bShieldSetValueEx = false; bShieldSetValueEx = false;
} }
...@@ -1183,7 +1204,7 @@ namespace FlyADBase ...@@ -1183,7 +1204,7 @@ namespace FlyADBase
ID, ID,
FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.CALL_PXX, FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.CALL_PXX,
new FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.Pack_CallRunto() { to = TargetPos }.ToBytes()); new FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.Pack_CallRunto() { to = TargetPos }.ToBytes());
} }
break; break;
case DRIVE_MAN_ORDER.ORIGIN: case DRIVE_MAN_ORDER.ORIGIN:
...@@ -1256,9 +1277,9 @@ namespace FlyADBase ...@@ -1256,9 +1277,9 @@ namespace FlyADBase
bool ret = FlyAD7JsonDb.Load(jsonDbPath, this); bool ret = FlyAD7JsonDb.Load(jsonDbPath, this);
bShieldSetValueEx = false; bShieldSetValueEx = false;
this.PropertyChanged += FlyAD7_PropertyChanged2; this.PropertyChanged += FlyAD7_PropertyChanged2;
return ret; return ret;
} }
...@@ -1454,7 +1475,7 @@ namespace FlyADBase ...@@ -1454,7 +1475,7 @@ namespace FlyADBase
/// <param name="velocity"></param> /// <param name="velocity"></param>
public void SetVelocity(UInt32 velocity) public void SetVelocity(UInt32 velocity)
{ {
SetPosParam(velocity,UInt32.MaxValue, UInt32.MaxValue, UInt32.MaxValue, UInt32.MaxValue, UInt32.MaxValue); SetPosParam(velocity, UInt32.MaxValue, UInt32.MaxValue, UInt32.MaxValue, UInt32.MaxValue, UInt32.MaxValue);
} }
/// <summary> /// <summary>
...@@ -1477,7 +1498,7 @@ namespace FlyADBase ...@@ -1477,7 +1498,7 @@ namespace FlyADBase
FLYAD7_OBJ_INTERFACE.SYS_DATA_INTERFACE.GET_SYSINFO); FLYAD7_OBJ_INTERFACE.SYS_DATA_INTERFACE.GET_SYSINFO);
} }
/// <summary> /// <summary>
/// 初始化系统信息区 /// 初始化系统信息区
/// </summary> /// </summary>
...@@ -1789,12 +1810,12 @@ namespace FlyADBase ...@@ -1789,12 +1810,12 @@ namespace FlyADBase
//备份参数 //备份参数
public bool IsDevParamValid = false; public bool IsDevParamValid = false;
public MOTORTYPE MotorType = MOTORTYPE.SERVO; public MOTORTYPE MotorType = MOTORTYPE.SERVO;
public UInt16 PosOfGrid = 10; public UInt16 PosOfGrid = 10;
public UInt16 Ratio01 = 4; public UInt16 Ratio01 = 4;
public UInt16 Ratio02 = 1; public UInt16 Ratio02 = 1;
public Int16 PosOffset = 0; public Int16 PosOffset = 0;
public UInt32 JogVelocity = 1000; public UInt32 JogVelocity = 1000;
/// <summary> /// <summary>
/// 硬件版本 /// 硬件版本
...@@ -1805,8 +1826,9 @@ namespace FlyADBase ...@@ -1805,8 +1826,9 @@ namespace FlyADBase
public int HardwareVersion = 2; public int HardwareVersion = 2;
public static string[] GetMemberNames() { public static string[] GetMemberNames()
var type = typeof(FlyAD7JsonDb); {
var type = typeof(FlyAD7JsonDb);
return type.GetMembers().Select(mi => mi.Name).ToArray(); return type.GetMembers().Select(mi => mi.Name).ToArray();
} }
......
...@@ -24,7 +24,7 @@ namespace FLY.Thick.Base.Server ...@@ -24,7 +24,7 @@ namespace FLY.Thick.Base.Server
/// 归0开始时间点,用于计算什么时候需要归0 /// 归0开始时间点,用于计算什么时候需要归0
/// </summary> /// </summary>
private TimeSpan orgStartTime; private TimeSpan orgStartTime;
/// <summary> /// <summary>
/// 使用timer.Elapsed 代替 DateTime.Now 使用 /// 使用timer.Elapsed 代替 DateTime.Now 使用
/// </summary> /// </summary>
...@@ -90,7 +90,7 @@ namespace FLY.Thick.Base.Server ...@@ -90,7 +90,7 @@ namespace FLY.Thick.Base.Server
ScanEnd = -1; ScanEnd = -1;
} }
public virtual void Init(IFlyADClientAdv flyad, GSample gsample) public virtual void Init(IFlyADClientAdv flyad, GSample gsample)
{ {
base.Init(flyad); base.Init(flyad);
this.gsample = gsample; this.gsample = gsample;
...@@ -128,24 +128,7 @@ namespace FLY.Thick.Base.Server ...@@ -128,24 +128,7 @@ namespace FLY.Thick.Base.Server
FinishEvent?.Invoke(this, null); FinishEvent?.Invoke(this, null);
base.Stop(); base.Stop();
} }
bool WaitFinish(ref CTRLST src, CTRLST next)
{
switch (mFlyAD.DriveStatus)
{
case DRIVE_MAN_STATUS.STOP://完成任务
case DRIVE_MAN_STATUS.LIMIT:
{
src = next;
return true;
} break;
case DRIVE_MAN_STATUS.STOP_MANUAL://异常
{
NotifyError(ERRNO_Running_Manual);
Stop(); return false;
} break;
}
return false;
}
protected override void OnPoll() protected override void OnPoll()
{ {
switch (state) switch (state)
...@@ -157,15 +140,31 @@ namespace FLY.Thick.Base.Server ...@@ -157,15 +140,31 @@ namespace FLY.Thick.Base.Server
mFlyAD.Origin(); mFlyAD.Origin();
state = CTRLST.ORIGINWAIT; state = CTRLST.ORIGINWAIT;
} }
else { else
{
state = CTRLST.SCAN_FORW; state = CTRLST.SCAN_FORW;
} }
} }
break; break;
case CTRLST.ORIGINWAIT: case CTRLST.ORIGINWAIT:
{ {
WaitFinish(ref state, CTRLST.FORWARD); switch (mFlyAD.DriveStatus)
} break; {
case DRIVE_MAN_STATUS.STOP://完成任务
{
state = CTRLST.FORWARD;
}
break;
case DRIVE_MAN_STATUS.LIMIT:
case DRIVE_MAN_STATUS.STOP_MANUAL://异常
{
NotifyError(ERRNO_Running_Manual);
Stop();
}
break;
}
}
break;
case CTRLST.FORWARD: case CTRLST.FORWARD:
{ {
int to = ScanEnd; int to = ScanEnd;
...@@ -185,17 +184,22 @@ namespace FLY.Thick.Base.Server ...@@ -185,17 +184,22 @@ namespace FLY.Thick.Base.Server
to = b; to = b;
} }
} }
mFlyAD.SetVelocity(Velocity); mFlyAD.SetVelocity(Velocity);
mFlyAD.Runto(to); mFlyAD.Runto(to);
state = CTRLST.FORWAIT_1; state = CTRLST.FORWAIT_1;
} break; }
break;
case CTRLST.FORWAIT_1: case CTRLST.FORWAIT_1:
{ {
if (WaitFinish(ref state, CTRLST.FORWAIT_2)) if (WaitFinish())
{
state = CTRLST.FORWAIT_2;
FlushAD(DIRECTION.FORWARD); FlushAD(DIRECTION.FORWARD);
}
} break; }
break;
case CTRLST.FORWAIT_2: case CTRLST.FORWAIT_2:
{ {
state = CTRLST.BACKWARD; state = CTRLST.BACKWARD;
...@@ -217,16 +221,22 @@ namespace FLY.Thick.Base.Server ...@@ -217,16 +221,22 @@ namespace FLY.Thick.Base.Server
state = CTRLST.FORWAIT_SAMPLE; state = CTRLST.FORWAIT_SAMPLE;
} }
} }
} break; }
break;
case CTRLST.FORWAIT_SAMPLE: case CTRLST.FORWAIT_SAMPLE:
{ {
WaitFinish(ref state, CTRLST.FORW_SAMPLE); if (WaitFinish())
} break; {
state = CTRLST.FORW_SAMPLE;
}
}
break;
case CTRLST.FORW_SAMPLE: case CTRLST.FORW_SAMPLE:
{ {
gsample.Do(Misc.DIRECTION.FORWARD); gsample.Do(Misc.DIRECTION.FORWARD);
state = CTRLST.BACKWARD; state = CTRLST.BACKWARD;
} break; }
break;
case CTRLST.BACKWARD: case CTRLST.BACKWARD:
{ {
int to = ScanStart; int to = ScanStart;
...@@ -246,16 +256,21 @@ namespace FLY.Thick.Base.Server ...@@ -246,16 +256,21 @@ namespace FLY.Thick.Base.Server
to = e; to = e;
} }
} }
mFlyAD.SetVelocity(Velocity); mFlyAD.SetVelocity(Velocity);
mFlyAD.Runto(to); mFlyAD.Runto(to);
state = CTRLST.BACKWAIT_1; state = CTRLST.BACKWAIT_1;
} break; }
break;
case CTRLST.BACKWAIT_1: case CTRLST.BACKWAIT_1:
{ {
if (WaitFinish(ref state, CTRLST.BACKWAIT_2)) if (WaitFinish())
{
state = CTRLST.BACKWAIT_2;
FlushAD(DIRECTION.BACKWARD); FlushAD(DIRECTION.BACKWARD);
} break; }
}
break;
case CTRLST.BACKWAIT_2: case CTRLST.BACKWAIT_2:
{ {
int b, e; int b, e;
...@@ -275,17 +290,23 @@ namespace FLY.Thick.Base.Server ...@@ -275,17 +290,23 @@ namespace FLY.Thick.Base.Server
state = CTRLST.BACKWAIT_SAMPLE; state = CTRLST.BACKWAIT_SAMPLE;
} }
} }
else { else
{
//完成一次周期 //完成一次周期
if (!gsample.IsFailure()) if (!gsample.IsFailure())
orgStartTime = timer.Elapsed; orgStartTime = timer.Elapsed;
state = CTRLST.INIT; state = CTRLST.INIT;
} }
} break; }
break;
case CTRLST.BACKWAIT_SAMPLE: case CTRLST.BACKWAIT_SAMPLE:
{ {
WaitFinish(ref state, CTRLST.BACKW_SAMPLE); if (WaitFinish())
} break; {
state = CTRLST.BACKW_SAMPLE;
}
}
break;
case CTRLST.BACKW_SAMPLE: case CTRLST.BACKW_SAMPLE:
{ {
gsample.Do(Misc.DIRECTION.BACKWARD); gsample.Do(Misc.DIRECTION.BACKWARD);
...@@ -293,7 +314,8 @@ namespace FLY.Thick.Base.Server ...@@ -293,7 +314,8 @@ namespace FLY.Thick.Base.Server
if (!gsample.IsFailure()) if (!gsample.IsFailure())
orgStartTime = timer.Elapsed; orgStartTime = timer.Elapsed;
state = CTRLST.INIT; state = CTRLST.INIT;
} break; }
break;
case CTRLST.SCAN_FORW: case CTRLST.SCAN_FORW:
...@@ -306,8 +328,11 @@ namespace FLY.Thick.Base.Server ...@@ -306,8 +328,11 @@ namespace FLY.Thick.Base.Server
break; break;
case CTRLST.SCAN_FORWAIT: case CTRLST.SCAN_FORWAIT:
{ {
if (WaitFinish(ref state, CTRLST.SCAN_BACKW)) if (WaitFinish())
{
state = CTRLST.SCAN_BACKW;
FlushAD(DIRECTION.FORWARD); FlushAD(DIRECTION.FORWARD);
}
} }
break; break;
case CTRLST.SCAN_BACKW: case CTRLST.SCAN_BACKW:
...@@ -320,8 +345,11 @@ namespace FLY.Thick.Base.Server ...@@ -320,8 +345,11 @@ namespace FLY.Thick.Base.Server
break; break;
case CTRLST.SCAN_BACKWAIT: case CTRLST.SCAN_BACKWAIT:
{ {
if (WaitFinish(ref state, CTRLST.INIT)) if (WaitFinish())
{
state = CTRLST.INIT;
FlushAD(DIRECTION.BACKWARD); FlushAD(DIRECTION.BACKWARD);
}
} }
break; break;
} }
...@@ -329,7 +357,8 @@ namespace FLY.Thick.Base.Server ...@@ -329,7 +357,8 @@ namespace FLY.Thick.Base.Server
private bool IsOrging() private bool IsOrging()
{ {
if (OrgInterval > 0) { if (OrgInterval > 0)
{
if (timer.Elapsed >= (orgStartTime + TimeSpan.FromMinutes(OrgInterval))) if (timer.Elapsed >= (orgStartTime + TimeSpan.FromMinutes(OrgInterval)))
return true; return true;
...@@ -383,7 +412,7 @@ namespace FLY.Thick.Base.Server ...@@ -383,7 +412,7 @@ namespace FLY.Thick.Base.Server
{ {
#region 成员变量 #region 成员变量
int scanCnt;//扫描次数, 当为-1时,无限次扫描,>0时,有限次扫描 int scanCnt;//扫描次数, 当为-1时,无限次扫描,>0时,有限次扫描
protected int ScanCnt protected int ScanCnt
{ {
...@@ -492,24 +521,7 @@ namespace FLY.Thick.Base.Server ...@@ -492,24 +521,7 @@ namespace FLY.Thick.Base.Server
FinishEvent(this, null); FinishEvent(this, null);
base.Stop(); base.Stop();
} }
bool WaitFinish(ref CTRLST src, CTRLST next)
{
switch (mFlyAD.DriveStatus)
{
case DRIVE_MAN_STATUS.STOP://完成任务
case DRIVE_MAN_STATUS.LIMIT:
{
src = next;
return true;
} break;
case DRIVE_MAN_STATUS.STOP_MANUAL://异常
{
NotifyError(ERRNO_Running_Manual);
Stop(); return false;
} break;
}
return false;
}
protected override void OnPoll() protected override void OnPoll()
{ {
switch (state) switch (state)
...@@ -518,48 +530,69 @@ namespace FLY.Thick.Base.Server ...@@ -518,48 +530,69 @@ namespace FLY.Thick.Base.Server
{ {
mFlyAD.Origin(); mFlyAD.Origin();
state = CTRLST.READY_ORIGINWAIT; state = CTRLST.READY_ORIGINWAIT;
} break; }
break;
case CTRLST.READY_ORIGINWAIT: case CTRLST.READY_ORIGINWAIT:
{ {
WaitFinish(ref state, CTRLST.READY_BACKW); if (WaitFinish())
}break; {
state = CTRLST.READY_BACKW;
}
}
break;
case CTRLST.READY_BACKW: case CTRLST.READY_BACKW:
{ {
mFlyAD.SetVelocity(Velocity); mFlyAD.SetVelocity(Velocity);
mFlyAD.RuntoMin(); mFlyAD.RuntoMin();
state = CTRLST.READY_BACKWAIT; state = CTRLST.READY_BACKWAIT;
} break; }
break;
case CTRLST.READY_BACKWAIT: case CTRLST.READY_BACKWAIT:
{ {
WaitFinish(ref state, CTRLST.SFORWARD); if (WaitFinish())
} break; {
state = CTRLST.SFORWARD;
}
}
break;
case CTRLST.SFORWARD: case CTRLST.SFORWARD:
{ {
mFlyAD.SetVelocity(Velocity); mFlyAD.SetVelocity(Velocity);
mFlyAD.RuntoMax(); mFlyAD.RuntoMax();
state = CTRLST.SFORWAIT_1; state = CTRLST.SFORWAIT_1;
} break; }
break;
case CTRLST.SFORWAIT_1: case CTRLST.SFORWAIT_1:
{ {
if (WaitFinish(ref state, CTRLST.SFORWAIT_2)) if (WaitFinish())
{
state = CTRLST.SFORWAIT_2;
FlushAD(DIRECTION.FORWARD); FlushAD(DIRECTION.FORWARD);
} break; }
}
break;
case CTRLST.SFORWAIT_2: case CTRLST.SFORWAIT_2:
{ {
state = CTRLST.SBACKWARD; state = CTRLST.SBACKWARD;
} break; }
break;
case CTRLST.SBACKWARD: case CTRLST.SBACKWARD:
{ {
mFlyAD.SetVelocity(Velocity); mFlyAD.SetVelocity(Velocity);
mFlyAD.RuntoMin(); mFlyAD.RuntoMin();
state = CTRLST.SBACKWAIT_1; state = CTRLST.SBACKWAIT_1;
} break; }
break;
case CTRLST.SBACKWAIT_1: case CTRLST.SBACKWAIT_1:
{ {
if (WaitFinish(ref state, CTRLST.SBACKWAIT_2)) if (WaitFinish())
{
state = CTRLST.SBACKWAIT_2;
FlushAD(DIRECTION.BACKWARD); FlushAD(DIRECTION.BACKWARD);
} break; }
}
break;
case CTRLST.SBACKWAIT_2: case CTRLST.SBACKWAIT_2:
{ {
state = CTRLST.SFORWARD; state = CTRLST.SFORWARD;
...@@ -573,7 +606,8 @@ namespace FLY.Thick.Base.Server ...@@ -573,7 +606,8 @@ namespace FLY.Thick.Base.Server
//扫描完成 //扫描完成
Stop(); return; Stop(); return;
} }
} break; }
break;
} }
} }
private void FlushAD(Misc.DIRECTION direction) private void FlushAD(Misc.DIRECTION direction)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment