123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- #include "stdafx.h"
- #include "SelfTestModel.h"
- #include "SelfTestMotionStageArgs.h"
- #include "MotionStages.h"
- #include "IMachineryManager.h"
- #include "ConfigurerMotion.h"
- #include "IPositionManager.h"
- #include "ITubeAngleController.h"
- #include "ITubeHeightController.h"
- using namespace DIOS::Dev::Detail::MachineryECOM;
- SelfTestModel::SelfTestModel()
- :m_stageArgs(new SelfTestMotionStageArgs()),
- m_coordinates(nullptr),
- m_tubeAngle(nullptr),
- m_tubeHeight(nullptr)
- {
- }
- SelfTestModel::~SelfTestModel()
- {
- if (m_stageArgs)
- {
- delete m_stageArgs;
- m_stageArgs = nullptr;
- }
- }
- void SelfTestModel::ChangeStage(const std::string &stageName)
- {
- m_StageName = stageName;
- OnMotionStage(stageName);
- }
- std::string SelfTestModel::GetStageName()
- {
- return m_StageName;
- }
- IMotionStageArgs *SelfTestModel::GetStageArgs()
- {
- return m_stageArgs;
- }
- void SelfTestModel::Initialize(IMachineryManager *machineryManager, IPositionManager *coordinates)
- {
- m_coordinates = coordinates;
- m_tubeAngle = (ITubeAngleController *)(machineryManager->Resove(CONTROLLER_TUBE_ANGLE));
- m_tubeHeight = (ITubeHeightController *)(machineryManager->Resove(CONTROLLER_TUBE_HEIGHT));
- }
- void SelfTestModel::LoadMachineryParams(ResDataObject ¶ms)
- {
- }
- void SelfTestModel::LoadModelParams(ResDataObject ¶ms)
- {
- }
- void SelfTestModel::SetTechnicalParams(ResDataObject ¶ms)
- {
- }
- void SelfTestModel::OnFeedbackMotionParams(ResDataObject ¶ms)
- {
- }
- BOOL SelfTestModel::GetMotionParams(ResDataObject ¶ms)
- {
- return TRUE;
- }
- void SelfTestModel::OnMotionStage(const std::string &stagename)
- {
- if (stagename == SELFTEST_STAGE_TUBE_HEIGHT_MOVETO_TARGET)
- {
- OnStageTubeHeightMoveToTarget();
- }
- else if (stagename == SELFTEST_STAGE_TUBE_HEIGHT_MOVE_BACK)
- {
- OnStageTubeHeightMoveBack();
- }
- else if (stagename == SELFTEST_STAGE_TUBE_ANGLE_ROTATETO_TARGET)
- {
- OnStageTubeAngleRotateToTarget();
- }
- else if (stagename == SELFTEST_STAGE_TUBE_ANGLE_ROTATE_BACK)
- {
- OnStageTubeAngleRotateBack();
- }
- else if (stagename == SELFTEST_STAGE_START_AUTO_SELFTEST)
- {
- OnStageAutoSelfTest();
- }
- }
- void SelfTestModel::OnStageAutoSelfTest()
- {
- auto current = m_coordinates->GetCurrentPhysical((DOF_MECH)m_stageArgs->DOF);
- auto target = m_stageArgs->HighLimit;
- MoveMech(m_stageArgs->DOF, current, target, m_stageArgs->Period, m_stageArgs->DutyCycle);
- }
- void SelfTestModel::OnStageTubeHeightMoveToTarget()
- {
- auto current = m_coordinates->GetCurrentPhysical((DOF_MECH)m_stageArgs->DOF);
- auto target = m_stageArgs->LowLimit;
- MoveMech(1, current, target, m_stageArgs->Period, m_stageArgs->DutyCycle);
- }
- void SelfTestModel::OnStageTubeHeightMoveBack()
- {
- auto current = m_coordinates->GetCurrentPhysical((DOF_MECH)m_stageArgs->DOF);
- auto target = m_stageArgs->HighLimit;
- MoveMech(1, current, target, m_stageArgs->Period, m_stageArgs->DutyCycle);
- }
- void SelfTestModel::OnStageTubeAngleRotateToTarget()
- {
- auto current = m_coordinates->GetCurrentPhysical((DOF_MECH)m_stageArgs->DOF);
- auto target = m_stageArgs->LowLimit;
- MoveMech(0, current, target, m_stageArgs->Period, m_stageArgs->DutyCycle);
- }
- void SelfTestModel::OnStageTubeAngleRotateBack()
- {
- auto current = m_coordinates->GetCurrentPhysical((DOF_MECH)m_stageArgs->DOF);
- auto target = m_stageArgs->HighLimit;
- MoveMech(0, current, target, m_stageArgs->Period, m_stageArgs->DutyCycle);
- }
- void SelfTestModel::MoveMech(int dof, float current, float target, int period, float dutyCycle)
- {
- if (dof == 0)
- {
- RotateTubeAngle(current, target, period,dutyCycle);
- }
- else if (dof == 1)
- {
- MoveTubeHeight(current, target, period, dutyCycle);
- }
- }
- void SelfTestModel::RotateTubeAngle(float current, float target, int period, float dutyCycle)
- {
- float offset = abs(current - target);
- auto step = m_coordinates->ConvertMotorStepValue(m_tubeAngle->Name(), offset);
- auto direction = JudgeDirectionInTubeAngleAxis(current, target);
- m_tubeAngle->Rotate(
- direction,
- step,
- period,
- dutyCycle);
- }
- void SelfTestModel::MoveTubeHeight(float current, float target, int period, float dutyCycle)
- {
- float offset = abs(current - target);
- auto step = m_coordinates->ConvertMotorStepValue(m_tubeHeight->Name(), offset);
- auto direction = JudgeDirectionInTubeHeightAxis(current, target);
- m_tubeHeight->Move(
- direction,
- step,
- period,
- dutyCycle
- );
- }
- int SelfTestModel::JudgeDirectionInTubeHeightAxis(float current, float target)
- {
- auto positive = ConfigurerMotion::GetTubeHeightAxisPositiveDirection();
- auto direction = positive > 0 ? 1 : -1;
- if (current > target)
- {
- return 1 * direction;
- }
- if (current < target)
- {
- return -1 * direction;
- }
- return 0;
- }
- int SelfTestModel::JudgeDirectionInTubeAngleAxis(float current, float target)
- {
- auto positive = ConfigurerMotion::GetTubeRotateAxisPositiveDirection();
- auto direction = positive > 0 ? 1 : -1;
- if (current > target)
- {
- return -1 * direction;
- }
- if (current < target)
- {
- return 1 * direction;
- }
- return 0;
- }
- void SelfTestModel::SwitchScanningComponents(int nSwitch)
- {
- }
- void SelfTestModel::SwitchWorkstation(string ws)
- {
- m_CurWS = ws;
- }
|