Files
mastermacs/src/masterMacsAxis.h

282 lines
7.1 KiB
C++

#ifndef masterMacsAXIS_H
#define masterMacsAXIS_H
#include "sinqAxis.h"
#include <bitset>
// Forward declaration of the controller class to resolve the cyclic dependency
// between C804Controller.h and C804Axis.h. See
// https://en.cppreference.com/w/cpp/language/class.
class masterMacsController;
class masterMacsAxis : public sinqAxis {
public:
/**
* @brief Construct a new masterMacsAxis
*
* @param pController Pointer to the associated controller
* @param axisNo Index of the axis
*/
masterMacsAxis(masterMacsController *pController, int axisNo);
/**
* @brief Destroy the masterMacsAxis
*
*/
virtual ~masterMacsAxis();
/**
* @brief Implementation of the `stop` function from asynMotorAxis
*
* @param acceleration Acceleration ACCEL from the motor record. This
* value is currently not used.
* @return asynStatus
*/
asynStatus stop(double acceleration);
/**
* @brief Implementation of the `doHome` function from sinqAxis. The
* parameters are described in the documentation of `sinqAxis::doHome`.
*
* @param minVelocity
* @param maxVelocity
* @param acceleration
* @param forwards
* @return asynStatus
*/
asynStatus doHome(double minVelocity, double maxVelocity,
double acceleration, int forwards);
/**
* @brief Implementation of the `doPoll` function from sinqAxis. The
* parameters are described in the documentation of `sinqAxis::doPoll`.
*
* @param moving
* @return asynStatus
*/
asynStatus doPoll(bool *moving);
/**
* @brief Implementation of the `doMove` function from sinqAxis. The
* parameters are described in the documentation of `sinqAxis::doMove`.
*
* @param position
* @param relative
* @param min_velocity
* @param max_velocity
* @param acceleration
* @return asynStatus
*/
asynStatus doMove(double position, int relative, double min_velocity,
double max_velocity, double acceleration);
/**
* @brief Readout of some values from the controller at IOC startup
*
* The following steps are performed:
* - Read out the motor status, motor position, velocity and acceleration
* from the MCU and store this information in the parameter library.
* - Set the enable PV accordint to the initial status of the axis.
*
* @return asynStatus
*/
asynStatus init();
/**
* @brief Enable / disable the axis.
*
* @param on
* @return asynStatus
*/
asynStatus enable(bool on);
/**
* @brief Read the encoder type (incremental or absolute) for this axis from
* the MCU and store the information in the PV ENCODER_TYPE.
*
* @return asynStatus
*/
asynStatus readEncoderType();
protected:
masterMacsController *pC_;
double lastSetSpeed_;
bool waitForHandshake_;
time_t timeAtHandshake_;
asynStatus readConfig();
/*
The axis status and axis error of MasterMACS are given as an integer from
the controller. The 16 individual bits contain the actual information.
*/
std::bitset<16> axisStatus_;
std::bitset<16> axisError_;
/**
* @brief Read the Master MACS status with the xR10 command and store the
* result in axisStatus_
*
*/
asynStatus readAxisStatus();
/*
The functions below read the specified status bit from the axisStatus_
bitset. Since a bit can either be 0 or 1, the return value is given as a
boolean.
*/
/**
* @brief Read the property from axisStatus_
*/
bool readyToBeSwitchedOn() { return axisStatus_[0]; }
/**
* @brief Read the property from axisStatus_
*/
bool switchedOn() { return axisStatus_[1]; }
// Bit 2 is unused
/**
* @brief Read the property from axisStatus_
*/
bool faultConditionSet() { return axisStatus_[3]; }
/**
* @brief Read the property from axisStatus_
*/
bool voltagePresent() { return axisStatus_[4]; }
/**
* @brief Read the property from axisStatus_
*/
bool quickStopping() { return axisStatus_[5] == 0; }
/**
* @brief Read the property from axisStatus_
*/
bool switchOnDisabled() { return axisStatus_[6]; }
/**
* @brief Read the property from axisStatus_
*/
bool warning() { return axisStatus_[7]; }
// Bit 8 is unused
/**
* @brief Read the property from axisStatus_
*/
bool remoteMode() { return axisStatus_[9]; }
/**
* @brief Read the property from axisStatus_
*/
bool targetReached() { return axisStatus_[10]; }
/**
* @brief Read the property from axisStatus_
*/
bool internalLimitActive() { return axisStatus_[11]; }
// Bits 12 and 13 are unused
/**
* @brief Read the property from axisStatus_
*/
bool setEventHasOcurred() { return axisStatus_[14]; }
/**
* @brief Read the property from axisStatus_
*/
bool powerEnabled() { return axisStatus_[15]; }
/**
* @brief Read the Master MACS status with the xR10 command and store the
* result in axisStatus_
*
*/
asynStatus readAxisError();
/*
The functions below read the specified error bit from the axisError_
bitset. Since a bit can either be 0 or 1, the return value is given as a
boolean.
*/
/**
* @brief Read the property from axisError_
*/
bool shortCircuit() { return axisError_[1]; }
/**
* @brief Read the property from axisError_
*/
bool encoderError() { return axisError_[2]; }
/**
* @brief Read the property from axisError_
*/
bool followingError() { return axisError_[3]; }
/**
* @brief Read the property from axisError_
*/
bool communicationError() { return axisError_[4]; }
/**
* @brief Read the property from axisError_
*/
bool feedbackError() { return axisError_[5]; }
/**
* @brief Read the property from axisError_
*/
bool positiveLimitSwitch() { return axisError_[6]; }
/**
* @brief Read the property from axisError_
*/
bool negativeLimitSwitch() { return axisError_[7]; }
/**
* @brief Read the property from axisError_
*/
bool positiveSoftwareLimit() { return axisError_[8]; }
/**
* @brief Read the property from axisError_
*/
bool negativeSoftwareLimit() { return axisError_[9]; }
/**
* @brief Read the property from axisError_
*/
bool overCurrent() { return axisError_[10]; }
/**
* @brief Read the property from axisError_
*/
bool overTemperature() { return axisError_[11]; }
/**
* @brief Read the property from axisError_
*/
bool overVoltage() { return axisError_[12]; }
/**
* @brief Read the property from axisError_
*/
bool underVoltage() { return axisError_[13]; }
/**
* @brief Read the property from axisError_
*/
bool stoFault() { return axisError_[15]; }
private:
friend class masterMacsController;
};
#endif