131 lines
3.1 KiB
C++
131 lines
3.1 KiB
C++
#pragma once
|
|
|
|
/* AstroSIB-FM700 FORK MOUNT CONTROL LIBRARY */
|
|
|
|
/* HARDWARE WRAPPER IMPLEMENTATION */
|
|
|
|
#include <thread>
|
|
|
|
#include "../LibSidServo/sidservo.h"
|
|
|
|
#include "mcc_mount_concepts.h"
|
|
#include "mcc_mount_coord.h"
|
|
|
|
|
|
namespace asibfm700
|
|
{
|
|
|
|
/* error codes enum definition */
|
|
|
|
enum class AsibFM700HardwareErrorCode : 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 category
|
|
struct AsibFM700HardwareErrorCategory : public std::error_category {
|
|
const char* name() const noexcept;
|
|
std::string message(int ec) const;
|
|
|
|
static const AsibFM700HardwareErrorCategory& get();
|
|
};
|
|
|
|
|
|
static inline std::error_code make_error_code(AsibFM700HardwareErrorCode ec)
|
|
{
|
|
return std::error_code(static_cast<int>(ec), AsibFM700HardwareErrorCategory::get());
|
|
}
|
|
|
|
} // namespace asibfm700
|
|
|
|
|
|
namespace std
|
|
{
|
|
|
|
template <>
|
|
class is_error_code_enum<asibfm700::AsibFM700HardwareErrorCode> : public true_type
|
|
{
|
|
};
|
|
|
|
} // namespace std
|
|
|
|
|
|
|
|
namespace asibfm700
|
|
{
|
|
|
|
class AsibFM700Hardware final
|
|
{
|
|
public:
|
|
static constexpr uint8_t XMOTOR_STOP_BIT = 0b00000001; // if 0th bit set then motor is stopped
|
|
static constexpr uint8_t YMOTOR_STOP_BIT = 0b00010000; // if 4th bit set then motor is stopped
|
|
|
|
// definitions from concept
|
|
typedef std::error_code error_t;
|
|
typedef mcc::MccAngle coord_t;
|
|
typedef std::chrono::system_clock::time_point time_point_t; // UTC time
|
|
|
|
enum class hw_moving_type_t : int { HW_MOVE_SLEWING, HW_MOVE_ADJUSTING, HW_MOVE_TRACKING, HW_MOVE_GUIDING };
|
|
|
|
struct axes_pos_t {
|
|
time_point_t time_point;
|
|
coord_t x, y;
|
|
coord_t xrate, yrate;
|
|
|
|
hw_moving_type_t moving_type{hw_moving_type_t::HW_MOVE_TRACKING};
|
|
// slewflags_t flags;
|
|
bool moveAndStop{false};
|
|
};
|
|
|
|
|
|
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;
|
|
hardware_configuration_t hwConfig;
|
|
};
|
|
|
|
AsibFM700Hardware(const hardware_config_t& conf);
|
|
|
|
~AsibFM700Hardware();
|
|
|
|
AsibFM700Hardware(const AsibFM700Hardware&) = delete;
|
|
AsibFM700Hardware& operator=(const AsibFM700Hardware&) = delete;
|
|
|
|
AsibFM700Hardware(AsibFM700Hardware&&) = default;
|
|
AsibFM700Hardware& operator=(AsibFM700Hardware&&) = default;
|
|
|
|
|
|
std::string_view id() const;
|
|
|
|
error_t setPos(axes_pos_t);
|
|
error_t getPos(axes_pos_t&);
|
|
|
|
error_t stop();
|
|
error_t init();
|
|
|
|
private:
|
|
hardware_config_t _hardwareConfig;
|
|
|
|
std::jthread _statePollingThread;
|
|
|
|
double _sideralRate2; // square of sideral rate
|
|
double _sideralRateEps2;
|
|
};
|
|
|
|
static_assert(mcc::traits::mcc_mount_hardware_c<AsibFM700Hardware>, "AsibFM700Hardware!!!");
|
|
|
|
|
|
} // namespace asibfm700
|