Skip to content

Commit

Permalink
Support linear units (fixes Zealandia-Systems#89). (Zealandia-Systems#90
Browse files Browse the repository at this point in the history
)
  • Loading branch information
smohekey authored May 21, 2023
1 parent 5278fb9 commit 795ef37
Show file tree
Hide file tree
Showing 20 changed files with 603 additions and 520 deletions.
2 changes: 1 addition & 1 deletion src/marlin/gcode/config/M2000.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class JsonApplicator : public swordfish::json::Reader<Object> {
if (_tableIndex >= 0) {

} else {
parent->setValue(_objectProperty, value);
parent->setValueFromJson(_objectProperty, value);
}
}

Expand Down
22 changes: 11 additions & 11 deletions src/marlin/gcode/control/G10_G11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ using namespace swordfish::motion;
# include "../gcode.h"
# include "../../module/motion.h"

//#define DEBUG_CNC_G10
// #define DEBUG_CNC_G10

template<typename TRecord, typename TTable>
static TRecord& getRecord(Table<TRecord, TTable>& table, uint16_t index, bool& created) {
Expand Down Expand Up @@ -146,7 +146,7 @@ void GcodeSuite::G10() {

LOOP_XYZ(i) {
if (parser.seenval(XYZ_CHAR(i))) {
const float v = parser.value_axis_units((AxisEnum) i);
const float v = parser.value_linear_units();

offset[i] = axis_is_relative((AxisEnum) i) ? toLogical(current_position[i], (AxisEnum) i) + v : v;
} else {
Expand Down Expand Up @@ -210,15 +210,15 @@ void GcodeSuite::G10() {
auto& offset = coordinateSystem->getOffset();

if (parser.seenval('X')) {
offset.x(parser.value_float());
offset.x(parser.value_linear_units());
}

if (parser.seenval('Y')) {
offset.y(parser.value_float());
offset.y(parser.value_linear_units());
}

if (parser.seenval('Z')) {
offset.z(parser.value_float());
offset.z(parser.value_linear_units());
}

Controller::getInstance().save();
Expand Down Expand Up @@ -278,11 +278,11 @@ void GcodeSuite::G10() {
auto& geometry = tool.getGeometry();

if (parser.seenval('W')) {
geometry.diameter(parser.value_float());
geometry.diameter(parser.value_linear_units());
}

if (parser.seenval('H')) {
geometry.length(parser.value_float());
geometry.length(parser.value_linear_units());
}

if (parser.seenval('D')) {
Expand Down Expand Up @@ -362,25 +362,25 @@ void GcodeSuite::G10() {
}

if (parser.seenval('D')) {
pocket.setDepth(parser.value_float());
pocket.setDepth(parser.value_linear_units());
}

auto& offset = pocket.getOffset();

if (parser.seenval('X')) {
offset.x(parser.value_float());
offset.x(parser.value_linear_units());
}

if (parser.seenval('Y')) {
auto yVal = parser.value_float();
auto yVal = parser.value_linear_units();

debug()("y: ", (float32_t) yVal);

offset.y(yVal);
}

if (parser.seenval('Z')) {
offset.z(parser.value_float());
offset.z(parser.value_linear_units());
}

Controller::getInstance().save();
Expand Down
68 changes: 34 additions & 34 deletions src/marlin/gcode/control/M211-M213.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,35 @@

#if HAS_SOFTWARE_ENDSTOPS

#include <Eigen/Core>
# include <Eigen/Core>

#include "../gcode.h"
#include "../../module/motion.h"
# include "../gcode.h"
# include "../../module/motion.h"

#include <swordfish/core/Vector3.h>
#include <swordfish/modules/motion/MotionModule.h>
# include <swordfish/core/Vector3.h>
# include <swordfish/modules/motion/MotionModule.h>

using namespace Eigen;
using namespace swordfish;
using namespace swordfish::motion;

static void setAxis(core::Vector3& vector, uint8_t axis, float32_t value) {
switch(axis) {
static void setAxis(core::LinearVector3& vector, uint8_t axis, float32_t value) {
switch (axis) {
case 0: {
vector.x(value);

break;
}

case 1: {
vector.y(value);

break;
}

case 2: {
vector.z(value);

break;
}
}
Expand All @@ -61,16 +61,16 @@ static void setAxis(core::Vector3& vector, uint8_t axis, float32_t value) {
static void logLimits() {
auto& motionModule = MotionModule::getInstance();
auto& limits = motionModule.getLimits();

Vector3f min = limits.getMin();
Vector3f max = limits.getMax();
//motionModule.toLogical(min);
//motionModule.toLogical(max);

// motionModule.toLogical(min);
// motionModule.toLogical(max);

SERIAL_ECHO_START();
SERIAL_ECHOPGM(STR_SOFT_ENDSTOPS);

serialprint_onoff(limits.areEnabled());
print_xyz(min, PSTR(STR_SOFT_MIN), PSTR(" "));
print_xyz(max, PSTR(STR_SOFT_MAX));
Expand All @@ -83,11 +83,11 @@ static void logLimits() {
void GcodeSuite::M211() {
auto& motionModule = MotionModule::getInstance();
auto& limits = motionModule.getLimits();

if (parser.seen('S')) {
limits.setEnabled(parser.value_bool());
}

logLimits();
}

Expand All @@ -96,19 +96,19 @@ void GcodeSuite::M212() {
auto& limits = motionManager.getLimits();
auto& minObj = limits.getMin();
auto writeConfig = false;
for(auto i = 0; i < 3; i++) {
if(parser.seen(XYZ_CHAR(i))) {

for (auto i = 0; i < 3; i++) {
if (parser.seen(XYZ_CHAR(i))) {
writeConfig = true;

setAxis(minObj, i, parser.linear_value_to_mm(parser.value_linear_units()));
}
}
if(writeConfig) {

if (writeConfig) {
Controller::getInstance().save();
}

logLimits();
}

Expand All @@ -117,19 +117,19 @@ void GcodeSuite::M213() {
auto& limits = motionManager.getLimits();
auto& maxObj = limits.getMax();
auto writeConfig = false;
for(auto i = 0; i < 3; i++) {
if(parser.seen(XYZ_CHAR(i))) {

for (auto i = 0; i < 3; i++) {
if (parser.seen(XYZ_CHAR(i))) {
writeConfig = true;

setAxis(maxObj, i, parser.linear_value_to_mm(parser.value_linear_units()));
}
}
if(writeConfig) {

if (writeConfig) {
Controller::getInstance().save();
}

logLimits();
}

Expand Down
Loading

0 comments on commit 795ef37

Please sign in to comment.