Skip to content

Commit

Permalink
Octopi: Moved autohome property to Hub so that Z stage is always home…
Browse files Browse the repository at this point in the history
…d befopre XY Stage.
  • Loading branch information
nicost committed Oct 21, 2024
1 parent 2a6d573 commit 1b2b3a4
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 64 deletions.
7 changes: 3 additions & 4 deletions DeviceAdapters/Octopi-Research/Squid.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,13 @@ class SquidHub : public HubBase<SquidHub>
int DetectInstalledDevices();

int OnPort(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnAutoHome(MM::PropertyBase* pProp, MM::ActionType eAct);

bool IsPortAvailable() { return (port_ != ""); };
int SendCommand(unsigned char* cmd, unsigned cmdSize);
int SendMoveCommand(const int cmd, long steps);
int SetMaxVelocityAndAcceleration(unsigned char axis, double maxVelocity, double acceleration);
int Home();
void GetPositionXYSteps(long& x, long& y);
void GetPositionZSteps(long& z);
void SetPositionXSteps(long x);
Expand All @@ -122,6 +124,7 @@ class SquidHub : public HubBase<SquidHub>

private:
bool initialized_;
bool autoHome_;
SquidMonitoringThread* monitoringThread_;
SquidXYStage* xyStageDevice_;
SquidZStage* zStageDevice_;
Expand Down Expand Up @@ -238,7 +241,6 @@ class SquidXYStage : public CXYStageBase<SquidXYStage>
// ----------------
int OnAcceleration(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnMaxVelocity(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnAutoHome(MM::PropertyBase* pProp, MM::ActionType eAct);

int Callback(long xSteps, long ySteps);

Expand All @@ -257,7 +259,6 @@ class SquidXYStage : public CXYStageBase<SquidXYStage>
bool busy_;
double maxVelocity_;
double acceleration_;
bool autoHome_;
bool initialized_;
uint8_t cmdNr_;

Expand Down Expand Up @@ -305,7 +306,6 @@ class SquidZStage : public CStageBase<SquidZStage>

int OnAcceleration(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnMaxVelocity(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnAutoHome(MM::PropertyBase* pProp, MM::ActionType eAct);

int Callback(long zSteps);

Expand All @@ -317,7 +317,6 @@ class SquidZStage : public CStageBase<SquidZStage>
double fullStepsPerRevZ_;
double maxVelocity_;
double acceleration_;
bool autoHome_;
bool initialized_;
uint8_t cmdNr_;
};
Expand Down
53 changes: 53 additions & 0 deletions DeviceAdapters/Octopi-Research/SquidHub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ MODULE_API void DeleteDevice(MM::Device* pDevice)

SquidHub::SquidHub() :
initialized_(false),
autoHome_(false),
monitoringThread_(0),
xyStageDevice_(0),
zStageDevice_(0),
Expand All @@ -77,6 +78,11 @@ SquidHub::SquidHub() :
yStageBusy_ = false;
zStageBusy_ = false;
busy_ = false;

pAct = new CPropertyAction(this, &SquidHub::OnAutoHome);
CreateProperty(g_AutoHome, g_No, MM::String, false, pAct, true);
AddAllowedValue(g_AutoHome, g_Yes);
AddAllowedValue(g_AutoHome, g_No);
}


Expand Down Expand Up @@ -117,6 +123,14 @@ int SquidHub::Initialize() {
return ret;
}

if (autoHome_)
{
ret = Home();
if (ret != DEVICE_OK) {
return ret;
}
}

initialized_ = true;

return DEVICE_OK;
Expand Down Expand Up @@ -369,3 +383,42 @@ bool SquidHub::ZStageBusy()
{
return busy_ || (status_ != COMPLETED_WITHOUT_ERRORS) || zStageBusy_;
}


int SquidHub::OnAutoHome(MM::PropertyBase* pProp, MM::ActionType eAct)
{
std::string response;
if (eAct == MM::BeforeGet)
{
response = autoHome_ ? g_Yes : g_No;
pProp->Set(response.c_str());
}
else if (eAct == MM::AfterSet)
{
pProp->Get(response);
autoHome_ = response == g_Yes;
}
return DEVICE_OK;
}


int SquidHub::Home()
{
const unsigned cmdSize = 8;
unsigned char cmd[cmdSize];
for (unsigned i = 0; i < cmdSize; i++) {
cmd[i] = 0;
}
cmd[1] = CMD_HOME_OR_ZERO;
cmd[2] = AXIS_Z;
cmd[3] = int((STAGE_MOVEMENT_SIGN_Z + 1) / 2); // "move backward" if SIGN is 1, "move forward" if SIGN is - 1
int ret = SendCommand(cmd, cmdSize);
if (ret != DEVICE_OK)
return ret;

cmd[1] = CMD_HOME_OR_ZERO;
cmd[2] = AXIS_XY;
cmd[3] = int((STAGE_MOVEMENT_SIGN_X + 1) / 2); // "move backward" if SIGN is 1, "move forward" if SIGN is - 1
cmd[4] = int((STAGE_MOVEMENT_SIGN_Y + 1) / 2); // "move backward" if SIGN is 1, "move forward" if SIGN is - 1
return SendCommand(cmd, cmdSize);
}
32 changes: 1 addition & 31 deletions DeviceAdapters/Octopi-Research/SquidXYStage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,10 @@ SquidXYStage::SquidXYStage() :
busy_(false),
maxVelocity_(25.0),
acceleration_(500.0),
autoHome_(false),
initialized_(false),
cmdNr_(0)
{
InitializeDefaultErrorMessages();

CPropertyAction* pAct = new CPropertyAction(this, &SquidXYStage::OnAutoHome);
CreateProperty(g_AutoHome, g_No, MM::String, false, pAct, true);
AddAllowedValue(g_AutoHome, g_Yes);
AddAllowedValue(g_AutoHome, g_No);
}

SquidXYStage::~SquidXYStage()
Expand Down Expand Up @@ -145,16 +139,9 @@ int SquidXYStage::Initialize()
CreateFloatProperty(g_Max_Velocity, maxVelocity_, false, pAct);
SetPropertyLimits(g_Max_Velocity, 1.0, 655.35);

if (autoHome_)
{
ret = Home();
if (ret != DEVICE_OK)
return ret;
}

initialized_ = true;

return DEVICE_OK;
return DEVICE_OK;
}


Expand Down Expand Up @@ -217,23 +204,6 @@ int SquidXYStage::Callback(long xSteps, long ySteps)
}


int SquidXYStage::OnAutoHome(MM::PropertyBase* pProp, MM::ActionType eAct)
{
std::string response;
if (eAct == MM::BeforeGet)
{
response = autoHome_ ? g_Yes : g_No;
pProp->Set(response.c_str());
}
else if (eAct == MM::AfterSet)
{
pProp->Get(response);
autoHome_ = response == g_Yes;
}
return DEVICE_OK;
}


int SquidXYStage::OnAcceleration(MM::PropertyBase* pProp, MM::ActionType eAct)
{
if (eAct == MM::BeforeGet)
Expand Down
32 changes: 3 additions & 29 deletions DeviceAdapters/Octopi-Research/SquidZStage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,9 @@ SquidZStage::SquidZStage() :
fullStepsPerRevZ_(200),
maxVelocity_(5.0),
acceleration_(100.0),
autoHome_(false),
initialized_(false),
cmdNr_(0)
{
CPropertyAction* pAct = new CPropertyAction(this, &SquidZStage::OnAutoHome);
CreateProperty(g_AutoHome, g_No, MM::String, false, pAct, true);
AddAllowedValue(g_AutoHome, g_Yes);
AddAllowedValue(g_AutoHome, g_No);
}


Expand Down Expand Up @@ -54,6 +49,9 @@ int SquidZStage::Initialize()
}
char hubLabel[MM::MaxStrLength];
hub_->GetLabel(hubLabel);
int ret = hub_->assignZStageDevice(this);
if (ret != DEVICE_OK)
return ret;

CPropertyAction* pAct = new CPropertyAction(this, &SquidZStage::OnAcceleration);
CreateFloatProperty(g_Acceleration, acceleration_, false, pAct);
Expand All @@ -63,13 +61,6 @@ int SquidZStage::Initialize()
CreateFloatProperty(g_Max_Velocity, maxVelocity_, false, pAct);
SetPropertyLimits(g_Max_Velocity, 1.0, 655.35);

if (autoHome_)
{
int ret = Home();
if (ret != DEVICE_OK)
return ret;
}

initialized_ = true;

return DEVICE_OK;
Expand Down Expand Up @@ -155,23 +146,6 @@ int SquidZStage::Callback(long zSteps)
}


int SquidZStage::OnAutoHome(MM::PropertyBase* pProp, MM::ActionType eAct)
{
std::string response;
if (eAct == MM::BeforeGet)
{
response = autoHome_ ? g_Yes : g_No;
pProp->Set(response.c_str());
}
else if (eAct == MM::AfterSet)
{
pProp->Get(response);
autoHome_ = response == g_Yes;
}
return DEVICE_OK;
}


int SquidZStage::OnAcceleration(MM::PropertyBase* pProp, MM::ActionType eAct)
{
if (eAct == MM::BeforeGet)
Expand Down

0 comments on commit 1b2b3a4

Please sign in to comment.