Skip to content

Commit bfb6693

Browse files
author
David
committed
Return E22 when position unreachable
1 parent 5797b41 commit bfb6693

5 files changed

Lines changed: 79 additions & 17 deletions

File tree

lib/Marlin/Configuration.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
//#define SWIFT_TEST_MODE
132132

133133
#define HW_VER "3.3"
134-
#define SW_VER_BASE "3.1.17"
134+
#define SW_VER_BASE "3.1.18"
135135

136136
#ifdef SWIFT_TEST_MODE
137137
#define SW_VER SW_VER_BASE"_t"

lib/Marlin/Marlin_main.cpp

Lines changed: 72 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,7 +1720,7 @@ void get_pos_from_polor(float pos[], float polor[])
17201720
}
17211721

17221722

1723-
void gcode_get_destination_polor()
1723+
uint8_t gcode_get_destination_polor()
17241724
{
17251725
float polor_destination[NUM_AXIS];
17261726
float current_polor[NUM_AXIS];
@@ -1744,13 +1744,26 @@ void gcode_get_destination_polor()
17441744
debugPrint("des polor:%f %f %f\r\n", polor_destination[0], polor_destination[1],polor_destination[2]);
17451745

17461746

1747-
get_pos_from_polor(destination, polor_destination);
1747+
float test_destination[NUM_AXIS] = {0.0};
1748+
get_pos_from_polor(test_destination, polor_destination);
17481749

17491750

1751+
debugPrint("des: %f, %f, %f\r\n", test_destination[0], test_destination[1], test_destination[2]);
1752+
1753+
float angle[3];
1754+
1755+
if (inverse_kinematics(test_destination, angle) != 0)
1756+
return E_OUT_OF_RANGE;
1757+
1758+
debugPrint("angle: %f, %f, %f\r\n", angle[0], angle[1], angle[2]);
1759+
17501760

17511761

1752-
debugPrint("destination:%f %f %f\r\n", destination[0], destination[1], destination[2]);
17531762

1763+
LOOP_XYZE(i)
1764+
destination[i] = test_destination[i];
1765+
1766+
debugPrint("destination:%f %f %f\r\n", destination[0], destination[1], destination[2]);
17541767

17551768
if (code_seen('F') && code_value_linear_units() > 0.0)
17561769
feedrate_mm_m = code_value_linear_units();
@@ -1828,9 +1841,14 @@ unsigned char inverse_kinematics(const float in_cartesian[3], float angle[3]) {
18281841

18291842
zIn = (z - MATH_L1) / MATH_LOWER_ARM;
18301843

1831-
if (x < 0.1)
1844+
float s = sqrt(x*x + y*y);
1845+
1846+
if (s - get_front_end_offset() < POLAR_MODULE_LENGTH_MIN)
1847+
return -1;
1848+
1849+
if (x < 0.01)
18321850
{
1833-
x = 0.1;
1851+
x = 0.01;
18341852
}
18351853

18361854
// Calculate value of theta 1: the rotation angle
@@ -2955,16 +2973,33 @@ static void homeaxis(AxisEnum axis) {
29552973
* - Set to current for missing axis codes
29562974
* - Set the feedrate, if included
29572975
*/
2958-
void gcode_get_destination() {
2976+
uint8_t gcode_get_destination() {
2977+
2978+
float test_destination[NUM_AXIS] = { 0.0 };
2979+
2980+
29592981
LOOP_XYZE(i) {
29602982
if (code_seen(axis_codes[i]))
29612983
{
2962-
destination[i] = code_value_axis_units(i) + (axis_relative_modes[i] || relative_mode ? current_position[i] : 0);
2984+
test_destination[i] = code_value_axis_units(i) + (axis_relative_modes[i] || relative_mode ? current_position[i] : 0);
29632985
}
29642986
else
2965-
destination[i] = current_position[i];
2987+
test_destination[i] = current_position[i];
29662988
}
29672989

2990+
debugPrint("des: %f, %f, %f\r\n", test_destination[0], test_destination[1], test_destination[2]);
2991+
2992+
float angle[3];
2993+
2994+
if (inverse_kinematics(test_destination, angle) != 0)
2995+
return E_OUT_OF_RANGE;
2996+
2997+
debugPrint("angle: %f, %f, %f\r\n", angle[0], angle[1], angle[2]);
2998+
2999+
3000+
LOOP_XYZE(i)
3001+
destination[i] = test_destination[i];
3002+
29683003
if (code_seen('F') && code_value_linear_units() > 0.0)
29693004
feedrate_mm_m = code_value_linear_units();
29703005

@@ -2977,6 +3012,8 @@ void gcode_get_destination() {
29773012
#if ENABLED(MIXING_EXTRUDER) && ENABLED(DIRECT_MIXING_IN_G1)
29783013
gcode_get_mix();
29793014
#endif
3015+
3016+
return E_OK;
29803017
}
29813018

29823019
void unknown_command_error() {
@@ -3022,9 +3059,12 @@ void unknown_command_error() {
30223059
/**
30233060
* G0, G1: Coordinated movement of X Y Z E axes
30243061
*/
3025-
inline void gcode_G0_G1() {
3062+
inline uint8_t gcode_G0_G1() {
30263063
if (IsRunning()) {
3027-
gcode_get_destination(); // For X Y Z E F
3064+
uint8_t result = gcode_get_destination(); // For X Y Z E F
3065+
3066+
if (result != E_OK)
3067+
return result;
30283068

30293069
#if ENABLED(FWRETRACT)
30303070

@@ -7464,13 +7504,15 @@ void process_next_command() {
74647504
#ifdef UARM_SWIFT
74657505
uarm_gcode_G0();
74667506
#endif
7467-
gcode_G0_G1();
7507+
needReply = 1;
7508+
result = gcode_G0_G1();
74687509
break;
74697510
case 1:
74707511
#ifdef UARM_SWIFT
74717512
uarm_gcode_G1();
74727513
#endif
7473-
gcode_G0_G1();
7514+
needReply = 1;
7515+
result = gcode_G0_G1();
74747516
break;
74757517

74767518
// G2, G3
@@ -7570,7 +7612,8 @@ void process_next_command() {
75707612
break;
75717613

75727614
case 2201:
7573-
gcode_get_destination_polor();
7615+
needReply = 1;
7616+
result = gcode_get_destination_polor();
75747617
break;
75757618

75767619
// rotate stepper motor
@@ -7606,7 +7649,8 @@ void process_next_command() {
76067649
{
76077650
bool relative_mode_backup = relative_mode;
76087651
relative_mode = true;
7609-
gcode_G0_G1();
7652+
needReply = 1;
7653+
result = gcode_G0_G1();
76107654
relative_mode = relative_mode_backup;
76117655
}
76127656
break;
@@ -7615,11 +7659,15 @@ void process_next_command() {
76157659
{
76167660
bool relative_mode_backup = relative_mode;
76177661
relative_mode = true;
7618-
gcode_get_destination_polor();
7662+
needReply = 1;
7663+
result = gcode_get_destination_polor();
76197664
relative_mode = relative_mode_backup;
76207665
}
76217666
break;
76227667

7668+
default:
7669+
code_is_good = false;
7670+
break;
76237671
#endif // UARM_SWIFT
76247672

76257673
}
@@ -8280,6 +8328,10 @@ void process_next_command() {
82808328
uarm_gcode_M2500();
82818329
break;
82828330

8331+
default:
8332+
code_is_good = false;
8333+
break;
8334+
82838335

82848336
#endif //UARM_SWIFT
82858337
}
@@ -8387,6 +8439,11 @@ void process_next_command() {
83878439
result = uarm_gcode_P2250(replyBuf);
83888440
break;
83898441
#endif
8442+
8443+
default:
8444+
code_is_good = false;
8445+
break;
8446+
83908447
}
83918448
break;
83928449

lib/Marlin/uArmParams.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@
114114
#define LOWER_UPPER_MAX_ANGLE 151
115115
#define LOWER_UPPER_MIN_ANGLE 10
116116

117+
#define POLAR_MODULE_LENGTH_MIN 72
118+
117119

118120
#define BT_NAME_MAX_LEN 11
119121

lib/Marlin/uArmSwift.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ void uarm_gcode_G0()
295295

296296

297297

298-
debugPrint("laser off");
298+
debugPrint("laser off\r\n");
299299

300300
// turn off laser
301301
analogWrite(FAN_PIN, 0);

update.log

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
v3.1.18 20170725
2+
Return E22 when position unreachable
3+
14
v3.1.17 20170725
25
Do no switch to absolute mode in G2204/G2205
36

0 commit comments

Comments
 (0)