📄 motor.java
字号:
package cn.com.yuzhiqiang.pcimotor;
//import cn.com.yuzhiqiang.swt.*;//
//import org.eclipse.swt.SWT;//
//import org.eclipse.swt.widgets.Display;//
//import org.eclipse.swt.widgets.Label;//
//import org.eclipse.swt.widgets.Shell;//
public class motor {
/**
* @param args
*/
public static final int XAXIS = 0;
public static final int YAXIS = 1;
public static final int ZAXIS = 2;
public static final int UAXIS = 3;
public static final int ALLAXIS = 4;
public static final int DV = 0; // 定长驱动
public static final int LV = 1; // 连续驱动
public static final int CWCCW = 0; // CW/CCW方式
public static final int CPDIR = 1; // CP/DIR方式
public static final int MDIRECTION = 0;// 反方向
public static final int PDIRECTION = 1;// 正方向
public static final int LINE = 0; // 直线运动
public static final int CURVE = 1; // S曲线运动
public static final int LOGIC = 0; // 逻辑计数器
public static final int FACT = 1; // 实位计数器
public static final int SUDENSTOP = 0; // 立即停止
public static final int DECSTOP = 1; // 减速停止
public static final int AUTO = 0; // 自动减速
public static final int HAND = 1; // 手动减速
public static int[]PA_RR0=new int[16];
//public static int[] PA_DataList = new int[7];// 公共参数数组
//public static int[] PA_LCData = new int[7]; //直线和S曲线参数数组
public static int[] PA_RR3 = new int[16];
public static int[] PA_RR1 = new int[16];
public static int[] PA_Int = new int[16];//new080904
public static int[] PA_RR5 = new int[16];//new080904
// static MCShow mcshow;
/*
* 公共参数数组成员
* 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)
*/
// public int[] PA_DataList=new int[7];//公共参数数组
// public int[] PA_LCData=new int[7]; //直线和S曲线参数数组
@SuppressWarnings({ "static-access", "static-access", "static-access" })
public static void main(String[] args) {
// TODO 自动生成方法存根
//调试用 在各个类中设为私有成员
int[] PA_DataList = new int[7];// 公共参数数组
int[] PA_LCData = new int[7]; // 直线和S曲线参数数组
// int[] PA_RR3 = new int[16];//
// int[] PA_RR1 = new int[16];//
int command=0;//0,steeringwheel;1,gun;2,brake.//new080906
PciCreat.gethD();//主程序中用//
PciCreat.gethE();
PciCreat pct=new PciCreat();//
// int hDevice=pct.gethD();//
//----------------------------------------------------------------------------
int hDevice=pct.hDevice;//new0808171710
int hEvent=pct.hEvent;
double angle=100;
int []node0={30,10};//待定
long ep;
//----------------------------------------------------------------------------
//调试0
ControlMotor CM = new ControlMotor();//
//每个轴在自己的函数中赋值 保护成员 下面为调试用
PA_DataList[0] = 1;
PA_DataList[1] = 5;
PA_DataList[2] = 3000;
PA_DataList[3] = 1000;
PA_DataList[4] = 1000;
PA_DataList[5] = 1000;
PA_DataList[6] = 20000;
PA_LCData[0] = XAXIS;
PA_LCData[1] = LV;
PA_LCData[2] = AUTO;
PA_LCData[3] = CPDIR;
PA_LCData[4] = LINE;
PA_LCData[5] = PDIRECTION;
PA_LCData[6] = 20000;//200细分180度 8细分90度 2000;
ControlMotor.SetAccofst(XAXIS, 0);//三个轴偏移值均为0 主程序中应该有属于初始化部分
ControlMotor.SetAccofst(YAXIS, 0);
ControlMotor.SetAccofst(ZAXIS, 0);
ShowDataFrame frame = new ShowDataFrame();
frame.pack();
frame.setVisible(true);
//调试用
int readangle;//
SteeringWheelClass stw=new SteeringWheelClass();//
GunClass gun=new GunClass();
BrakeClass brake=new BrakeClass();
// CM.SetCOMPP(XAXIS, LOGIC, 5000);//可以软件限位//
// int[]PA_RR0=new int[16];//
// ControlMotor.GetRR0Status(PA_RR0);//
// CM.SetLMTEnable(XAXIS, SUDENSTOP);//
// ControlMotor.GetRR1Status(XAXIS,PA_RR1);//
// PA_RR1[13]++;//根据负方向限制信号驱动停止时,为1.
//test080907
//=================================================================================
if(command==0){//steeringwheel
// 此段循环代码:1、实现依靠光码盘的限位功能。2、看在定速情况下改变drvspeed时,电机的加减速状况。
// PA_DataList[2]=2000;
// int i=0;
PA_DataList[2]=3000;
PA_LCData[5] = PDIRECTION;
CM.InitLVDV(PA_DataList,PA_LCData);
CM.StartLVDV(XAXIS);
CM.Delays(10);
PA_DataList[2]-=500;
CM.InitLVDV(PA_DataList,PA_LCData);
CM.StartLVDV(XAXIS);
CM.Delays(10);
PA_DataList[2]-=500;
CM.InitLVDV(PA_DataList,PA_LCData);
CM.StartLVDV(XAXIS);
CM.Delays(10);
PA_DataList[2]-=500;
CM.InitLVDV(PA_DataList,PA_LCData);
CM.StartLVDV(XAXIS);
CM.Delays(10);
CM.InstStop(XAXIS);
PA_DataList[2]=500;
PA_LCData[5] = MDIRECTION;
CM.InitLVDV(PA_DataList,PA_LCData);
CM.StartLVDV(XAXIS);
CM.Delays(10);
PA_DataList[2]+=500;
CM.InitLVDV(PA_DataList,PA_LCData);
CM.StartLVDV(XAXIS);
CM.Delays(10);
PA_DataList[2]+=500;
CM.InitLVDV(PA_DataList,PA_LCData);
CM.StartLVDV(XAXIS);
CM.Delays(10);
PA_DataList[2]+=500;
CM.InitLVDV(PA_DataList,PA_LCData);
CM.StartLVDV(XAXIS);
CM.Delays(10);
CM.InstStop(XAXIS);
stw.Rotate(90,motor.PDIRECTION,1);
stw.Rotate(90,motor.MDIRECTION,1);
stw.Rotate(360,motor.PDIRECTION,1);
stw.Rotate(360,motor.MDIRECTION,1);
}
if(command==1){//gun
gun.Rotate(30,1);//Rotate(int percent, int urgency)
}
if(command==2){//brake
brake.Rotate(30, 1);//Rotate(int percent, int urgency)
}
if(command==3){//instantbrake
brake.InstantBrake();//
}
if(command==4){//return0
stw.ReturnRefAngle(0);// 返回参考点,public static boolean ReturnRefAngle(int r)
gun.ReleaseGun();
brake.ReleaseBrake();
}
//=================================================================================
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -