📄 brakeclass.java
字号:
package cn.com.yuzhiqiang.pcimotor;
public class BrakeClass extends ControlMotor {
final static int ALLSTEPS=334;//算出后赋值 比如60度10细分对应的脉冲值
protected static int[] ZDatalist=new int[7];//公共参数数组
protected static int[] ZLCData=new int[7];//直线和S曲线参数数组
static int RefAngle=0;//设置参考原点
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 static void SetRefAngle(int reangle){
RefAngle=reangle;
}
protected void InitialPB(int urg,int dir,int pulse){
if(urg<=1)urg=1;
if(urg>=3)urg=3;
//公共参数数组赋值
ZDatalist[0]=1*urg;//倍率 (1~500)
ZDatalist[1]=1;//初始速度(1~8000)
ZDatalist[2]=2000;//驱动速度 2000*multiple
ZDatalist[3]=1000;//加速度为 1000*multiple
ZDatalist[4]=ZDatalist[3];//减速度(125~1000000)
ZDatalist[5]=1000;//加速度变化率(954~62500000)
ZDatalist[6]=ZDatalist[5];//减速度变化率(954~62500000)
//直线参数数组赋值
ZLCData[0]=motor.ZAXIS;//刹车用Z轴
ZLCData[1]=motor.DV;
ZLCData[2]=motor.AUTO;
ZLCData[3]=motor.CWCCW;
ZLCData[4]=motor.LINE;
ZLCData[5]=dir;
ZLCData[6]=pulse;//发出的脉冲值
}
//释放刹车函数 待验证 外部限位 恢复原点函数
protected static void ReleaseBrake(){//考虑urg紧急度目前为3和参考原点
//外部限位在主程序中设置
// ControlMotor.SetLMTEnable(motor.ZAXIS, motor.SUDENSTOP);//设置外部限位有效
int[] zdl=new int[7];//设置成局部变量
int[] zlc=new int[7];
//赋值数组
zdl[0]=3;
zdl[1]=1;
zdl[2]=5000;
zdl[3]=3000;
zdl[4]=zdl[3];
zdl[5]=1000;
zdl[6]=zdl[5];
zlc[0]=motor.ZAXIS;
zlc[1]=motor.LV;
zlc[2]=motor.AUTO;//连续时没有意义 已验证
zlc[3]=motor.CWCCW;
zlc[4]=motor.LINE;
zlc[5]=motor.MDIRECTION;//认为正方向为踩油门的方向 即开度增大的方向
zlc[6]=ControlMotor.ReadLP(motor.ZAXIS);// 返回脉冲数 考虑参考原点时为-RefAngle
ControlMotor.RunLVDV(motor.ZAXIS, zdl, zlc);
ControlMotor.GetRR0Status(RR0);
while(RR0[2]!=0);//等待Z轴电机停止
}
public boolean Rotate(int percent,int urgency){
boolean bFinished=false;
int iLastPosition;
int iNextPosition;
int iCurrentPosition_gun;
int iPulse,iDirection;
iLastPosition=ControlMotor.ReadLP(motor.ZAXIS);//读上次脉冲数 得到当前位置
iNextPosition=percent*ALLSTEPS;
iCurrentPosition_gun=ControlMotor.ReadLP(motor.YAXIS);
if(iCurrentPosition_gun>=10){
GunClass.ReleaseGun();
}//先判断刹车状态 插入释放刹车语句
// 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.ZAXIS, ZDatalist, ZLCData);//启动电机
ControlMotor.GetRR0Status(RR0);
while(RR0[2]!=0);//等待Z轴电机运行完毕
bFinished=true;
return bFinished;
}
//急刹车函数
public static boolean InstantBrake(){
boolean bFinished=false;
// int iStep=ALLSTEPS-ControlMotor.ReadLP(motor.ZAXIS);
int[] zdl=new int[7];//设置成局部变量
int[] zlc=new int[7];
//赋值数组
zdl[0]=3;
zdl[1]=1;
zdl[2]=5000;
zdl[3]=3000;
zdl[4]=zdl[3];
zdl[5]=1000;
zdl[6]=zdl[5];
zlc[0]=motor.ZAXIS;
zlc[1]=motor.LV;
zlc[2]=motor.AUTO;//连续时没有意义 已验证
zlc[3]=motor.CWCCW;
zlc[4]=motor.LINE;
zlc[5]=motor.PDIRECTION;//认为正方向为踩刹车的方向 即开度增大的方向
zlc[6]=ALLSTEPS-ControlMotor.ReadLP(motor.ZAXIS);// 用不着这么多步就能停止 以后改
ControlMotor.RunLVDV(motor.ZAXIS, zdl, zlc);
ControlMotor.GetRR0Status(RR0);
while(RR0[2]!=0);//等待Z轴电机停止
bFinished=true;
return bFinished;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -