You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.5 KiB
67 lines
2.5 KiB
#pragma once
|
|
#include <map>
|
|
|
|
#include "api/api.hpp"
|
|
#include "api\i_zcan_cmder_master.hpp"
|
|
#include "cmdid.hpp"
|
|
|
|
namespace iflytop {
|
|
class ZModuleDeviceManager {
|
|
private:
|
|
map<uint16_t, ZIModule *> m_modulers;
|
|
IZcanCmderMaster *m_cancmder = nullptr;
|
|
|
|
public:
|
|
void initialize();
|
|
void registerModule(uint16_t id, ZIModule *module);
|
|
/*******************************************************************************
|
|
* ZIModule *
|
|
*******************************************************************************/
|
|
int32_t stop(uint16_t id);
|
|
int32_t brake(uint16_t id);
|
|
|
|
int32_t get_last_exec_status(uint16_t id, int32_t *status);
|
|
int32_t get_status(uint16_t id, int32_t *status);
|
|
|
|
int32_t set_param(uint16_t id, int32_t param_id, int32_t param_value);
|
|
int32_t get_param(uint16_t id, int32_t param_id, int32_t *param_value);
|
|
|
|
int32_t readio(uint16_t id, int32_t *io);
|
|
int32_t writeio(uint16_t id, int32_t io);
|
|
|
|
int32_t read_adc(uint16_t id, int adcindex, int32_t *adc);
|
|
|
|
/*******************************************************************************
|
|
* ZIMotor *
|
|
*******************************************************************************/
|
|
|
|
int32_t motor_enable(uint16_t id, int32_t enable);
|
|
int32_t motor_rotate(uint16_t id, int32_t direction, int32_t velocitylevel);
|
|
int32_t motor_move_by(uint16_t id, int32_t distance, int32_t velocitylevel);
|
|
int32_t motor_move_to(uint16_t id, int32_t position, int32_t velocitylevel);
|
|
int32_t motor_move_to_with_torque(uint16_t id, int32_t pos, int32_t torque);
|
|
|
|
/*******************************************************************************
|
|
* ZIXYMotor *
|
|
*******************************************************************************/
|
|
int32_t xymotor_enable(uint16_t id, int32_t enable);
|
|
int32_t xymotor_move_by(uint16_t id, int32_t dx, int32_t dy, int32_t velocitylevel);
|
|
int32_t xymotor_move_to(uint16_t id, int32_t x, int32_t y, int32_t velocitylevel);
|
|
|
|
private:
|
|
template <typename T>
|
|
int32_t findModule(uint16_t id, T **module) {
|
|
auto it = m_modulers.find(id);
|
|
if (it == m_modulers.end()) {
|
|
return err::kce_no_such_module;
|
|
}
|
|
T *_module = dynamic_cast<T *>(it->second);
|
|
if (_module == nullptr) {
|
|
return err::kce_operation_not_support;
|
|
}
|
|
*module = _module;
|
|
return 0;
|
|
}
|
|
};
|
|
|
|
} // namespace iflytop
|