using SKMC.Api.Motion.Model;
using SKMC.Api.Recipe.Model;
using System;
using System.Collections.Generic;
namespace SKMC.Api.Motion.Control
{
///
/// 基于流程化的运动控制层接口
/// 结合点位、速度配置, 方便控制脚本调用
///
public interface IMotionControl
{
///
/// 设置参数
///
/// interval/timeout_move/timeout_home
///
void Set(string key, int value);
///
/// 获取参数
///
/// interval/timeout_move/timeout_home
///
int Get(string key);
///
/// 控制使能, true: motion控制有效, false: motion控制无效
/// 运动过程中如有电机抛出MotionException, 该控制使能自动失效
///
void Enable(bool enabled = true);
///
/// 控制使能是否有效
///
///
bool IsEnable();
///
/// 开启所有电机使能
///
void EnableAllAxises();
///
/// 关闭所有电机使能
///
void DisableAllAxises();
///
/// 判断控制卡是否连接状态
///
///
bool IsCardConnected();
///
/// 电机上使能
///
/// 电机码
/// 清除驱动报警
void EnableAxis(string axisCode, bool clearError = true);
///
/// 电机下使能
///
/// 电机码
void DisableAxis(string axisCode);
///
/// 多个电机上使能
///
/// 电机码集合
/// 清除驱动报警
void EnableAxises(List axisCodes, bool clearError = true);
///
/// 多个电机下使能
///
/// 电机码集合
void DisableAxises(List axisCodes);
///
/// 获取电机对象
///
/// 电机码
/// 电机对象
MotionAxis GetAxis(string axisCode);
///
/// 指定轴回零
///
/// 电机码
/// 是否等待(!注意:目前此参数设置为false无效)
/// 安全条件, 回零中如果不满足该安全条件立即停止并报警
///
///
/// 超时时间(毫秒)
void Home(string axisCode, bool waiting = true, Func safeCnd = null, Action onSuccess = null, Action onTimeout = null, int timeout = 60000);
///
/// 指定轴快速回零, 该轴必须是闭环电机, 如果是开环电机则降级为普通的HomeAxis回零
/// 并且传入的stateCheck为true后(表示总线连接OK并且上一次回零到现在未中断),使用speedCode速度移动到0位置再进行回零。
/// 如果传入的stateCheck为false则降级为普通的HomeAxis回零
///
/// 电机码
/// 快速移动到0位置的速度码, !注意:为确保安全设置合适的速度
/// 状态判断, 这里指Ecat总线连接状态以及上一次回零后Ecat总线是否正常
/// 是否等待(!注意:目前此参数设置为false无效)
/// 安全条件, 回零中如果不满足该安全条件立即停止并报警
///
///
/// 超时时间(毫秒)
void HomeFast(string axisCode, string speedCode, bool stateCheck, bool waiting = true,
Func safeCnd = null, Action onSuccess = null, Action onTimeout = null, int timeout = 60000);
///
/// 指定轴反向回零.
/// 在无法进行负方向回零时, 可通过该方法往正方向回零, 回零完毕后设置当前位置为正限位最大值, 即可实现与负方向回零相同效果
///
/// 电机码
/// 回零模式, 例如正限位+Z相回零的模式是2
/// 限位位置相对原点的位置, 单位mm, 推荐在限位位置设置点位并从点位获取
/// 是否等待
/// 安全条件, 回零中如果不满足该安全条件立即停止并报警
///
///
/// 超时时间(毫秒)
void HomeReverse(string axisCode, short homeMode, double maxPos, bool waiting = true,
Func safeCnd = null, Action onSuccess = null, Action onTimeout = null, int timeout = 60000);
///
/// 判断绑定某个点位的电机(一个或多个)是否在该点位附近。需同时满足negativeOffset与PositiveOffset的位置限定后返回true.
/// 具体判断如下:
/// 1.电机未上使能, 返回false
/// 2.电机Enc数值 小于 点位设置值 - negativeOffset 或者 电机Enc数值 大于 点位设置值 + positiveOffset, 返回false
/// 3.剩下返回true
///
/// 点位码
/// 绑定点位的电机序号, 0开头, 默认-1表示该点位的所有电机
/// 大于该点位的负方向距离
/// 小于该点位的正方向距离
/// 是否满足位置条件
bool CheckNear(string pointCode, short index = -1, double negativeOffset = 0.1, double positiveOffset = 0.1);
///
/// 通过点位码驱动对应的Axis运动, speedRadio表示每秒旋转圈数
///
/// 点位码
/// 每秒旋转圈数
/// 是否等待到位, 默认为true
/// 整定范围, 单位毫米或者步距
/// 运动完成后的回调动作
/// 超时未完成的回调动作
void MoveRound(string pointCode, double speedRadio, bool waiting = true, double inRange = -1,
Action onSuccess = null, Action onTimeout = null);
///
/// 让绑定点位码的(多个)电机以指定速度运动到点位码
///
/// 点位码
/// 速度码, null表示使用该点配置的默认速度码
/// 是否等待到位, 默认为true
/// 整定范围, 单位毫米或者步距
/// 运动完成后的回调动作
/// 超时未完成的回调动作
void MovePoint(string pointCode, string speedCode = null, bool waiting = true, double inRange = -1,
Action onSuccess = null, Action onTimeout = null);
///
/// 让绑定点位码的(多个)电机以指定速度运动到点位码
///
/// 点位对象
/// 速度对象, null表示使用该点配置的默认速度
/// 是否等待到位, 默认为true
/// 整定范围, 单位毫米或者步距
/// 运动完成后的回调动作
/// 超时未完成的回调动作
void MovePoint(RecipePoint recipePoint, RecipeSpeed recipeSpeed = null, bool waiting = true, double inRange = -1,
Action onSuccess = null, Action onTimeout = null);
///
/// 让绑定点位码的(多个)电机以指定速度运动到点位码并能叠加指定偏移量
///
/// 点位码
/// 各个电机的偏移量数组, 需要按电机绑定顺序赋值
/// 速度码, null表示使用该点配置的默认速度码
/// 是否等待到位, 默认为true
/// 整定范围, 单位毫米或者步距
/// 运动完成后的回调动作
/// 超时未完成的回调动作
void MovePointFix(string pointCode, double[] posOffsets, string speedCode = null, bool waiting = true, double inRange = -1,
Action onSuccess = null, Action onTimeout = null);
///
/// 让绑定点位码的(多个)电机以指定速度运动到点位码,并能叠加指定偏移量
///
/// 点位对象
/// 各个电机的偏移量数组, 需要按电机绑定顺序赋值
/// 速度对象, null表示使用该点配置的默认速度
/// 是否等待到位, 默认为true
/// 整定范围, 单位毫米或者步距
/// 运动完成后的回调动作
/// 超时未完成的回调动作
void MovePointFix(RecipePoint recipePoint, double[] posOffsets, RecipeSpeed recipeSpeed = null, bool waiting = true, double inRange = -1,
Action onSuccess = null, Action onTimeout = null);
///
/// 让绑定点位码的指定单个电机以指定速度运动到点位码
///
/// 点位码
/// 指定电机的电机码
/// 速度码, null表示使用该点配置的默认速度码
/// 是否等待到位, 默认为true
/// 整定范围, 单位毫米或者步距
/// 运动完成后的回调动作
/// 超时未完成的回调动作
void MovePointOne(string pointCode, string axisCode, string speedCode = null,
bool waiting = true, double inRange = -1,
Action onSuccess = null, Action onTimeout = null);
///
/// 让绑定点位码的指定单个电机以指定速度运动到点位码
///
/// 点位对象
/// 指定电机的电机码
/// 速度对象, null表示使用该点配置的默认速度
/// 是否等待到位, 默认为true
/// 整定范围, 单位毫米或者步距
/// 运动完成后的回调动作
/// 超时未完成的回调动作
void MovePointOne(RecipePoint recipePoint, string axisCode, RecipeSpeed recipeSpeed = null,
bool waiting = true, double inRange = -1,
Action onSuccess = null, Action onTimeout = null);
///
/// 让绑定点位码的指定单个电机以指定速度运动到点位码,并能叠加指定偏移量
///
/// 点位码
/// 基于点位的偏移量(mm)
/// 指定电机的电机码
/// 速度码, null表示使用该点配置的默认速度码
/// 是否等待到位, 默认为true
/// 整定范围, 单位毫米或者步距
/// 运动完成后的回调动作
/// 超时未完成的回调动作
void MovePointOneFix(string pointCode, double fixset, string axisCode, string speedCode = null,
bool waiting = true, double inRange = -1,
Action onSuccess = null, Action onTimeout = null);
///
/// 让绑定点位码的指定单个电机以指定速度运动到点位码,并能叠加指定偏移量
///
/// 点位对象
/// 基于点位的偏移量(mm)
/// 指定电机的电机码
/// 速度对象, null表示使用该点配置的默认速度
/// 是否等待到位, 默认为true
/// 整定范围, 单位毫米或者步距
/// 运动完成后的回调动作
/// 超时未完成的回调动作
void MovePointOneFix(RecipePoint recipePoint, double fixset, string axisCode, RecipeSpeed recipeSpeed = null,
bool waiting = true, double inRange = -1,
Action onSuccess = null, Action onTimeout = null);
///
/// 聚合多个点位码并同时运动
///
/// 需要聚合运动的点位对象集合
/// 是否等待到位, 默认为true
/// 整定范围, 单位毫米或者步距
/// 是否同步到达,false: 使用recipeSpeed的速度,true:以recipeSpeed为基准,调整各点位速度
/// 运动完成后的回调动作
/// 超时未完成的回调动作
void MovePoints(List recipePoints, RecipeSpeed recipeSpeed,
bool waiting = true, double inRange = -1, bool sync = false,
Action onSuccess = null, Action onTimeout = null);
///
/// 聚合多个点位码并同时运动
///
/// 需要聚合运动的点位码集合
/// 速度码, null表示使用各点位的默认速度码
/// 是否等待到位, 默认为true
/// 整定范围, 单位毫米或者步距
/// 是否同步到达,false: 使用各自的点位中的速度,true:以speedCode为基准,调整各点位速度
/// 运动完成后的回调动作
/// 超时未完成的回调动作
void MovePoints(string[] pointCodes, string speedCode = null,
bool waiting = true, double inRange = -1, bool sync = false,
Action onSuccess = null, Action onTimeout = null);
///
/// 等待电机运动到位
///
/// 电机码
/// 超时时间
/// 整定范围, 单位毫米或者步距
/// 运动完成后的回调动作
/// 超时未完成的回调动作
void WaitAxis(string axisCode, int timeout = 10000, double inRange = -1,
Action onSuccess = null, Action onTimeout = null);
///
/// 等待电机运动到位
///
/// 电机对象
/// 超时时间
/// 整定范围, 单位毫米或者步距
/// 运动完成后的回调动作
/// 超时未完成的回调动作
void WaitAxis(MotionAxis motionAxis, int timeout = 10000, double inRange = -1,
Action onSuccess = null, Action onTimeout = null);
///
/// 等待点位上所有电机到位
///
/// 点位码
/// 超时时间
/// 整定范围, 单位毫米或者步距
/// 运动完成后的回调动作
/// 超时未完成的回调动作
void WaitPoint(string pointCode, int timeout = 10000, double inRange = -1,
Action onSuccess = null, Action onTimeout = null);
///
/// 等待点位上所有电机到位
///
/// 点位对象
/// 超时时间
/// 整定范围, 单位毫米或者步距
/// 安全条件, 运动中如果不满足该安全条件立即停止并报警
/// 运动完成后的回调动作
/// 超时未完成的回调动作
void WaitPoint(RecipePoint recipePoint, int timeout = 10000, double inRange = -1,
Action onSuccess = null, Action onTimeout = null);
///
/// 等待电机组所有电机到位
///
/// 电机码集合
/// 超时时间
void WaitGroup(List axisCodes, int timeout = 10000);
///
/// 等待并阻塞当前线程, 直到满足特定条件
///
/// 完成条件 (满足后释放阻塞)
/// 超时动作
/// 超时时间(ms)
void WaitCnd(Func cndDone, Action onTimeout, int timeout);
///
/// 电机按一定速度持续运动, 非阻塞
///
/// 电机码
/// 速度码
/// 方向
void MoveKeep(string axisCode, string speedCode, ushort direction);
///
/// 电机相对运动
///
/// 电机码
/// 速度码
/// 距离
/// 是否等待
void MoveRel(string axisCode, string speedCode, double distance, bool waiting = true);
///
/// 电机绝对运动,确保回零后调用
///
/// 电机码
/// 速度码
/// 坐标
/// 是否等待
void MoveAbs(string axisCode, string speedCode, double position, bool waiting = false);
///
/// 电机绝对运动,确保回零后调用
///
/// 电机码
/// 速度对象
/// 坐标
/// 是否等待
void MoveAbs(string axisCode, RecipeSpeed recipeSpeed, double position, bool waiting = false);
///
/// 停止单个电机
///
/// 电机码
void Stop(string axisCode, bool waiting = false);
///
/// 停止多个电机
///
/// 电机码集合
void Stop(List axisCodes);
///
/// 点位上多个电机停止运动
///
/// 点位码
void StopPoint(string pointCode);
///
/// 所有电机停止
///
void StopAll();
///
/// 暂停一个电机运动
///
/// 电机码
void Pause(string axisCode);
///
/// 暂停一个点位上多个电机运动
///
/// 点位码
void PausePoint(string pointCode);
///
/// 恢复一个电机运动
///
/// 电机码
void Resume(string axisCode);
///
/// 暂停一个点位上多个电机运行
///
/// 点位码
void ResumePoint(string pointCode);
///
/// 清除电机计数(反馈值与目标值)
///
/// 电机码
void ClearCounter(string axisCode);
///
/// 清除电机驱动器报警(部分驱动器可能无效)
///
/// 电机码
void ClearError(string axisCode);
///
/// 更新电机持续运行时的速度
///
/// 电机码
/// 速度码
void UpdateKeepSpeed(string axisCode, string speedCode);
///
/// 更新电机持续运行时的速度.
/// [注意]速度单位是mm/s, 慎用
///
/// 电机码
/// 速度对象, 至少需要MaxVel、Acc、Dec 这3个属性
void UpdateKeepSpeed(string axisCode, RecipeSpeed recipeSpeed);
///
/// 更新电机点对点移动时的速度
///
/// 电机码
/// 速度码
void UpdateMoveSpeed(string axisCode, string speedCode);
///
/// 更新电机点对点移动时的速度.
/// [注意]速度单位是mm/s, 慎用
///
/// 电机码
/// 速度对象, 至少需要MaxVel、Acc、Dec 这3个属性
void UpdateMoveSpeed(string axisCode, RecipeSpeed recipeSpeed);
///
/// 开始监测电机步距
///
/// 电机码
/// 时间周期, -1表示当前
void StartWatch(string axisCode, long ticks = -1);
///
/// 读取电机状态并获取对象
///
/// 电机码
/// 电机对象
MotionAxis ReadStatus(string axisCode);
///
/// 读取电机状态
///
/// 电机对象
void ReadStatus(MotionAxis motionAxis);
///
/// 电机到位判断
///
/// 电机码
/// 是否到位
bool CheckDone(string axisCode);
///
/// 多个电机到位判断, 如果其中一个电机未到位返回false
///
/// 电机码
/// 是否到位
bool CheckDone(List axisCodes);
///
/// 设置DO点开关值(会检测接口是否失效, 推荐气缸等动作IO使用)
///
/// DO码
/// 开关值
/// 本次动作是否记录到日志
void PushIO(string doCode, short value, bool logged = true);
///
/// 设置DO点开关值
///
/// DO码
/// 开关值
/// 本次动作是否记录到日志
void PushIO(string doCode, int value, bool logged = true);
///
/// 设置DO点开关值(不检测接口是否失效, 推荐指示灯等非动作IO使用)
///
/// DO码
/// 开关值
/// 本次动作是否记录到日志
void SetIO(string doCode, short value, bool logged = true);
///
/// 设置DO点开关值反向
///
/// DO码
void PushIORev(string doCode);
///
/// 设置一对DO点开关值
///
/// DO1码
/// DO1开关值
/// DO2码
/// DO2开关值
void PushIOPair(string do1Code, short do1Value, string do2Code, short do2Value);
///
/// 获取DI开关值
///
/// DI码
/// 是否从缓存获取
///
short GetDiValue(string diCode, bool fromCache = true);
///
/// 读取一次DI开关值并写入cache, 同时返回该数值
///
/// DI码
///
short ReadDiValue(string diCode);
///
/// 获取DO开关值
///
/// DO码
/// 是否从缓存获取
///
short GetDoValue(string doCode, bool fromCache = true);
///
/// 读取一次DO开关值并写入cache, 同时返回该数值
///
/// DI码
///
short ReadDoValue(string doCode);
///
/// 获取模拟量数值
///
/// AD码
///
short GetAdValue(string adCode);
///
/// 获取模拟量数值
///
/// AD序号
///
short GetAdValue(short adIndex);
///
/// 读取一次模拟量数值到MotionCacher的MotionAO中
///
/// AD码
void ReadAdValue(string adCode);
///
/// 读取一次模拟量数值到MotionCacher的MotionAO中
///
/// AD序号
void ReadAdValue(short adIndex);
}
}