1 |
|
/******************************************************************** |
2 |
|
* Description: interp_write.cc |
3 |
|
* |
4 |
|
* Derived from a work by Thomas Kramer |
5 |
|
* |
6 |
|
* Author: |
7 |
|
* License: GPL Version 2 |
8 |
|
* System: Linux |
9 |
|
* |
10 |
|
* Copyright (c) 2004 All rights reserved. |
11 |
|
* |
12 |
|
********************************************************************/ |
13 |
|
#include <unistd.h> |
14 |
|
#include <stdio.h> |
15 |
|
#include <stdlib.h> |
16 |
|
#include <math.h> |
17 |
|
#include <string.h> |
18 |
|
#include <ctype.h> |
19 |
|
#include <sys/types.h> |
20 |
|
#include <sys/stat.h> |
21 |
|
#include "rs274ngc.hh" |
22 |
|
#include "interp_return.hh" |
23 |
|
#include "interp_internal.hh" |
24 |
|
#include "rs274ngc_interp.hh" |
25 |
|
|
26 |
|
/****************************************************************************/ |
27 |
|
/*! write_g_codes |
28 |
|
|
29 |
|
Returned Value: int (INTERP_OK) |
30 |
|
|
31 |
|
Side effects: |
32 |
|
The active_g_codes in the settings are updated. |
33 |
|
|
34 |
|
Called by: |
35 |
|
Interp::execute |
36 |
|
Interp::init |
37 |
|
|
38 |
|
The block may be NULL. |
39 |
|
|
40 |
|
This writes active g_codes into the settings->active_g_codes array by |
41 |
|
examining the interpreter settings. The array of actives is composed |
42 |
|
of ints, so (to handle codes like 59.1) all g_codes are reported as |
43 |
|
ints ten times the actual value. For example, 59.1 is reported as 591. |
44 |
|
|
45 |
|
The correspondence between modal groups and array indexes is as follows |
46 |
|
(no apparent logic to it). |
47 |
|
|
48 |
|
The group 0 entry is taken from the block (if there is one), since its |
49 |
|
codes are not modal. |
50 |
|
|
51 |
|
group 0 - gez[2] g4, g10, g28, g30, g53, g92 g92.1, g92.2, g92.3 - misc |
52 |
|
group 1 - gez[1] g0, g1, g2, g3, g38.2, g80, g81, g82, g83, g84, g85, |
53 |
|
g86, g87, g88, g89 - motion |
54 |
|
group 2 - gez[3] g17, g18, g19 - plane selection |
55 |
|
group 3 - gez[6] g90, g91 - distance mode |
56 |
|
group 4 - gez[14] g90.1, g91.1 - IJK distance mode for arcs |
57 |
|
group 5 - gez[7] g93, g94, g95 - feed rate mode |
58 |
|
group 6 - gez[5] g20, g21 - units |
59 |
|
group 7 - gez[4] g40, g41, g42 - cutter radius compensation |
60 |
|
group 8 - gez[9] g43, g49 - tool length offse |
61 |
|
group 9 - no such group |
62 |
|
group 10 - gez[10] g98, g99 - return mode in canned cycles |
63 |
|
group 11 - no such group |
64 |
|
group 12 - gez[8] g54, g55, g56, g57, g58, g59, g59.1, g59.2, g59.3 |
65 |
|
- coordinate system |
66 |
|
group 13 - gez[11] g61, g61.1, g64 - control mode |
67 |
|
group 14 - gez[12] g50, g51 - adaptive feed mode |
68 |
|
group 15 - gez[13] g96, g97 - spindle speed mode |
69 |
|
group 16 - gez[15] g7,g8 - lathe diameter mode |
70 |
|
|
71 |
|
*/ |
72 |
|
|
73 |
4578 |
int Interp::write_g_codes(block_pointer block, //!< pointer to a block of RS274/NGC instructions |
74 |
|
setup_pointer settings) //!< pointer to machine settings |
75 |
|
{ |
76 |
|
int *gez; |
77 |
|
|
78 |
4578 |
gez = settings->active_g_codes; |
79 |
4578 |
gez[0] = settings->sequence_number; |
80 |
4578 |
gez[1] = settings->motion_mode; |
81 |
4578 |
gez[2] = ((block == NULL) ? -1 : block->g_modes[0]); |
82 |
4578 |
switch(settings->plane) { |
83 |
|
case CANON_PLANE_XY: |
84 |
4290 |
gez[3] = G_17; |
85 |
4290 |
break; |
86 |
|
case CANON_PLANE_XZ: |
87 |
218 |
gez[3] = G_18; |
88 |
218 |
break; |
89 |
|
case CANON_PLANE_YZ: |
90 |
60 |
gez[3] = G_19; |
91 |
60 |
break; |
92 |
|
case CANON_PLANE_UV: |
93 |
|
gez[3] = G_17_1; |
94 |
|
break; |
95 |
|
case CANON_PLANE_UW: |
96 |
|
gez[3] = G_18_1; |
97 |
|
break; |
98 |
|
case CANON_PLANE_VW: |
99 |
|
gez[3] = G_19_1; |
100 |
|
break; |
101 |
|
} |
102 |
|
gez[4] = |
103 |
4578 |
(settings->cutter_comp_side == RIGHT) ? G_42 : |
104 |
4578 |
(settings->cutter_comp_side == LEFT) ? G_41 : G_40; |
105 |
4578 |
gez[5] = (settings->length_units == CANON_UNITS_INCHES) ? G_20 : G_21; |
106 |
4578 |
gez[6] = (settings->distance_mode == MODE_ABSOLUTE) ? G_90 : G_91; |
107 |
4578 |
gez[7] = (settings->feed_mode == INVERSE_TIME) ? G_93 : |
108 |
4578 |
(settings->feed_mode == UNITS_PER_MINUTE) ? G_94 : G_95; |
109 |
|
gez[8] = |
110 |
4578 |
(settings->origin_index < |
111 |
4563 |
7) ? (530 + (10 * settings->origin_index)) : (584 + |
112 |
9141 |
settings->origin_index); |
113 |
4557 |
gez[9] = (settings->tool_offset.tran.x || settings->tool_offset.tran.y || settings->tool_offset.tran.z || |
114 |
4535 |
settings->tool_offset.a || settings->tool_offset.b || settings->tool_offset.c || |
115 |
9113 |
settings->tool_offset.u || settings->tool_offset.v || settings->tool_offset.w) ? G_43 : G_49; |
116 |
4578 |
gez[10] = (settings->retract_mode == OLD_Z) ? G_98 : G_99; |
117 |
|
gez[11] = |
118 |
4578 |
(settings->control_mode == CANON_CONTINUOUS) ? G_64 : |
119 |
4578 |
(settings->control_mode == CANON_EXACT_PATH) ? G_61 : G_61_1; |
120 |
4578 |
gez[12] = -1; |
121 |
|
gez[13] = |
122 |
4578 |
(settings->spindle_mode == CONSTANT_RPM) ? G_97 : G_96; |
123 |
4578 |
gez[14] = (settings->ijk_distance_mode == MODE_ABSOLUTE) ? G_90_1 : G_91_1; |
124 |
4578 |
gez[15] = (settings->lathe_diameter_mode) ? G_7 : G_8; |
125 |
4578 |
return INTERP_OK; |
126 |
|
} |
127 |
|
|
128 |
|
/****************************************************************************/ |
129 |
|
|
130 |
|
/*! write_m_codes |
131 |
|
|
132 |
|
Returned Value: int (INTERP_OK) |
133 |
|
|
134 |
|
Side effects: |
135 |
|
The settings->active_m_codes are updated. |
136 |
|
|
137 |
|
Called by: |
138 |
|
Interp::execute |
139 |
|
Interp::init |
140 |
|
|
141 |
|
This is testing only the feed override to see if overrides is on. |
142 |
|
Might add check of speed override. |
143 |
|
|
144 |
|
*/ |
145 |
|
|
146 |
4578 |
int Interp::write_m_codes(block_pointer block, //!< pointer to a block of RS274/NGC instructions |
147 |
|
setup_pointer settings) //!< pointer to machine settings |
148 |
|
{ |
149 |
|
int *emz; |
150 |
|
|
151 |
4578 |
emz = settings->active_m_codes; |
152 |
4578 |
emz[0] = settings->sequence_number; /* 0 seq number */ |
153 |
4578 |
emz[1] = (block == NULL) ? -1 : block->m_modes[4]; /* 1 stopping */ |
154 |
4578 |
emz[2] = (settings->spindle_turning == CANON_STOPPED) ? 5 : /* 2 spindle */ |
155 |
4578 |
(settings->spindle_turning == CANON_CLOCKWISE) ? 3 : 4; |
156 |
|
emz[3] = /* 3 tool change */ |
157 |
4578 |
(block == NULL) ? -1 : block->m_modes[6]; |
158 |
|
emz[4] = /* 4 mist */ |
159 |
4578 |
(settings->mist) ? 7 : (settings->flood) ? -1 : 9; |
160 |
|
emz[5] = /* 5 flood */ |
161 |
4578 |
(settings->flood) ? 8 : -1; |
162 |
4578 |
if (settings->feed_override) { |
163 |
4578 |
if (settings->speed_override) emz[6] = 48; |
164 |
|
else emz[6] = 50; |
165 |
|
} else if (settings->speed_override) { |
166 |
|
emz[6] = 51; |
167 |
|
} else emz[6] = 49; |
168 |
|
|
169 |
|
emz[7] = /* 7 overrides */ |
170 |
4578 |
(settings->adaptive_feed) ? 52 : -1; |
171 |
|
|
172 |
|
emz[8] = /* 8 overrides */ |
173 |
4578 |
(settings->feed_hold) ? 53 : -1; |
174 |
|
|
175 |
4578 |
return INTERP_OK; |
176 |
|
} |
177 |
|
|
178 |
|
/****************************************************************************/ |
179 |
|
|
180 |
|
/*! write_settings |
181 |
|
|
182 |
|
Returned Value: int (INTERP_OK) |
183 |
|
|
184 |
|
Side effects: |
185 |
|
The settings->active_settings array of doubles is updated with the |
186 |
|
sequence number, feed, and speed settings. |
187 |
|
|
188 |
|
Called by: |
189 |
|
Interp::execute |
190 |
|
Interp::init |
191 |
|
|
192 |
|
*/ |
193 |
|
|
194 |
4578 |
int Interp::write_settings(setup_pointer settings) //!< pointer to machine settings |
195 |
|
{ |
196 |
|
double *vals; |
197 |
|
|
198 |
4578 |
vals = settings->active_settings; |
199 |
4578 |
vals[0] = settings->sequence_number; /* 0 sequence number */ |
200 |
4578 |
vals[1] = settings->feed_rate; /* 1 feed rate */ |
201 |
4578 |
vals[2] = settings->speed; /* 2 spindle speed */ |
202 |
|
|
203 |
4578 |
return INTERP_OK; |
204 |
|
} |
205 |
|
|
206 |
|
/****************************************************************************/ |