注:由于电机不带编码器,无法做home和当前位置信息读取!
功能:
三个轴的点位运动:前进 后退,并分别显示每个轴的移动脉冲数(可以换算为距离)!
开发环境:VS2017
硬件设备:固高科技三维移动平台
源码:
代码语言:javascript复制using System;
using System.Windows.Forms;
using gts;
namespace 三维平移台控制系统
{
public partial class mainFrom : DevComponents.DotNetBar.OfficeForm
{
public mainFrom()
{
this.EnableGlass = false;
InitializeComponent();
}
short Rtn;
int vel = 0;
int[] pos= {0,0,0 };
bool flag = false;
uint clk;
double prfpos, prfvel, encpos, encvel;
short AXIS = 1;
private void buttonX1_Click(object sender, EventArgs e)
{
mc.GT_ZeroPos(AXIS, 1);
pos[AXIS-1] = 0;
}
private void buttonX2_Click(object sender, EventArgs e)
{
//Rtn = mc.GT_Close();
Rtn = mc.GT_PrfTrap(AXIS);
mc.TTrapPrm trapprm;
mc.GT_GetTrapPrm(AXIS, out trapprm);
trapprm.acc = 0.1;//设置加速度
trapprm.dec = 0.1;//设置减速度
trapprm.smoothTime = 1;
mc.GT_SetTrapPrm(AXIS, ref trapprm);
pos[AXIS-1] = Convert.ToInt32(textBoxX1.Text);
vel = Convert.ToInt32(textBoxX2.Text);
mc.GT_SetPos(AXIS, pos[AXIS-1]);
mc.GT_SetVel(AXIS, vel);
// mc.GT_Update(AXIS);
mc.GT_Update(1 << (AXIS - 1));
//MessageBox.Show((1 << (AXIS - 1)).ToString());
}
private void buttonX3_Click(object sender, EventArgs e)
{
//Rtn = mc.GT_Close();
Rtn = mc.GT_PrfTrap(AXIS);
mc.TTrapPrm trapprm;
mc.GT_GetTrapPrm(AXIS, out trapprm);
trapprm.acc = 0.1;
trapprm.dec = 0.1;
trapprm.smoothTime = 1;
mc.GT_SetTrapPrm(AXIS, ref trapprm);
pos[AXIS-1] -= Convert.ToInt32(textBoxX1.Text);
vel = Convert.ToInt32(textBoxX2.Text);
mc.GT_SetPos(AXIS, pos[AXIS-1]);
mc.GT_SetVel(AXIS, vel);
//mc.GT_Update(AXIS);
mc.GT_Update(1 << (AXIS - 1));
}
private void timer1_Tick(object sender, EventArgs e)
{
//if ()
//{
// mc.GT_GetPrfPos(AXIS, out prfpos, 1, out clk);// profile 起始轴号
// mc.GT_GetEncPos(AXIS, out encpos, 1, out clk);// encoder 起始轴号
// textBox3.Text = prfpos.ToString();
// textBox5.Text = encpos.ToString();
// mc.GT_GetPrfVel(AXIS, out prfvel, 1, out clk);// 起始规划轴号
// mc.GT_GetEncVel(AXIS, out encvel, 1, out clk);// encoder 起始轴号
// textBox4.Text = prfvel.ToString();
// textBox6.Text = encvel.ToString();
//}
mc.GT_GetPrfPos(AXIS, out prfpos, 1, out clk);// profile 起始轴号
mc.GT_GetPrfVel(AXIS, out prfvel, 1, out clk);// 起始规划轴号
if (AXIS == 1)
{
labelX4.Text = "规划位置 : " prfpos.ToString();
labelX5.Text = "规划速度 : " prfvel.ToString();
}
else if (AXIS == 2)
{
labelX6.Text = "规划位置 : " prfpos.ToString();
labelX7.Text = "规划速度 : " prfvel.ToString();
}
else if (AXIS == 3)
{
labelX8.Text = "规划位置 : " prfpos.ToString();
labelX9.Text = "规划速度 : " prfvel.ToString();
}
}
private void mainFrom_Load(object sender, EventArgs e)
{
comboBoxEx1.SelectedIndex = 0;
textBoxX1.Text = "2000";
textBoxX2.Text = "10";
/*初始化*/
Rtn = mc.GT_Open(0, 1);
Rtn = mc.GT_Reset();
Rtn = mc.GT_LoadConfig("GTS800.cfg"); ;
Rtn = mc.GT_ClrSts(1, 8); //axis 起始轴号,count
timer1.Enabled = true;
}
private void comboBoxEx1_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxEx1.SelectedItem.ToString())
{
case "X轴":
AXIS = 1; break;
case "Y轴":
AXIS = 2; break;
case "Z轴":
AXIS = 3; break;
default:break;
}
}
}
}
bin文件:
运行效果: