24 #include "MGrblAxis.hpp"
26 #include <ccut/async.hpp>
28 #include "MGrblPlatform.hpp"
29 #include "util/grbl/GrblDeviceBase.hpp"
30 #include "util/grbl/GrblGenerator.hpp"
32 using namespace logger;
34 using namespace smc::internal;
35 using namespace smc::units;
38 MGrblAxis::MGrblAxis(
const std::string &uid,
39 const std::shared_ptr<MGrblPlatform> &mgrbl,
40 const std::shared_ptr<GrblPlatform> &grbl) :
45 void MGrblAxis::updateInstance()
const
47 std::shared_ptr<MGrblPlatform> mgrbl(m_mgrbl.lock());
49 throw Exception(ErrorCode::Canceled,
"platform stopped (deleted)");
51 mgrbl->updateInstance(
const_cast<MGrblAxis &
>(*
this));
63 return ccut::make_future_error(ex);
76 return ccut::make_future_error(ex);
89 return ccut::make_future_error(ex);
102 return ccut::make_future_error(ex);
115 return ccut::make_future_error(ex);
128 return ccut::make_future_error<units::value_t>(ex);
147 return ccut::make_future_error(ex);
152 const std::chrono::milliseconds &timeout)
const
161 return ccut::make_future_error(ex);
174 return ccut::make_future_error<Axis::State>(ex);
187 return ccut::make_future_error<std::set<std::string>>(ex);
200 return ccut::make_future_error<std::string>(ex);
205 const std::string &value)
const
209 std::shared_ptr<MGrblPlatform> mgrbl(m_mgrbl.lock());
211 throw Exception(ErrorCode::Canceled,
"platform stopped (deleted)");
213 const std::string
uid{this->
uid()};
214 std::shared_ptr<GrblPlatform> grbl{mgrbl->getFirstInstance()};
215 grbl::Axis grblAxis = grbl->getAxis(
uid);
217 return mgrbl->run<
void>([name, value, grblAxis,
uid,
221 mgrbl->runOnInstance(
223 [&name, &grblAxis, &
id](GrblPlatform::Shared &,
229 const std::string settingCmd = grbl::gen::System::setSetting(
id,
231 mgrbl->runOnInstance(
233 [&settingCmd, &
uid, &
id, &value](GrblPlatform::Shared &grbl,
235 grbl::ErrorCode rc = ctx.device->send(settingCmd);
237 grbl->updateAxisSetting(
uid,
id, value);
239 cmd.prom->get<
void>().set_value();
244 return ccut::make_future_error<void>(ex);
DeviceId uid() const
Get the address of device.
Exception thrown by MotionController in case of issues with command.
std::future< State > getState() const override
Get the current axis state.
bool canConvert(const units::Value &value, units::unit_t unit) const override
Check if unit conversion is possible in a manner specific to this device.
std::future< void > resume() const override
Resume paused motion.
std::future< void > pause() const override
Pause ongoing motion, prevent queued motions from running.
std::future< void > takeReference(const std::chrono::milliseconds &timeout=std::chrono::seconds{ 120}) const override
Start a homing sequence.
std::future< std::set< std::string > > listConfig() const override
list device configuration options
std::future< units::value_t > getPosition(units::unit_t unit) const override
Get current position of this axis.
units::value_t lastPosition(units::unit_t unit) const override
Get last known position of the axis.
std::future< void > setActualPosition(const units::Value &position) const override
Set current axis position.
std::future< void > stop() const override
Stop any ongoing motion, flush the motion-queue.
std::future< std::string > getConfig(const std::string &name) const override
get device configuration value
bool convert(units::Value &value, units::unit_t unit) const override
Convert value in a manner specific to this device.
std::future< void > moveBy(const units::Value &distance) const override
Move this axis by given distance.
std::future< void > moveTo(const units::Value &position) const override
Move this axis to given position.
bool canConvert(const units::Value &value, units::unit_t unit) const override
Check if unit conversion is possible in a manner specific to this device.
std::future< std::set< std::string > > listConfig() const override
list device configuration options
std::future< void > moveBy(const units::Value &distance) const override
Move this axis by given distance.
bool convert(units::Value &value, units::unit_t unit) const override
Convert value in a manner specific to this device.
std::future< void > moveTo(const units::Value &position) const override
Move this axis to given position.
std::future< void > takeReference(const std::chrono::milliseconds &timeout=std::chrono::seconds{ 120}) const override
Start a homing sequence.
std::future< void > stop() const override
Stop any ongoing motion, flush the motion-queue.
std::future< State > getState() const override
Get the current axis state.
units::value_t lastPosition(units::unit_t unit) const override
Get last known position of the axis.
std::future< std::string > getConfig(const std::string &name) const override
get device configuration value
std::future< void > setConfig(const std::string &name, const std::string &value) const override
set device configuration value
std::future< void > pause() const override
Pause ongoing motion, prevent queued motions from running.
std::future< void > resume() const override
Resume paused motion.
std::future< void > setActualPosition(const units::Value &position) const override
Set current axis position.
std::future< units::value_t > getPosition(units::unit_t unit) const override
Get current position of this axis.
main motion-lib namespace
void checkReply(grbl::ErrorCode code)
check command result code
const grbl::GrblParser::SettingDesc & findSetting(const std::string &name, grbl::Axis axis) const
find setting id for axis