📄 gunclass.java
字号:
package cn.com.yuzhiqiang.pcimotor;
public class GunClass extends ControlMotor {
final static int ALLSTEPS = 334;// 算出后赋值 比如60度10细分对应的脉冲值
protected static int[] YDatalist = new int[7];// 公共参数数组
protected static int[] YLCData = new int[7];// 直线和S曲线参数数组
static int[] RR0 = motor.PA_RR0;// 引用
/*
* Y轴控制刹车
* 公共参数数组成员
* LONG Multiple; 倍率 (1~500)
* LONG StartSpeed; 初始速度(1~8000)
* LONG DriveSpeed; 驱动速度(1~8000)
* LONG Acceleration; 加速度(125~1000000)
* LONG Deceleration; 减速度(125~1000000)
* LONG AccIncRate; 加速度变化率(954~62500000)
* LONG DecIncRate; 减速度变化率(954~62500000)
*
*
* 直线和S曲线参数数组成员
* LONG AxisNum; 轴号 (X轴 | Y轴 | X、Y轴)
* LONG LV_DV; 驱动方式 (连续 | 定长 )
* LONG DecMode; 减速方式 (自动减速 | 手动减速)
* LONG PulseMode; 脉冲方式 (CW/CCW方式 | CP/DIR方式)
* LONG Line_Curve; 运动方式 (直线 | 曲线)
* LONG Direction; 运动方向 (正方向 | 反方向)
* LONG nPulseNum; 定量输出脉冲数(0~268435455)
*/
protected void InitialPB(int urg, int dir, int pulse) {
if (urg <= 1)urg = 1;
if (urg >= 3)urg = 3;
// 公共参数数组赋值
YDatalist[0] = 1 * urg;
YDatalist[1] = 30;
YDatalist[2] = 2000 ;// 驱动速度 2000的倍数
YDatalist[3] = 1000 ;//随urg而变化
YDatalist[4] = YDatalist[3];
YDatalist[5] = 1000;
YDatalist[6] = YDatalist[5];
// 直线参数数组赋值
YLCData[0] = motor.YAXIS;// 油门用Y轴
YLCData[1] = motor.DV;
YLCData[2] = motor.AUTO;
YLCData[3] = motor.CWCCW;
YLCData[4] = motor.LINE;
YLCData[5] = dir;
YLCData[6] = pulse;// 发出的脉冲值
}
//恢复原位函数
protected static void ReleaseGun(){//以后加上紧急度urg和参考点 目前倍数为2
//在主程序中设置外部限位有效 尽量不用限位释放油门
// ControlMotor.SetLMTEnable(motor.YAXIS, motor.SUDENSTOP);//设置外部限位有效
int[] ydl=new int[7];//设置成局部变量
int[] ylc=new int[7];
//赋值数组
ydl[0]=2;//1*urg
ydl[1]=30;
ydl[2]=5000;
ydl[3]=3000;
ydl[4]=ydl[3];
ydl[5]=1000;
ydl[6]=ydl[5];
ylc[0]=motor.YAXIS;
ylc[1]=motor.LV;
ylc[2]=motor.AUTO;//
ylc[3]=motor.CWCCW;
ylc[4]=motor.LINE;
ylc[5]=motor.MDIRECTION;//认为正方向为踩油门的方向 即开度增大的方向
ylc[6]=ControlMotor.ReadLP(motor.YAXIS);//返回到0的脉冲数 如果有参考原点加入
ControlMotor.RunLVDV(motor.YAXIS, ydl, ylc);
ControlMotor.GetRR0Status(RR0);
while(RR0[1]!=0);//等待Y轴停止
//考虑接触开关失灵的状态
}
public boolean Rotate(int percent, int urgency) {
boolean bFinished = false;
int iLastPosition;
int iNextPosition;
int iCurrentPosition_brake;
int iPulse, iDirection;
iLastPosition = ControlMotor.ReadLP(motor.YAXIS);// 读上次脉冲数 得到当前位置
iNextPosition = percent * ALLSTEPS;
iCurrentPosition_brake = ControlMotor.ReadLP(motor.ZAXIS);
if (iCurrentPosition_brake >= 10) {
BrakeClass.ReleaseBrake();
}
// 先判断刹车状态 插入释放刹车语句
// if(percent<=5) ControlMotor.先判断刹车状态 如果刹车开度不为100 释放刹车后在运行油门
// 前提 认为电机顺时针转为正方向 开度增大
if (iNextPosition >= iLastPosition) {
iPulse = iNextPosition - iLastPosition;
iDirection = motor.PDIRECTION;
} else {
iPulse = iLastPosition - iNextPosition;
iDirection = motor.MDIRECTION;
}
InitialPB(urgency, iDirection, iPulse);
ControlMotor.RunLVDV(motor.YAXIS, YDatalist, YLCData);// 启动电机
ControlMotor.GetRR0Status(RR0);
while (RR0[1] != 0);// 等待电机运行完毕
bFinished = true;
return bFinished;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -