调试速度档位设置,四挡 100 75,50,25 , 对应加速度,减速度10倍关系;验证通过

This commit is contained in:
zhengxuan.zhang
2024-02-28 13:39:04 +08:00
parent 7bcf86d55f
commit 27ce323db7
10 changed files with 143 additions and 81 deletions
+1
View File
@@ -324,6 +324,7 @@ enum HSI_MOTION_AXIS_TYPE
// This is the default "Sensor level" Y Axis - use on single Y axis machines
HSI_MOTION_AXIS_Z = 0x0004,
// This is the default "Sensor level" Z Axis - use on single Z axis machines
HSI_MOTION_AXIS_XYZ = 0x0007,
HSI_MOTION_AXIS_R = 0x0008,
// This is the default "Sensor level" R Axis - use on single R axis machines
HSI_MOTION_AXIS_X1 = 0x0010,
+134 -74
View File
@@ -254,7 +254,7 @@ HSI_Motion::HSI_Motion()
m_Home_Pos_Axis[i] = 0; //记住关闭电源时的位置,用于判断是否还需要回原点
}
//m_Home_Machine_Axis[4] = 0; //用于启动时需要回原点的轴号选择
m_Home_Machine_Axis[4] = 0; //用于启动时需要回原点的轴号选择
for (int i = 0; i < 5; i++)
{
m_N_Work_Limit[i] = -40; //负限位
@@ -1927,8 +1927,8 @@ HSI_STATUS HSI_Motion::Jog(UINT AxisTypes, double Speed)
int DecCurve(1);
int JogSpeed(1);
bool bJOGDir = Speed > 0 ? true : false; //运动方向
byte AxisNumber = static_cast<byte>(AxisConvertIndex(AxisTypes)); //Jog
jogAxisNum = AxisNumber;
jogDirFlag = bJOGDir;
m_Thread_State = HSI_THREAD_PAUSED;
@@ -1936,8 +1936,8 @@ HSI_STATUS HSI_Motion::Jog(UINT AxisTypes, double Speed)
{
//软限位
g_pLogger->SendAndFlushWithTime(
L"[Jog] Limit Enable, m_P_Work_Limit[AxisNumber] = %f,m_N_Work_Limit[AxisNumber] = %f\n",
m_P_Work_Limit[AxisNumber], m_N_Work_Limit[AxisNumber]);
L"[Jog] Limit Enable, Axis = %d, m_P_Work_Limit = %f,m_N_Work_Limit = %f\n",
AxisTypes,m_P_Work_Limit[AxisTypes], m_N_Work_Limit[AxisTypes]);
}
else
{
@@ -1946,9 +1946,9 @@ HSI_STATUS HSI_Motion::Jog(UINT AxisTypes, double Speed)
}
//是否回过家判断
if (m_Home_Machine_Axis[AxisNumber] == 0)
if (m_Home_Machine_Axis[AxisTypes] == 0)
{
g_pLogger->SendAndFlushWithTime(L"[Jog] Current Axis[%d] not homed \n", AxisNumber);
g_pLogger->SendAndFlushWithTime(L"[Jog] Current Axis[%d] not homed \n", AxisTypes);
return rStatus;
}
@@ -1962,13 +1962,6 @@ HSI_STATUS HSI_Motion::Jog(UINT AxisTypes, double Speed)
/*GetPositionXyz(1, now_pos[0], now_pos[1], now_pos[2], time);*/
//GetPositionEncPrfMulti(1, now_pos, Prf_pos, 1);
JogSpeed = abs(SpeedPercent(AxisNumber, Speed, DriveSpeed, StartSpeed, AccLine, DecLine, AccCurve, DecCurve));
g_pLogger->SendAndFlushWithTime(
L"[Jog] Speed: [%d], DriveSpeed: [%d], AccCurve: [%d], AccLine: [%d], DecCurve: [%d], DecLine: [%d]\n",
Speed, DriveSpeed, AccCurve, AccLine, DecCurve, DecLine);
//if (m_DeviceType != 3)
//{
// if (AxisTypes == AXIS_X /*&& m_motorType & 0x01*/)
@@ -2073,52 +2066,37 @@ HSI_STATUS HSI_Motion::Jog(UINT AxisTypes, double Speed)
//}
//速度限制
g_pLogger->SendAndFlushWithTime(
L"[Jog] DriveSpeed: [%d], AccCurve: [%d], AccLine: [%d], DecCurve: [%d], DecLine: [%d]\n",
DriveSpeed, AccCurve, AccLine, DecCurve, DecLine);
JogSpeed = abs(SpeedPercent(AxisTypes, Speed, DriveSpeed, StartSpeed, AccLine, DecLine, AccCurve, DecCurve));
g_pLogger->SendAndFlushWithTime(
L"[Jog] Speed: [%d], DriveSpeed: [%d],AccLine: [%d], DecLine: [%d] AccCurve: [%d], DecCurve: [%d],\n",
Speed, DriveSpeed, AccLine, DecLine,AccCurve, DecCurve );
//转到真实ACS平台轴号,并开始执行
byte AxisNumber = static_cast<byte>(AxisConvertIndex(AxisTypes)); //Jog
double motionParam[5] = { DriveSpeed,AccLine*10 , DecLine*10, AccCurve,DecCurve }; //速度,加速度,减速度,Kill, jerk
SetSingleAxisParam(AxisNumber, motionParam);
// 急停判断
if ((StartSpeed < 250) && (DriveSpeed < 6))
{
m_IsUseJerk = 1;
g_pLogger->SendAndFlushWithTime(L"[Jog] Use Jerk\n");
}
else
{
m_IsUseJerk = 0;
g_pLogger->SendAndFlushWithTime(L"[Jog] No Use Jerk\n");
}
//打印当前轴的速度
double motionParam[5] = {0};
GetMotorParam(jogAxisNum, motionParam);
g_pLogger->SendAndFlushWithTime(
L"[Jog] Axis= %d,Current Velocity = %.2f, Acceleration= %.2f, Deceleration= %.2f, KillDeceleration= %.2f, Jerk= %.2f\n",
jogAxisNum, motionParam[0], motionParam[1], motionParam[2], motionParam[3], motionParam[4]);
//开始JOG运动
if (!bJOGDir)
{
DriveSpeed = DriveSpeed * (-1); // Negative direction : Using - (minus) velocity
}
//int acsDirection = bJOGDir ? ACSC_POSITIVE_DIRECTION : ACSC_NEGATIVE_DIRECTION; //正方向,或 负方向
//设置加速度
if (!acsc_SetAccelerationImm(handleACS, jogAxisNum, AccLine, nullptr))
{
g_pLogger->SendAndFlushWithTime(L"[Jog] ACS SetAccelerationImm failed, Aixs:[%d] AccCurve:[%d]\n",
jogAxisNum,
AccLine);
ErrorsHandler();
DriveSpeed = DriveSpeed * (-1); // Negative direction : Using - (minus) velocity //正方向,或 负方向
}
//设置减速度
if (!acsc_SetDeceleration(handleACS, jogAxisNum, AccLine, nullptr))
{
g_pLogger->SendAndFlushWithTime(L"[Jog] ACS SetDeceleration failed, Aixs:[%d] DecCurve:[%d]\n", jogAxisNum,
AccLine);
ErrorsHandler();
}
if (!acsc_Jog(handleACS, 0, jogAxisNum, DriveSpeed, nullptr))
if (!acsc_Jog(handleACS, 0, AxisNumber, DriveSpeed, nullptr))
{
printf("[Jog] 轴[%d] [%s] 方向移动失败", AxisTypes, bJOGDir ? "" : "");
g_pLogger->SendAndFlushWithTime(L"[Jog] failed, Aixs:[%d] JOGDir:[%S]\n", AxisTypes,
@@ -2128,7 +2106,7 @@ HSI_STATUS HSI_Motion::Jog(UINT AxisTypes, double Speed)
jogMoving = true;
g_pLogger->SendAndFlushWithTime(L"[Jog] Out, DriveSpeed = %d AccCurve:[%d] DecCurve:[%d]\n", DriveSpeed,
g_pLogger->SendAndFlushWithTime(L"[Jog] Out, AxisNumber = %d, DriveSpeed = %d AccCurve:[%d] DecCurve:[%d]\n", AxisNumber, DriveSpeed,
AccLine, AccLine);
}
return rStatus;
@@ -3573,6 +3551,7 @@ HSI_STATUS HSI_Motion::SetPositionXyz(UINT AxisTypes, double PositionX, double P
if (CurrentMotionState != E_SO7_MOTION_MOVETO) //当前运动状态
{
CurrentMotionState = E_SO7_MOTION_MOVETO;
//限位功能
LimitOver(HSI_MOTION_AXIS_X, PositionX);
LimitOver(HSI_MOTION_AXIS_Y, PositionY);
@@ -3589,26 +3568,25 @@ HSI_STATUS HSI_Motion::SetPositionXyz(UINT AxisTypes, double PositionX, double P
m_PosThread[4] = m_PositionA;
//打印当前位置,目标位置
g_pLogger->SendAndFlushWithTime(
L"[SetPositionXyz] Pos[1] = %.4f,Pos[2] = %.4f,Pos[3] = %.4f,Pos[4] = %.4f, Resolution[1] = %.4f\n",
m_PosThread[1] * m_Resolution[1], m_PosThread[2] * m_Resolution[2], m_PosThread[3] * m_Resolution[3],
m_PosThread[4] * m_Resolution[4], m_Resolution[1]);
g_pLogger->SendAndFlushWithTime(L"[SetPositionXyz] Pos[1] = %.4f, Pos[2] = %.4f, Pos[3] = %.4f\n", PositionX,PositionY, PositionZ);
//g_pLogger->SendAndFlushWithTime(
// L"[SetPositionXyz] Pos[1] = %.4f,Pos[2] = %.4f,Pos[3] = %.4f,Pos[4] = %.4f, Resolution[1] = %.4f\n",
// m_PosThread[1] * m_Resolution[1], m_PosThread[2] * m_Resolution[2], m_PosThread[3] * m_Resolution[3],
// m_PosThread[4] * m_Resolution[4], m_Resolution[1]);
g_pLogger->SendAndFlushWithTime(L"[SetPositionXyz] PositionX = %.4f, PositionY = %.4f, PositionZ = %.4f\n", PositionX,PositionY, PositionZ);
//设置运动参数
//SetSingleAxisMotionParams
//打印轴当前运动参数
byte AxisNumber = static_cast<byte>(AxisConvertIndex(AxisTypes)); //轴号换算
double motionParam[5] = {0};
GetMotorParam(AxisNumber, motionParam); //获取单轴运动参数
g_pLogger->SendAndFlushWithTime(
L"[SetPositionXyz] Axis= %.2f, Velocity = %.2f, Acceleration= %.2f, Deceleration= %.2f, KillDeceleration= %.2f, Jerk= %.2f\n",
jogAxisNum, motionParam[0], motionParam[1], motionParam[2], motionParam[3], motionParam[4]);
//设置轴运动速度,TO-DO
//开始运动到指定位置,多轴运动
int Axes[] = {ACSC_AXIS_1, ACSC_AXIS_0,ACSC_AXIS_8, -1}; //需要运动的轴
double Points[] = {PositionY, PositionX, PositionZ}; //目标位置点
double Points[] = {PositionX, PositionY, PositionZ}; //目标位置点
if (!acsc_ToPointM(handleACS, 0, Axes, Points, nullptr)) //移动到绝对位置
{
g_pLogger->SendAndFlushWithTime(L"[SetPositionXyz] ACS Multi Motion Error\n");
@@ -3688,49 +3666,98 @@ int HSI_Motion::CaculateStepMotorACC(int pos, int maxacc, int minacc)
* \param motionParam
* \return
*/
HSI_STATUS HSI_Motion::GetMotorParam(int AXIS, double motionParam[5])
HSI_STATUS HSI_Motion::GetSingleAxisParam(int AXIS, double motionParam[5])
{
auto rStatus = HSI_STATUS_NORMAL;
if (handleACS != ACSC_INVALID)
{
g_pLogger->SendAndFlushWithTime(L"[GetMotorParam] In\n");
g_pLogger->SendAndFlushWithTime(L"[GetSingleAxisParam] In\n");
//依次是 速度
if (!acsc_GetVelocity(handleACS, AXIS, motionParam + 0, nullptr))
{
g_pLogger->SendAndFlushWithTime(L"[GetMotorParam] acsc_GetVelocity error\n");
g_pLogger->SendAndFlushWithTime(L"[GetSingleAxisParam] acsc_GetVelocity error\n");
rStatus = HSI_ACS_ERROR;
ErrorsHandler();
}
// 加速度
if (!acsc_GetAcceleration(handleACS, AXIS, motionParam + 1, nullptr))
{
g_pLogger->SendAndFlushWithTime(L"[GetMotorParam] acsc_GetAcceleration error\n");
g_pLogger->SendAndFlushWithTime(L"[GetSingleAxisParam] acsc_GetAcceleration error\n");
rStatus = HSI_ACS_ERROR;
ErrorsHandler();
}
//减速、
if (!acsc_GetDeceleration(handleACS, AXIS, motionParam + 2, nullptr))
{
g_pLogger->SendAndFlushWithTime(L"[GetMotorParam] acsc_GetDeceleration error\n");
g_pLogger->SendAndFlushWithTime(L"[GetSingleAxisParam] acsc_GetDeceleration error\n");
rStatus = HSI_ACS_ERROR;
ErrorsHandler();
}
// 杀死速度
if (!acsc_GetKillDeceleration(handleACS, AXIS, motionParam + 3, nullptr))
{
g_pLogger->SendAndFlushWithTime(L"[GetMotorParam] acsc_GetKillDeceleration error\n");
g_pLogger->SendAndFlushWithTime(L"[GetSingleAxisParam] acsc_GetKillDeceleration error\n");
rStatus = HSI_ACS_ERROR;
ErrorsHandler();
}
//抖动
if (!acsc_GetJerk(handleACS, AXIS, motionParam + 4, nullptr))
{
g_pLogger->SendAndFlushWithTime(L"[GetMotorParam] acsc_GetJerk error\n");
g_pLogger->SendAndFlushWithTime(L"[GetSingleAxisParam] acsc_GetJerk error\n");
rStatus = HSI_ACS_ERROR;
ErrorsHandler();
}
g_pLogger->SendAndFlushWithTime(L"[GetMotorParam] Out\n");
g_pLogger->SendAndFlushWithTime(L"[GetSingleAxisParam] Out\n");
}
return rStatus;
}
//===========================================================================
HSI_STATUS HSI_Motion::SetSingleAxisParam(int AXIS, double motionParam[5])
{
auto rStatus = HSI_STATUS_NORMAL;
if (handleACS != ACSC_INVALID)
{
g_pLogger->SendAndFlushWithTime(L"[SetSingleAxisParam] In\n");
//依次是 速度
if (!acsc_SetVelocity(handleACS, AXIS, motionParam[0], nullptr))
{
g_pLogger->SendAndFlushWithTime(L"[SetSingleAxisParam] acsc_SetVelocity error\n");
rStatus = HSI_ACS_ERROR;
ErrorsHandler();
}
// 加速度
if (!acsc_SetAcceleration(handleACS, AXIS, motionParam[1], nullptr))
{
g_pLogger->SendAndFlushWithTime(L"[SetSingleAxisParam] acsc_SetAcceleration error\n");
rStatus = HSI_ACS_ERROR;
ErrorsHandler();
}
//减速度
if (!acsc_SetDeceleration(handleACS, AXIS, motionParam[2], nullptr))
{
g_pLogger->SendAndFlushWithTime(L"[SetSingleAxisParam] acsc_SetDeceleration error\n");
rStatus = HSI_ACS_ERROR;
ErrorsHandler();
}
//// 杀死速度
//if (!acsc_SetKillDeceleration(handleACS, AXIS, motionParam[3], nullptr))
//{
// g_pLogger->SendAndFlushWithTime(L"[SetSingleAxisParam] acsc_SetKillDeceleration error\n");
// rStatus = HSI_ACS_ERROR;
// ErrorsHandler();
//}
////抖动
//if (!acsc_SetJerk(handleACS, AXIS, motionParam[4], nullptr))
//{
// g_pLogger->SendAndFlushWithTime(L"[SetSingleAxisParam] acsc_SetJerk error\n");
// rStatus = HSI_ACS_ERROR;
// ErrorsHandler();
//}
g_pLogger->SendAndFlushWithTime(L"[SetSingleAxisParam] Out\n");
}
return rStatus;
@@ -4047,16 +4074,21 @@ HSI_STATUS HSI_Motion::Load_EF3_Motion_Inifile(CString GoogolIniFile)
csAppPath)); //超时时间(0.1ms)
GetPrivateProfileString(L"RESOLUTION", L"SCALE_RESOLUTION_" + axisNum[i], L"0.0004",
temp.GetBufferSetLength(50), 50, csAppPath);
m_Resolution[i] = (atof(T2A(temp)));
m_Resolution[i] = (atof(T2A(temp)));//分辨率
GetPrivateProfileString(L"LIMIT", L"NEG_WORKING_LIMIT_" + axisNum[i], L"-40", temp.GetBufferSetLength(50),
50, csAppPath);
m_N_Work_Limit[i] = (atof(T2A(temp)));
m_N_Work_Limit[i] = (atof(T2A(temp))); //各轴负限位
GetPrivateProfileString(L"LIMIT", L"POS_WORKING_LIMIT_" + axisNum[i], L"160", temp.GetBufferSetLength(50),
50, csAppPath);
m_P_Work_Limit[i] = (atof(T2A(temp)));
m_P_Work_Limit[i] = (atof(T2A(temp)));//各轴正限位
//打印正负限位
g_pLogger->SendAndFlushWithTime(L"[Load_EF3_Motion_Inifile] m_N_Work_Limit[%d]: %.2f, m_P_Work_Limit[%d]: %.2f\n",
i, m_N_Work_Limit[i], i, m_P_Work_Limit[i]);
m_Home_Time[i] = static_cast<long>(GetPrivateProfileInt(L"HOME", L"HOME_TIME_" + axisNum[i], 1500,
csAppPath));
csAppPath)); //回家超时时间(0.1ms)
m_Home_AddJogGears[i] = GetPrivateProfileInt(L"HOME", L"HOME_ADD_JOGCHOICE_" + axisNum[i], 100, csAppPath);
m_Home_DecJogGears[i] = GetPrivateProfileInt(L"HOME", L"HOME_DEC_JOGCHOICE_" + axisNum[i], 100, csAppPath);
m_SetPotion_Count[i] = GetPrivateProfileInt(L"SET_POSITION_SPEED", L"SET_POSITION_COUNT_" + axisNum[i], 10,
@@ -4090,7 +4122,7 @@ HSI_STATUS HSI_Motion::Load_EF3_Motion_Inifile(CString GoogolIniFile)
/*m_JogDriveSpeed[j][i] = GetPrivateProfileInt(L"JOG_SPEED", L"JOG_DRIVESPEED_" , 10, csAppPath);*/
//m_JogDriveSpeed[j][i] = speed / (m_Resolution[j] * 50);//速度转换为脉冲
m_JogDriveSpeed[j][i] = speed; //直接读取速度
g_pLogger->SendAndFlushWithTime(L"[Load_EF3_Motion_Inifile] m_JogDriveSpeed[%d][%d]: %.2f %ld\n", i, j,
g_pLogger->SendAndFlushWithTime(L"[Load_EF3_Motion_Inifile] m_JogDriveSpeed[%d][%d]: %ld %ld\n", i, j,
speed, m_JogDriveSpeed[j][i]); //打印配置文件 档位速度
GetPrivateProfileString(L"JOG_SPEED", L"JOG_STARTSPEED_" + strGear[i] + axisNum[j], L"10",
@@ -7865,7 +7897,7 @@ double HSI_Motion::LimitOver(UINT AxisTypes, double& LimitPos) //
{
switch (AxisNumber)
{
case 1: // X 轴
case HSI_MOTION_AXIS_X: // X 轴
{
if (LimitPos >= m_P_Work_Limit[1])
{
@@ -7877,7 +7909,7 @@ double HSI_Motion::LimitOver(UINT AxisTypes, double& LimitPos) //
}
break;
}
case 2: //Y 轴
case HSI_MOTION_AXIS_Y: //Y 轴
{
if (LimitPos >= m_P_Work_Limit[2])
{
@@ -7889,7 +7921,7 @@ double HSI_Motion::LimitOver(UINT AxisTypes, double& LimitPos) //
}
break;
}
case 3:
case HSI_MOTION_AXIS_Z:
{
if (LimitPos >= m_P_Work_Limit[3])
{
@@ -7901,7 +7933,7 @@ double HSI_Motion::LimitOver(UINT AxisTypes, double& LimitPos) //
}
break;
}
case 4: //Z轴
case HSI_MOTION_AXIS_R:
{
if (LimitPos >= m_P_Work_Limit[4])
{
@@ -7956,6 +7988,34 @@ short HSI_Motion::AxisConvertIndex(UINT AxisTypes)
return AxisNumber;
}
//===========================================================================
void HSI_Motion::SetSingleAxisMotionParams(UINT AxisTypes, double SetmotionParam[5]) //设置单轴运动参数
{
g_pLogger->SendAndFlushWithTime(L"[SetSingleAxisMotionParams] In\n");
double getMotionParam[5] = { 0 };
//轴号转换
byte AxisNumber = static_cast<byte>(AxisConvertIndex(AxisTypes)); //SetSingleAxisMotionParams
//打印轴当前运动参数
GetSingleAxisParam(AxisNumber, getMotionParam); //获取单轴运动参数
g_pLogger->SendAndFlushWithTime(
L"[before] Axis= %.2f, Velocity = %.2f, Acceleration= %.2f, Deceleration= %.2f, KillDeceleration= %.2f, Jerk= %.2f\n",
jogAxisNum, getMotionParam[0], getMotionParam[1], getMotionParam[2], getMotionParam[3], getMotionParam[4]);
//设置单轴参数
SetSingleAxisParam(AxisTypes, SetmotionParam);
//打印轴当前运动参数
GetSingleAxisParam(AxisNumber, getMotionParam); //获取单轴运动参数
g_pLogger->SendAndFlushWithTime(
L"[after] Axis= %.2f, Velocity = %.2f, Acceleration= %.2f, Deceleration= %.2f, KillDeceleration= %.2f, Jerk= %.2f\n",
jogAxisNum, getMotionParam[0], getMotionParam[1], getMotionParam[2], getMotionParam[3], getMotionParam[4]);
g_pLogger->SendAndFlushWithTime(L"[SetSingleAxisMotionParams] Out\n");
}
//===========================================================================
short HSI_Motion::IndexConvertAxis(int Index)
{
+3 -2
View File
@@ -238,8 +238,8 @@ public:
* \param motionParam
* \return
*/
HSI_STATUS HSI_Motion::GetMotorParam(int AXIS, double motionParam[5]);
HSI_STATUS HSI_Motion::GetSingleAxisParam(int AXIS, double motionParam[5]);
HSI_STATUS HSI_Motion::SetSingleAxisParam(int AXIS, double motionParam[5]);
/**
* \brief
* \param AxisTypes
@@ -636,6 +636,7 @@ public:
*/
short AxisConvertIndex(UINT AxisTypes);
short IndexConvertAxis(int Index);
void SetSingleAxisMotionParams(UINT AxisTypes, double motionParam[5]);
double LimitOver(UINT AxisTypes, double& LimitPos);
int P2P(short AxisNumber, long Pos, double Speed, double Acc);
void DoEvents();
+2 -2
View File
@@ -12,5 +12,5 @@
#define HSI_VERSION_REVNUM
#define HSI_VERSION_BUILD_DATE _T(__DATE__ )
#define HSI_VERSION_BUILD_TIME _T(__TIME__ )
#define HSI_FILE_DESCRIPTION "2024.02.27 / 16:28 "
#define HSI_FILE_CSDESCRIPTION _T("2024.02.27 / 16:28 ")
#define HSI_FILE_DESCRIPTION "2024.02.28 / 11:38 "
#define HSI_FILE_CSDESCRIPTION _T("2024.02.28 / 11:38 ")
Binary file not shown.
Binary file not shown.
+3 -3
View File
@@ -75,9 +75,9 @@ namespace HSI_SEVENOCEAN_EF1_CsTest
#endregion
//6 是否回家
var bHomed = true;
rStatus = Motion.IsHomed(ref bHomed);
Console.WriteLine("Motion.IsHomed:{0}", rStatus);
//var bHomed = true;
//rStatus = Motion.IsHomed(ref bHomed);
//Console.WriteLine("Motion.IsHomed:{0}", rStatus);
var bexit = false;
var SpeedGear = 0.3;
var dPos = new double[3];
Binary file not shown.