Skip to content

Commit 91d22c5

Browse files
committed
orient.comp: Add modes with preceding referencing to index signal
1 parent ba9d306 commit 91d22c5

2 files changed

Lines changed: 74 additions & 14 deletions

File tree

src/emc/rs274ngc/interp_check.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,8 @@ int Interp::check_other_codes(block_pointer block) //!< pointer to a block
338338
CHKS(((motion == G_2 || motion == G_3 || (block->m_modes[7] == 19)) &&
339339
fabs(p_value - block->p_number) > 0.001),
340340
_("P value not an integer with M19 G2 or G3"));
341-
CHKS((block->m_modes[7] == 19) && ((p_value > 2) || p_value < 0),
342-
_("P value must be 0,1,or 2 with M19"));
341+
CHKS((block->m_modes[7] == 19) && ((p_value > 5) || p_value < 0),
342+
_("P value must be 0,1,2,3,4 or 5 with M19"));
343343
CHKS(((motion == G_2 || motion == G_3) && round_to_int(block->p_number) < 1),
344344
_("P value should be 1 or greater with G2 or G3"));
345345
}

src/hal/components/orient.comp

Lines changed: 72 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
component orient "Provide a PID command input for orientation mode based on current spindle position, target angle and orient mode";
22

33
pin in bit enable "enable angular output for orientation mode";
4-
pin in s32 mode "0: rotate - shortest move; 1: always rotate clockwise; 2: always rotate counterclockwise";
4+
pin in s32 mode "sets rotation direction";
55
pin in float position "spindle position input, unit 1 rev";
66
pin in float angle "orient target position in degrees, 0 ≤ angle < 360";
77
pin out float command "target spindle position, input to PID command";
88
pin out float poserr "in degrees - aid for PID tuning";
99
pin out bit is-oriented "This pin goes high when poserr < tolerance. Use to drive spindle.N.is-oriented";
1010
pin in float tolerance = 0.5 "The tolerance in degrees for considering the align completed";
11+
pin io bit index-enable "Connect to the spindle encoder counter to reset to index before orienting";
12+
13+
param r unsigned state "state machine for index homing";
1114

1215
variable int last_enable = 0;
1316
variable int debounce = 0; // to prevent the in-position triggering with the spindle moving
17+
variable double target_angle = 0;
18+
variable double latched_position = 0;
1419

1520
option fp yes;
1621
option period no;
@@ -37,6 +42,9 @@ The *mode* pin is interpreted as follows:
3742
which may be clockwise or counterclockwise.
3843
* 1: the spindle rotates always rotates clockwise to the new angle.
3944
* 2: the spindle rotates always rotates counterclockwise to the new angle.
45+
* 3: same as mode 0 but with homing to index before orienting to the new angle.
46+
* 4: same as mode 1 but with homing to index before orienting to the new angle.
47+
* 5: same as mode 2 but with homing to index before orienting to the new angle.
4048

4149
=== HAL USAGE
4250

@@ -63,16 +71,35 @@ license "GPL";
6371

6472
FUNCTION(_) {
6573

66-
double target_angle;
67-
double latched_position;
6874
is_oriented = 0; // spindle.is-oriented inhibits spindle.orient
69-
if (enable) {
70-
if (enable ^ last_enable) { // positive edge on enable
71-
is_oriented = 0;
75+
76+
switch (state){
77+
case 0: // waiting
78+
if (enable) {
79+
index_enable = 0;
80+
if (enable ^ last_enable) { // positive edge on enable
81+
is_oriented = 0;
82+
if (mode > 2){
83+
index_enable = 1;
84+
state = 3;
85+
} else {
86+
state = 1;
87+
}
88+
}
89+
}
90+
break;
91+
92+
case 1: // normal orient - init
93+
if (! enable) state = 0;
7294
debounce = 0;
7395
latched_position = position; // sample now
7496
target_angle = angle/360.0;
75-
switch (mode) {
97+
state = 2;
98+
break;
99+
100+
case 2: // orienting
101+
if (! enable) state = 0;
102+
switch (mode % 3) {
76103
case 0: // shortest move
77104
command = floor(latched_position+0.5-target_angle) + target_angle;
78105
break;
@@ -82,12 +109,45 @@ FUNCTION(_) {
82109
case 2: // always ccw
83110
command = floor(latched_position-target_angle) + target_angle ;
84111
break;
112+
default:
113+
rtapi_print_msg(RTAPI_MSG_ERR, "unhandled mode %i\n", mode % 3);
114+
}
115+
poserr = (position - command) * 360.0;
116+
debounce += (fabs(poserr) < tolerance && debounce <=100);
117+
is_oriented = (debounce > 100);
118+
if (is_oriented) state = 0;
119+
break;
120+
121+
case 3: // index search - init
122+
if (! enable) state = 0;
123+
latched_position = position; // sample now
124+
state = 4;
125+
break;
126+
127+
case 4: // waiting for spindle index
128+
if (! enable) state = 0;
129+
if (! index_enable){ // index has reset)
130+
state = 1;
131+
break;
132+
}
133+
switch (mode) {
134+
case 3: // shortest move to index
135+
if (0 > latched_position) {
136+
command = position + 0.5;
137+
} else {
138+
command = position - 0.5;
139+
}
140+
break;
141+
case 4: // always cw to index
142+
command = position + 0.5;
143+
break;
144+
case 5: // always ccw to index
145+
command = position - 0.5;
146+
break;
147+
default:
148+
rtapi_print_msg(RTAPI_MSG_ERR, "unhandled mode %i\n", mode);
85149
}
86-
}
87-
poserr = (position - command) * 360.0;
88-
debounce += (fabs(poserr) < tolerance && debounce <=100);
89-
is_oriented = (debounce > 100);
150+
break;
90151
}
91152
last_enable = enable;
92153
}
93-

0 commit comments

Comments
 (0)