Page MenuHomec4science

SmaractHub.h
No OneTemporary

File Metadata

Created
Mon, Feb 10, 14:53

SmaractHub.h

This document is not UTF8. It was detected as Shift JIS and converted to UTF8 for display.
#pragma once
#include "MMDevice.h"
#include "DeviceBase.h"
#include "../../3rdparty/MCSControl.h"
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
/*
* Global custom error codes and messages
*/
#define ERR_HUB_NOT_CONNECTED 10001
#define ERR_HUB_NONE_DETECTED 10002
#define ERR_ASIGP_BAD_MULT 10003
#define ERR_UNEXPECTED_PACKET 10004
#define ERR_DEVICE_NOT_FOUND 10005
#define ERR_NO_FILE_FOUND 10006
#define ERR_NOT_REFERENCED 10007
#define ERR_OUT_OF_BOUNDS 10008
const char* const g_Msg_ERR_HUB_NOT_CONNECTED =
"Hub Device not found. The Smaract Hub device is needed to create this device";
const char* const g_Msg_ERR_HUB_NONE_DETECTED =
"No Hub device could be detected";
const char* const g_Msg_ERR_ASIGP_BAD_MULT =
"ASI Gamepad bad multiplier (> 1 or < -1)";
const char* const g_Msg_ERR_UNEXPECTED_PACKET =
"Unexpected packet received";
class SmaractTrStage;
class SmaractRotStage;
class ToolActuator;
class SmaractHub : public HubBase<SmaractHub>
{
public:
SmaractHub();
~SmaractHub();
int Initialize();
int Shutdown();
void GetName(char* pszName) const;
bool Busy();
MM::DeviceDetectionStatus DetectDevice(void);
int DetectInstalledDevices();
bool IsConnected();
unsigned int getChannel(const char* devName);
bool isCommModeAsync();
bool isCalibrate();
bool isReference();
bool isZStageLocked();
bool OpenNewFile();
void WriteToRecordingFile(std::string inputString);
void CloseRecordingFile();
int ChangeScale();
int MoveTRStages();
int Snapshot();
int RecordStage(double pos, long speedLayer, std::string name);
int RecordTool(long pos, std::string name);
int PlayRecording(MM::PropertyBase* pProp, MM::ActionType eAct);
int OpenExistingFile(char* fileName);
int DecodeAndAct(std::string const& line);
void SetTRStage(const char* name, SmaractTrStage* pStage);
void SetRotStage(const char* name, SmaractRotStage* pStage);
void SetToolActuator(ToolActuator* pStage);
int Reference(MM::PropertyBase* pProp, MM::ActionType eAct);
int speedLayersValue[4];
int ReplayOffset[3];
SA_INDEX getMCSHandle();
static MMThreadLock& GetLock() {return lock_;}
private:
int OnCommMode(MM::PropertyBase* pProp, MM::ActionType eAct);
bool async_;
int OnCalibrate(MM::PropertyBase* pProp, MM::ActionType eAct);
bool calibrate_;
int OnReference(MM::PropertyBase* pProp, MM::ActionType eAct);
bool reference_;
int OnXOLMove(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnYOLMove(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnZOLMove(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnToolMove(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnSpeedLayerChange(MM::PropertyBase* pProp, MM::ActionType eAct);
int SmaractHub::OnSpeedLayerValueChange(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnRecordingToggle(MM::PropertyBase* pProp, MM::ActionType eAct);
int SmaractHub::OnRotationToggle(MM::PropertyBase* pProp, MM::ActionType eAct);
int SmaractHub::OnTremorFactorChange(MM::PropertyBase* pProp, MM::ActionType eAct);
SmaractTrStage* xTRStage;
SmaractTrStage* yTRStage;
SmaractTrStage* zTRStage;
SmaractRotStage* xROTStage;
SmaractRotStage* yROTStage;
SmaractRotStage* zROTStage;
ToolActuator* toolActuator;
double prevXVect;
double prevYVect;
double prevZVect;
double timeoutOffset;
double tremorFactor;
int lastPositions [5];
bool newFile;
double speedFactor;
bool initialized_;
bool isConnected_;
bool hasRecordedOnce_;
unsigned int noChannels_;
SA_INDEX mcsHandle_;
std::string port_;
std::string name_;
std::vector<std::string> devConn_;
std::vector<std::string> peripherals_;
static MMThreadLock lock_;
std::ofstream recordingFile;
std::ifstream readingFile;
};
class SmaractTrStage : public CStageBase<SmaractTrStage>
{
public:
SmaractTrStage(const char* devName);
~SmaractTrStage();
int Initialize();
int Shutdown();
void GetName(char* pszName) const;
bool Busy();
int IsStageSequenceable(bool& isSequenceable) const {isSequenceable = false; return DEVICE_OK;}
bool IsContinuousFocusDrive() const {return false;}
int GetPositionUm(double& pos);
int GetPositionSteps(long &steps) { return DEVICE_UNSUPPORTED_COMMAND; }
int GetLimits(double& /*min*/, double& /*max*/);
int SetPositionUm(double pos);
int SetRelativePositionUm(double pos);
int SetPositionSteps(long steps) { return DEVICE_UNSUPPORTED_COMMAND; }
int SetOrigin();
int SetFrequency(int x);
int SetErrorReporting(boolean reporting);
int OnLimit(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnFrequency(MM::PropertyBase* pProp, MM::ActionType eAct);
int Move(double velocity);
int OnOLMove(MM::PropertyBase* pProp, MM::ActionType eAct);
std::string ExportName();
//TO REMOVE - Testing
void testMoveCallback();
private:
unsigned int channel_;
bool async_;
bool hasSensor_;
bool initialized_;
std::string name_;
int olMoveScale_;
int OnOLStep(MM::PropertyBase* pProp, MM::ActionType eAct);
signed int minPos_; // [nm]
signed int maxPos_; // [nm]
unsigned int olAmplitude_;
unsigned int olFrequency_;
int olMaxSteps_;
};
class SmaractRotStage : public CStageBase<SmaractRotStage>
{
public:
SmaractRotStage(const char* devName);
~SmaractRotStage();
int Initialize();
int Shutdown();
void GetName(char* pszName) const;
bool Busy();
int IsStageSequenceable(bool& isSequenceable) const {isSequenceable = false; return DEVICE_OK;}
bool IsContinuousFocusDrive() const {return false;}
int GetPositionUm(double& angT /*[uー]*/);
int GetPositionSteps(long &steps) { return DEVICE_UNSUPPORTED_COMMAND; }
int GetLimits(double& minAngT /*[uー]*/, double& maxAngT /*[uー]*/);
int SetPositionUm(double angT /*[uー]*/);
int SetRelativePositionUm(double dAngT /*[uー]*/);
int SetPositionSteps(long steps) { return DEVICE_UNSUPPORTED_COMMAND; }
int SetOrigin();
int SetFrequency(int x);
int SetErrorReporting(boolean reporting);
int OnLimit(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnFrequency(MM::PropertyBase* pProp, MM::ActionType eAct);
int Move(double velocity);
int OnOLMove(MM::PropertyBase* pProp, MM::ActionType eAct);
std::string ExportName();
private:
unsigned int channel_;
bool hasSensor_;
bool initialized_;
bool async_;
std::string name_;
long posSteps_; // Step recorder for rotary stage without sensor
int olMoveScale_;
signed int minAng_; // [uー]
signed int maxAng_; // [uー]
unsigned int olAmplitude_;
unsigned int olFrequency_;
int olMaxSteps_;
};
// Arduino Tool Actuator
#define ERR_TACT_NOT_CONNECTED 20001
#define ERR_TACT_ERR_COMMAND 20002
#define ERR_TACT_ERR_OUT_OF_RANGE 20003
const char* const g_Msg_ERR_TACT_NOT_CONNECTED =
"Tool Actuator Arduino not found";
const char* const g_Msg_ERR_TACT_ERR_COMMAND =
"Tool Actuator Arduino command error";
#define UM_PER_STEP 20
#define STEPS_PER_UM 0.05
#define STEPSIZE 100
#define BUF_LEN (64)
#define NAME ("ATA")
#define CMD_NME ("NME") // Get controller name
#define CMD_MOV ("MOV") // Move to
#define CMD_MOQ ("MOQ") // Ask movement status
#define CMD_HOM ("HOM") // Homing
#define CMD_POS ("POS") // Set position
#define CMD_POQ ("POQ") // Get position
#define CMD_DLY ("DLY") // Set step delay
#define CMD_DLQ ("DLQ") // Get step delay
#define STA_ERR ("ERR") // Return error if command is not understood
#define STA_COK ("COK") // Return "command OK" if command is understood
#define STA_OOR ("OOR") // Return "position out of reach"
#define STA_MOV ("MOV") // Return "MOV" when movement finished
#define STA_IDL ("IDL") // Return "IDL" when movement finished
class ToolActuator : public CStageBase<ToolActuator>
{
public:
ToolActuator();
~ToolActuator() {};
int Initialize();
int Shutdown();
void GetName(char* pszName) const;
bool Busy();
std::string ExportName();
int IsStageSequenceable(bool& isSequenceable) const { isSequenceable = false; return DEVICE_OK;}
bool IsContinuousFocusDrive() const { return false; }
int GetPositionUm(double &pos);
int GetPositionSteps(long &steps);
int GetLimits(double& , double& ) { return DEVICE_UNSUPPORTED_COMMAND; }
int SetPositionUm(double pos);
int SetRelativePositionUm(double pos);
int SetPositionSteps(long steps);
int SetOrigin() { return DEVICE_UNSUPPORTED_COMMAND; }
int OnMove(MM::PropertyBase* pProp, MM::ActionType eAct);
int OnPort(MM::PropertyBase* pPropt, MM::ActionType eAct);
int OnStep(MM::PropertyBase* pProp, MM::ActionType eAct);
private:
std::string name_;
std::string port_;
bool initialized_;
bool portAvailable_;
bool isMoving_;
long steps_;
int maxExtrude_; // [steps]
};

Event Timeline