167 lines
4.9 KiB
C++
167 lines
4.9 KiB
C++
#pragma once
|
|
|
|
// #include <mcc_defaults.h>
|
|
// #include <mcc_generics.h>
|
|
|
|
#include <mcc/mcc_angle.h>
|
|
#include <mcc/mcc_coordinate.h>
|
|
|
|
#include <LibSidServo/sidservo.h>
|
|
|
|
// #include "LibSidServo/sidservo.h"
|
|
#include "asibfm700_common.h"
|
|
|
|
|
|
namespace asibfm700
|
|
{
|
|
|
|
/* error codes enum definition */
|
|
|
|
enum class AsibFM700ServoControllerErrorCode : int {
|
|
// error codes from sidservo library
|
|
ERROR_OK = MCC_E_OK,
|
|
ERROR_FATAL = MCC_E_FATAL,
|
|
ERROR_BADFORMAT = MCC_E_BADFORMAT,
|
|
ERROR_ENCODERDEV = MCC_E_ENCODERDEV,
|
|
ERROR_MOUNTDEV = MCC_E_MOUNTDEV,
|
|
ERROR_FAILED = MCC_E_FAILED,
|
|
// my codes ...
|
|
ERROR_POLLING_TIMEOUT,
|
|
ERROR_NULLPTR
|
|
};
|
|
|
|
// error category
|
|
struct AsibFM700ServoControllerErrorCategory : public std::error_category {
|
|
const char* name() const noexcept;
|
|
std::string message(int ec) const;
|
|
|
|
static const AsibFM700ServoControllerErrorCategory& get();
|
|
};
|
|
|
|
|
|
static inline std::error_code make_error_code(AsibFM700ServoControllerErrorCode ec)
|
|
{
|
|
return std::error_code(static_cast<int>(ec), AsibFM700ServoControllerErrorCategory::get());
|
|
}
|
|
|
|
} // namespace asibfm700
|
|
|
|
|
|
namespace std
|
|
{
|
|
|
|
template <>
|
|
class is_error_code_enum<asibfm700::AsibFM700ServoControllerErrorCode> : public true_type
|
|
{
|
|
};
|
|
|
|
} // namespace std
|
|
|
|
|
|
namespace asibfm700
|
|
{
|
|
|
|
class AsibFM700ServoController
|
|
{
|
|
public:
|
|
static constexpr mcc::MccMountType hwMountType{mcc::MccMountType::FORK_TYPE};
|
|
|
|
static constexpr std::string_view hardwareName = "Sidereal-ServoControllerII";
|
|
|
|
typedef std::error_code error_t;
|
|
|
|
enum class hardware_movement_state_t : int {
|
|
HW_MOVE_ERROR = -1,
|
|
HW_MOVE_STOPPED = 0,
|
|
HW_MOVE_STOPPING,
|
|
HW_MOVE_SLEWING,
|
|
HW_MOVE_ADJUSTING,
|
|
HW_MOVE_TRACKING,
|
|
HW_MOVE_GUIDING,
|
|
HW_MOVE_UNKNOWN
|
|
};
|
|
|
|
// typedef AsibFM700ServoControllerMovementState hardware_movement_state_t;
|
|
|
|
struct hardware_state_t {
|
|
mcc::impl::MccGenXY XY{0.0, 0.0}, speedXY{0.0, 0.0};
|
|
hardware_movement_state_t movementState{hardware_movement_state_t::HW_MOVE_STOPPED};
|
|
};
|
|
|
|
|
|
struct hardware_config_t {
|
|
// the 'char*' fields from conf_t:
|
|
// wrap it to std::string
|
|
std::string MountDevPath;
|
|
std::string EncoderDevPath;
|
|
std::string EncoderXDevPath;
|
|
std::string EncoderYDevPath;
|
|
|
|
conf_t devConfig; // devices paths and PIDs parameters
|
|
hardware_configuration_t hwConfig; // EEPROM-located configuration
|
|
|
|
std::chrono::milliseconds pollingInterval{300}; // hardware polling interval
|
|
std::chrono::milliseconds pollingTimeout{30000}; // hardware polling timeout
|
|
};
|
|
|
|
/* constructors and destructor */
|
|
|
|
AsibFM700ServoController();
|
|
|
|
AsibFM700ServoController(hardware_config_t config);
|
|
|
|
AsibFM700ServoController(const AsibFM700ServoController&) = delete;
|
|
AsibFM700ServoController& operator=(const AsibFM700ServoController&) = delete;
|
|
|
|
AsibFM700ServoController(AsibFM700ServoController&&) = default;
|
|
AsibFM700ServoController& operator=(AsibFM700ServoController&&) = default;
|
|
|
|
virtual ~AsibFM700ServoController();
|
|
|
|
/* public methods */
|
|
|
|
error_t hardwareSetState(hardware_state_t const& state);
|
|
error_t hardwareGetState(hardware_state_t* state);
|
|
|
|
error_t hardwareInit();
|
|
|
|
error_t hardwareShutdown();
|
|
|
|
void hardwareUpdateConfig(conf_t cfg);
|
|
|
|
// save config to EEPROM
|
|
error_t hardwareUpdateConfig(hardware_configuration_t cfg);
|
|
// load config from EEPROM
|
|
error_t hardwareUpdateConfig();
|
|
|
|
hardware_config_t getHardwareConfig() const;
|
|
|
|
protected:
|
|
hardware_config_t _hardwareConfig;
|
|
|
|
std::unique_ptr<std::mutex> _setStateMutex;
|
|
};
|
|
|
|
} // namespace asibfm700
|
|
|
|
template <>
|
|
struct std::formatter<asibfm700::AsibFM700ServoController::hardware_movement_state_t, char>
|
|
: std::formatter<std::string_view> {
|
|
auto format(asibfm700::AsibFM700ServoController::hardware_movement_state_t e, auto& ctx) const
|
|
{
|
|
return formatter<std::string_view>::format(
|
|
e == asibfm700::AsibFM700ServoController::hardware_movement_state_t::HW_MOVE_ERROR ? "ERROR"
|
|
: e == asibfm700::AsibFM700ServoController::hardware_movement_state_t::HW_MOVE_STOPPED ? "STOPPED"
|
|
: e == asibfm700::AsibFM700ServoController::hardware_movement_state_t::HW_MOVE_STOPPING ? "STOPPING"
|
|
: e == asibfm700::AsibFM700ServoController::hardware_movement_state_t::HW_MOVE_SLEWING ? "SLEWING"
|
|
: e == asibfm700::AsibFM700ServoController::hardware_movement_state_t::HW_MOVE_ADJUSTING ? "ADJUSTING"
|
|
: e == asibfm700::AsibFM700ServoController::hardware_movement_state_t::HW_MOVE_TRACKING ? "TRACKING"
|
|
: e == asibfm700::AsibFM700ServoController::hardware_movement_state_t::HW_MOVE_GUIDING ? "GUIDING"
|
|
: "UNKNOWN",
|
|
ctx);
|
|
}
|
|
};
|
|
|
|
|
|
static_assert(mcc::mcc_hardware_c<asibfm700::AsibFM700ServoController>, "!!!");
|