int RAMPSXYStage::SetPositionSteps(long x, long y) { LogMessage("XYStage: SetPositionSteps"); RAMPSHub* pHub = static_cast<RAMPSHub*>(GetParentHub()); std::string status = pHub->GetState(); if (status == "Running") { return ERR_STAGE_MOVING; } double newPosX = x * stepSize_um_; double newPosY = y * stepSize_um_; double difX = newPosX - posX_um_; double difY = newPosY - posY_um_; double distance = sqrt( (difX * difX) + (difY * difY) ); posX_um_ = x * stepSize_um_; posY_um_ = y * stepSize_um_; // TODO(dek): if no position change, don't send new position. char buff[100]; sprintf(buff, "G0 X%f Y%f", posX_um_/1000., posY_um_/1000.); std::string buffAsStdStr = buff; int ret = pHub->SendCommand(buffAsStdStr); if (ret != DEVICE_OK) return ret; pHub->SetTargetXY(posX_um_, posY_um_); ret = OnXYStagePositionChanged(posX_um_, posY_um_); if (ret != DEVICE_OK) return ret; return DEVICE_OK; }
void XYStage::EventHandler(int eventId, int /*data*/) { if(eventId == XY_MOVED) { Hub* hub = static_cast<Hub*>(GetParentHub()); if(hub) { hub->SetOff(); } _busy = false; // Notify double x(0), y(0); xy_CurrentPosition(&x, &y); OnXYStagePositionChanged(x, y); } }