|
@ -36,18 +36,17 @@ void SingleAxisMotorControler::initialize(const char* name, IflytopCanProtocolSt |
|
|
m_currentPosReg = m_processer->activeReg(m_slave, SAMC_REG_STAT_CURRENT_POS, icps::kwr, 0); |
|
|
m_currentPosReg = m_processer->activeReg(m_slave, SAMC_REG_STAT_CURRENT_POS, icps::kwr, 0); |
|
|
m_exceptionReg = m_processer->activeReg(m_slave, SAMC_REG_STAT_EXCEPTION, icps::kwr, 0); |
|
|
m_exceptionReg = m_processer->activeReg(m_slave, SAMC_REG_STAT_EXCEPTION, icps::kwr, 0); |
|
|
|
|
|
|
|
|
cfg_acc_reg = m_processer->activeReg(m_slave, SAMC_REG_CFG_ACC, icps::kwr, 0); |
|
|
|
|
|
cfg_dec_reg = m_processer->activeReg(m_slave, SAMC_REG_CFG_DEC, icps::kwr, 0); |
|
|
|
|
|
cfg_velocity_reg = m_processer->activeReg(m_slave, SAMC_REG_CFG_VELOCITY, icps::kwr, 0); |
|
|
|
|
|
cfg_zero_shift_reg = m_processer->activeReg(m_slave, SAMC_REG_CFG_ZERO_SHIFT, icps::kwr, 0); // 零点偏移
|
|
|
|
|
|
cfg_runhome_velocity_reg = m_processer->activeReg(m_slave, SAMC_REG_CFG_RUNHOME_VELOCITY, icps::kwr, 0); // 归零速度
|
|
|
|
|
|
cfg_runtohome_dec_reg = m_processer->activeReg(m_slave, SAMC_REG_CFG_RUNTOHOME_DEC, icps::kwr, 0); // 归零减速度
|
|
|
|
|
|
cfg_runtohome_max_distance_reg = m_processer->activeReg(m_slave, SAMC_REG_CFG_RUNTOHOME_MAX_DISTANCE, icps::kwr, 0); // 归零最大距离
|
|
|
|
|
|
cfg_runtohome_leave_zero_point_distance_reg = |
|
|
|
|
|
m_processer->activeReg(m_slave, SAMC_REG_CFG_RUNTOHOME_LEAVE_ZERO_POINT_DISTANCE, icps::kwr, 0); // 离开零点距离
|
|
|
|
|
|
cfg_min_pos_reg = m_processer->activeReg(m_slave, SAMC_REG_CFG_MIN_POS, icps::kwr, 0); // 最小位置
|
|
|
|
|
|
cfg_max_pos_reg = m_processer->activeReg(m_slave, SAMC_REG_CFG_MAX_POS, icps::kwr, 0); // 最大位置
|
|
|
|
|
|
cfg_runtohome_keep_move_distance_reg = m_processer->activeReg(m_slave, SAMC_REG_CFG_RUNTOHOME_KEEP_MOVE_DISTANCE, icps::kwr, 0); // 归零阶段1移动距离
|
|
|
|
|
|
|
|
|
cfg_acc = m_processer->activeReg(m_slave, SAMC_REG_CFG_ACC, icps::kwr, 0); |
|
|
|
|
|
cfg_dec = m_processer->activeReg(m_slave, SAMC_REG_CFG_DEC, icps::kwr, 0); |
|
|
|
|
|
cfg_velocity = m_processer->activeReg(m_slave, SAMC_REG_CFG_VELOCITY, icps::kwr, 0); |
|
|
|
|
|
cfg_zero_shift = m_processer->activeReg(m_slave, SAMC_REG_CFG_ZERO_SHIFT, icps::kwr, 0); // 零点偏移
|
|
|
|
|
|
cfg_runhome_velocity = m_processer->activeReg(m_slave, SAMC_REG_CFG_RUNHOME_VELOCITY, icps::kwr, 0); // 归零速度
|
|
|
|
|
|
cfg_runtohome_dec = m_processer->activeReg(m_slave, SAMC_REG_CFG_RUNTOHOME_DEC, icps::kwr, 0); // 归零减速度
|
|
|
|
|
|
cfg_runtohome_max_distance = m_processer->activeReg(m_slave, SAMC_REG_CFG_RUNTOHOME_MAX_DISTANCE, icps::kwr, 0); // 归零最大距离
|
|
|
|
|
|
cfg_runtohome_leave_zero_point_distance = m_processer->activeReg(m_slave, SAMC_REG_CFG_RUNTOHOME_LEAVE_ZERO_POINT_DISTANCE, icps::kwr, 0); // 离开零点距离
|
|
|
|
|
|
cfg_min_pos = m_processer->activeReg(m_slave, SAMC_REG_CFG_MIN_POS, icps::kwr, 0); // 最小位置
|
|
|
|
|
|
cfg_max_pos = m_processer->activeReg(m_slave, SAMC_REG_CFG_MAX_POS, icps::kwr, 0); // 最大位置
|
|
|
|
|
|
cfg_runtohome_keep_move_distance = m_processer->activeReg(m_slave, SAMC_REG_CFG_RUNTOHOME_KEEP_MOVE_DISTANCE, icps::kwr, 0); // 归零阶段1移动距离
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
icps::error_t SingleAxisMotorControler::onHostRegisterWriteEvent(icps::WriteEvent* event) { |
|
|
icps::error_t SingleAxisMotorControler::onHostRegisterWriteEvent(icps::WriteEvent* event) { |
|
@ -88,7 +87,7 @@ icps::error_t SingleAxisMotorControler::rotate(int32_t velocity) { |
|
|
|
|
|
|
|
|
m_step_scheduler.reset(); |
|
|
m_step_scheduler.reset(); |
|
|
m_step_scheduler.pushActionAction([this, velocity](StepActionContext* context) { //
|
|
|
m_step_scheduler.pushActionAction([this, velocity](StepActionContext* context) { //
|
|
|
motor_rotate(velocity, cfg_acc_reg->getValue(), cfg_dec_reg->getValue()); |
|
|
|
|
|
|
|
|
motor_rotate(velocity, cfg_acc->getValue(), cfg_dec->getValue()); |
|
|
}); |
|
|
}); |
|
|
m_step_scheduler.pushActionIsDone([](StepActionContext* context) { return false; }); |
|
|
m_step_scheduler.pushActionIsDone([](StepActionContext* context) { return false; }); |
|
|
m_step_scheduler.regDoneCallback([this]() { changeToState(kstate_idle); }); |
|
|
m_step_scheduler.regDoneCallback([this]() { changeToState(kstate_idle); }); |
|
@ -104,7 +103,7 @@ icps::error_t SingleAxisMotorControler::moveTo(int32_t pos) { |
|
|
|
|
|
|
|
|
m_step_scheduler.reset(); |
|
|
m_step_scheduler.reset(); |
|
|
m_step_scheduler.pushActionAction([this, pos](StepActionContext* context) { //
|
|
|
m_step_scheduler.pushActionAction([this, pos](StepActionContext* context) { //
|
|
|
motor_moveTo(pos, cfg_velocity_reg->getValue(), cfg_acc_reg->getValue(), cfg_dec_reg->getValue()); |
|
|
|
|
|
|
|
|
motor_moveTo(pos, cfg_velocity->getValue(), cfg_acc->getValue(), cfg_dec->getValue()); |
|
|
}); |
|
|
}); |
|
|
m_step_scheduler.pushActionIsDone(bind(&SingleAxisMotorControler::motorIsStop, this, std::placeholders::_1)); |
|
|
m_step_scheduler.pushActionIsDone(bind(&SingleAxisMotorControler::motorIsStop, this, std::placeholders::_1)); |
|
|
m_step_scheduler.regDoneCallback([this]() { changeToState(kstate_idle); }); |
|
|
m_step_scheduler.regDoneCallback([this]() { changeToState(kstate_idle); }); |
|
@ -121,7 +120,7 @@ icps::error_t SingleAxisMotorControler::moveBy(int32_t pos) { |
|
|
|
|
|
|
|
|
m_step_scheduler.reset(); |
|
|
m_step_scheduler.reset(); |
|
|
m_step_scheduler.pushActionAction([this, pos](StepActionContext* context) { //
|
|
|
m_step_scheduler.pushActionAction([this, pos](StepActionContext* context) { //
|
|
|
motor_moveBy(pos, cfg_velocity_reg->getValue(), cfg_acc_reg->getValue(), cfg_dec_reg->getValue()); |
|
|
|
|
|
|
|
|
motor_moveBy(pos, cfg_velocity->getValue(), cfg_acc->getValue(), cfg_dec->getValue()); |
|
|
}); |
|
|
}); |
|
|
m_step_scheduler.pushActionIsDone(bind(&SingleAxisMotorControler::motorIsStop, this, std::placeholders::_1)); |
|
|
m_step_scheduler.pushActionIsDone(bind(&SingleAxisMotorControler::motorIsStop, this, std::placeholders::_1)); |
|
|
m_step_scheduler.regDoneCallback([this]() { changeToState(kstate_idle); }); |
|
|
m_step_scheduler.regDoneCallback([this]() { changeToState(kstate_idle); }); |
|
@ -149,10 +148,10 @@ icps::error_t SingleAxisMotorControler::runToHome() { |
|
|
m_motor->stop(); |
|
|
m_motor->stop(); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
motor_moveBy(-cfg_runtohome_max_distance_reg->getValue(), //
|
|
|
|
|
|
cfg_runhome_velocity_reg->getValue() * 2, //
|
|
|
|
|
|
cfg_acc_reg->getValue(), //
|
|
|
|
|
|
cfg_runtohome_dec_reg->getValue()); |
|
|
|
|
|
|
|
|
motor_moveBy(-cfg_runtohome_max_distance->getValue(), //
|
|
|
|
|
|
cfg_runhome_velocity->getValue() * 2, //
|
|
|
|
|
|
cfg_acc->getValue(), //
|
|
|
|
|
|
cfg_runtohome_dec->getValue()); |
|
|
}); |
|
|
}); |
|
|
m_step_scheduler.pushActionIsDone([this](StepActionContext* context) { |
|
|
m_step_scheduler.pushActionIsDone([this](StepActionContext* context) { |
|
|
if (motorIsStop(context)) { |
|
|
if (motorIsStop(context)) { |
|
@ -173,10 +172,10 @@ icps::error_t SingleAxisMotorControler::runToHome() { |
|
|
*/ |
|
|
*/ |
|
|
m_step_scheduler.pushActionAction([this](StepActionContext* context) { //
|
|
|
m_step_scheduler.pushActionAction([this](StepActionContext* context) { //
|
|
|
regGpioIrqProcesser(nullptr); |
|
|
regGpioIrqProcesser(nullptr); |
|
|
motor_moveBy(cfg_runtohome_leave_zero_point_distance_reg->getValue(), //
|
|
|
|
|
|
cfg_runhome_velocity_reg->getValue(), //
|
|
|
|
|
|
cfg_acc_reg->getValue(), //
|
|
|
|
|
|
cfg_dec_reg->getValue()); // 此时处于零点位置,先离开原点一定位置
|
|
|
|
|
|
|
|
|
motor_moveBy(cfg_runtohome_leave_zero_point_distance->getValue(), //
|
|
|
|
|
|
cfg_runhome_velocity->getValue(), //
|
|
|
|
|
|
cfg_acc->getValue(), //
|
|
|
|
|
|
cfg_dec->getValue()); // 此时处于零点位置,先离开原点一定位置
|
|
|
}); |
|
|
}); |
|
|
m_step_scheduler.pushActionIsDone(bind(&SingleAxisMotorControler::motorIsStop, this, std::placeholders::_1)); |
|
|
m_step_scheduler.pushActionIsDone(bind(&SingleAxisMotorControler::motorIsStop, this, std::placeholders::_1)); |
|
|
|
|
|
|
|
@ -190,10 +189,10 @@ icps::error_t SingleAxisMotorControler::runToHome() { |
|
|
m_runToHomeContext.zeroPointPos = m_motor->getXACTUAL(); |
|
|
m_runToHomeContext.zeroPointPos = m_motor->getXACTUAL(); |
|
|
m_motor->stop(); |
|
|
m_motor->stop(); |
|
|
}); |
|
|
}); |
|
|
motor_moveBy(-cfg_runtohome_leave_zero_point_distance_reg->getValue() * 1.5, //
|
|
|
|
|
|
cfg_runhome_velocity_reg->getValue(), //
|
|
|
|
|
|
cfg_acc_reg->getValue(), //
|
|
|
|
|
|
cfg_runtohome_dec_reg->getValue()); // 此时处于零点位置,先离开原点一定位置
|
|
|
|
|
|
|
|
|
motor_moveBy(-cfg_runtohome_leave_zero_point_distance->getValue() * 1.5, //
|
|
|
|
|
|
cfg_runhome_velocity->getValue(), //
|
|
|
|
|
|
cfg_acc->getValue(), //
|
|
|
|
|
|
cfg_runtohome_dec->getValue()); // 此时处于零点位置,先离开原点一定位置
|
|
|
}); |
|
|
}); |
|
|
m_step_scheduler.pushActionIsDone([this](StepActionContext* context) { |
|
|
m_step_scheduler.pushActionIsDone([this](StepActionContext* context) { |
|
|
if (motorIsStop(context)) { |
|
|
if (motorIsStop(context)) { |
|
@ -211,7 +210,7 @@ icps::error_t SingleAxisMotorControler::runToHome() { |
|
|
int32_t nowposition = m_motor->getXACTUAL(); |
|
|
int32_t nowposition = m_motor->getXACTUAL(); |
|
|
int32_t nowposition_real = nowposition - m_runToHomeContext.zeroPointPos; |
|
|
int32_t nowposition_real = nowposition - m_runToHomeContext.zeroPointPos; |
|
|
ZLOGI(m_name, "nowposition:%d,zeroPointPosition:%d", nowposition, m_runToHomeContext.zeroPointPos); |
|
|
ZLOGI(m_name, "nowposition:%d,zeroPointPosition:%d", nowposition, m_runToHomeContext.zeroPointPos); |
|
|
m_motor->setXACTUAL(nowposition_real - cfg_zero_shift_reg->getValue()); |
|
|
|
|
|
|
|
|
m_motor->setXACTUAL(nowposition_real - cfg_zero_shift->getValue()); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
/**
|
|
|
/**
|
|
@ -219,10 +218,10 @@ icps::error_t SingleAxisMotorControler::runToHome() { |
|
|
*/ |
|
|
*/ |
|
|
m_step_scheduler.pushActionAction([this](StepActionContext* context) { //
|
|
|
m_step_scheduler.pushActionAction([this](StepActionContext* context) { //
|
|
|
regGpioIrqProcesser(nullptr); |
|
|
regGpioIrqProcesser(nullptr); |
|
|
motor_moveTo(0, //
|
|
|
|
|
|
cfg_runhome_velocity_reg->getValue(), //
|
|
|
|
|
|
cfg_acc_reg->getValue(), //
|
|
|
|
|
|
cfg_dec_reg->getValue()); // 此时处于零点位置,先离开原点一定位置
|
|
|
|
|
|
|
|
|
motor_moveTo(0, //
|
|
|
|
|
|
cfg_runhome_velocity->getValue(), //
|
|
|
|
|
|
cfg_acc->getValue(), //
|
|
|
|
|
|
cfg_dec->getValue()); // 此时处于零点位置,先离开原点一定位置
|
|
|
}); |
|
|
}); |
|
|
m_step_scheduler.pushActionIsDone(bind(&SingleAxisMotorControler::motorIsStop, this, std::placeholders::_1)); |
|
|
m_step_scheduler.pushActionIsDone(bind(&SingleAxisMotorControler::motorIsStop, this, std::placeholders::_1)); |
|
|
|
|
|
|
|
|