24 #include "MFEPositionSensor.hpp"
26 #include <ccut/async.hpp>
27 #include <ccut/utils.hpp>
29 #include "MFEPlatform.hpp"
31 #include "platform/specialized/MGrblPlatform/MGrblPlatform.hpp"
32 #include "util/grbl/GrblTypes.hpp"
35 using namespace smc::internal;
39 MFEPositionSensor::MFEPositionSensor(
const std::string &uid,
40 const std::shared_ptr<MFEPlatform> &mfe) :
45 std::future<units::value_t> MFEPositionSensor::getPosition(
46 units::unit_t unit)
const
50 std::shared_ptr<MFEPlatform> mfe(m_mfe.lock());
52 throw Exception(ErrorCode::Canceled,
"platform stopped (deleted)");
54 const std::string
uid{this->
uid()};
64 throw Exception{ErrorCode::InvalidArguments,
65 "edge driver not available"};
67 throw Exception{ErrorCode::InvalidArguments,
68 "failed to get reg info: " + regUid};
71 ctx.edge->read(info.reg, info.shift, value);
79 units::value_t::value_type(
80 reinterpret_cast<const int32_t &
>(value))});
86 units::value_t::value_type(
87 reinterpret_cast<const float &
>(value))});
90 throw Exception(ErrorCode::IncompatibleUnits,
91 "failed to convert to " +
to_string(unit));
97 return ccut::make_future_error<units::value_t>(ex);
108 if (value.unit == units::radians)
110 ErrorCode::IncompatibleUnits,
111 "can't modify resolver readout position (in radians)");
112 else if (!
convert(stepsValue, units::steps))
113 throw Exception(ErrorCode::IncompatibleUnits,
114 "failed to convert in steps");
120 return ccut::make_future_error<void>(ex);
126 std::shared_ptr<MFEPlatform> mfe(m_mfe.lock());
128 throw Exception(ErrorCode::Canceled,
"platform stopped (deleted)");
130 return mfe->getResolverPosition(
uid(), unit);
137 std::shared_ptr<MFEPlatform> mfe(m_mfe.lock());
139 throw Exception(ErrorCode::Canceled,
"platform stopped (deleted)");
141 grbl::Axis grblAxis = mfe->getResolverAxis(
uid());
143 return mfe->run<std::set<std::string>>(
145 std::set<std::string> ret;
148 [&ret, grblAxis](GrblPlatform::Shared &,
150 for (
const std::string &name : ctx.
listConfig(grblAxis))
152 if (ccut::startsWith(
153 name, MFEPlatform::s_resolverSettingPrefix))
155 const std::string setting{name.substr(
156 MFEPlatform::s_resolverSettingPrefix.size())};
157 if (!MFEPlatform::s_resolverConfigHidden.count(
165 cmd.prom->get<std::set<std::string>>().set_value(ret);
170 return ccut::make_future_error<std::set<std::string>>(ex);
175 const std::string &name)
const
179 std::shared_ptr<MFEPlatform> mfe(m_mfe.lock());
181 throw Exception(ErrorCode::Canceled,
"platform stopped (deleted)");
183 const std::string
uid{this->
uid()};
184 grbl::Axis grblAxis = mfe->getResolverAxis(
uid);
186 return mfe->run<std::string>(
192 [&ret, grblAxis, mfe,
uid,
196 MFEPlatform::s_resolverSettingPrefix + name,
201 mfe->updateResolverSetting(
uid,
id, ret);
205 cmd.prom->get<std::string>().set_value(ret);
210 return ccut::make_future_error<std::string>(ex);
215 const std::string &value)
const
219 std::shared_ptr<MFEPlatform> mfe(m_mfe.lock());
221 throw Exception(ErrorCode::Canceled,
"platform stopped (deleted)");
223 const std::string
uid{this->
uid()};
224 grbl::Axis grblAxis = mfe->getResolverAxis(
uid);
226 return mfe->run<
void>([grblAxis, mfe,
uid, name,
231 [grblAxis, mfe,
uid, name, value](GrblPlatform::Shared &,
235 MFEPlatform::s_resolverSettingPrefix + name,
240 mfe->updateResolverSetting(
uid,
id, value);
244 cmd.prom->get<
void>().set_value();
249 return ccut::make_future_error(ex);
254 units::unit_t unit)
const
260 static const std::set<units::unit_t> s_angle{
261 units::unit_t::degrees, units::unit_t::radians, units::unit_t::turns};
265 std::shared_ptr<MFEPlatform> mfe(m_mfe.lock());
267 throw Exception(ErrorCode::Canceled,
"platform stopped (deleted)");
269 if (unit == value.unit)
271 else if (value.unit == units::steps && s_angle.count(unit))
276 logger::warning(MFEPlatform::s_loggerCat)
277 <<
"resolver mode not set";
280 value = value / mode;
284 else if (s_angle.count(value.unit) && unit == units::steps)
289 logger::warning(MFEPlatform::s_loggerCat)
290 <<
"resolver mode not set";
293 value.convert(units::turns);
294 value = mode * value;
DeviceId uid() const
Get the address of device.
Exception thrown by MotionController in case of issues with command.
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 > setActualPosition(const units::value_t &value) const override
Set the current position value.
units::value_t lastPosition(units::unit_t unit) const override
Get last known 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 > setConfig(const std::string &name, const std::string &value) const override
set device configuration value
const std::string & to_string(Axis::State state)
convert State to string
main motion-lib namespace
void _sendSetSetting(grbl::SettingId settingId, const std::string &value)
set a setting on Grbl
std::set< std::string > listConfig()
list config values
const grbl::GrblParser::SettingDesc & findSetting(const std::string &name, grbl::Axis axis) const
find setting id for axis
std::string _sendGetSetting(grbl::SettingId settingId)
retrieve a setting from Grbl, eventually update internal cache
bool getRegInfo(const std::string &uid, RegInfo &info) const
Get the RegInfo object.