summaryrefslogtreecommitdiff
path: root/docs/src/examples/spindle_es.txt
blob: 0209749834ef6014c7aa66917d0dd7ff13e2eccb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
= Spindle Control

[[cha:Spindle-Control]] (((Spindle Control)))

////
ATTENTION TRANSLATORS before translating this document copy the base document
into this copy to get the latest version. Untranslated documents are not kept
up to date with the English documents. 

Do not translate anchors or links, translate only the text of a link after the
comma.
Anchor [[anchor-name]]
Link <<anchor-name,text after the comma can be translated>>

Make sure the documents build after translating.
////

== 0-10v Spindle Speed (((0-10v Spindle Speed)))

If your spindle speed is controlled by an analog signal, 
(for example, by a VFD with a 0 to 10 volt signal) and
you're using a DAC card like the m5i20 to output the control signal: 

First you need to figure the scale of spindle speed to control signal.
For this example the spindle top speed of 5000 RPM is equal to 10
volts. 

image::images/spindle-math.png[align="center"]

We have to add a scale component to the HAL file to scale the
motion.spindle-speed-out to the 0 to 10 needed by the VFD if your DAC
card does not do scaling.

----
loadrt scale count=1
addf scale.0 servo-thread
setp scale.0.gain 0.002    
net spindle-speed-scale motion.spindle-speed-out => scale.0.in
net spindle-speed-DAC scale.0.out => <your DAC pin name>    
----

== PWM Spindle Speed (((PWM Spindle Speed)))

If your spindle can be controlled by a PWM signal, 
use the pwmgen component to create the signal:

----
loadrt pwmgen output_type=0 
addf pwmgen.update servo-thread
addf pwmgen.make-pulses base-thread    
net spindle-speed-cmd motion.spindle-speed-out => pwmgen.0.value
net spindle-on motion.spindle-on => pwmgen.0.enable
net spindle-pwm pwmgen.0.pwm => parport.0.pin-09-out
# Set the spindle's top speed in RPM
setp pwmgen.0.scale 1800
----

This assumes that the spindle controller's response to PWM is simple:
0% PWM gives 0 RPM, 10% PWM gives 180 RPM, etc. If there is a minimum
PWM required to get the spindle to turn, follow the example in the
nist-lathe sample configuration to use a scale component.

== Spindle Enable (((Spindle Enable)))

If you need a spindle enable signal, 
link your output pin to motion.spindle-on. 
To link these pins to a parallel port pin put something like 
the following in your .hal file, making sure you pick the
pin that is connected to your control device.

----
net spindle-enable motion.spindle-on => parport.0.pin-14-out
----

== Spindle Direction (((Spindle Direction)))

If you have direction control of your spindle the HAL pins
motion.spindle-forward and motion.spindle-reverse are controlled by M3
and M4. Spindle speed 'Sn' must be set to a positive non-zero value for
M3/M4 to turn on spindle motion.

To link these pins to a parallel port pin, put something like the
following in your .hal file making sure you pick the pin that is
connected to your control device.

----
net spindle-fwd motion.spindle-forward => parport.0.pin-16-out
net spindle-rev motion.spindle-reverse => parport.0.pin-17-out
----

== Spindle Soft Start (((Spindle Soft Start)))

If you need to ramp your spindle speed command and your control does
not have that feature it can be done in HAL. Basically you need to
hijack the output of motion.spindle-speed-out and run it through a
limit2 component with the scale set so it will ramp the rpm from
motion.spindle-speed-out to your device that receives the rpm. The
second part is to let LinuxCNC know when the spindle is at speed so motion
can begin.

In the 0-10 volt example the line
    'net spindle-speed-scale motion.spindle-speed-out => scale.0.in'
is changed as shown in the following example:

.Intro to HAL components limit2 and near:
*********************************************************************
In case you have not run across them before, here's a quick introduction 
to the two HAL components used in the following example. 

* A "limit2" is a HAL component (floating point) that accepts an 
   input value and provides an output that has been limited to a 
   max/min range, and also limited to not exceed a specified 
   rate of change. 

* A "near" is a HAL component (floating point) with a binary output 
   that says whether two inputs are approximately equal. 

More info is available in the documentation for HAL components, 
or from the man pages, just say 'man limit2' or 'man near' in a terminal. 
*********************************************************************

----
# load real time a limit2 and a near with names so it is easier to follow
loadrt limit2 names=spindle-ramp
loadrt near names=spindle-at-speed

# add the functions to a thread
addf spindle-ramp servo-thread
addf spindle-at-speed servo-thread

# set the parameter for max rate-of-change
# (max spindle accel/decel in units per second)
setp spindle-ramp.maxv 60

# hijack the spindle speed out and send it to spindle ramp in
net spindle-cmd <= motion.spindle-speed-out => spindle-ramp.in

# the output of spindle ramp is sent to the scale in
net spindle-ramped <= spindle-ramp.out => scale.0.in

# to know when to start the motion we send the near component 
# (named spindle-at-speed) to the spindle commanded speed from
# the signal spindle-cmd and the actual spindle speed
# provided your spindle can accelerate at the maxv setting.
net spindle-cmd => spindle-at-speed.in1
net spindle-ramped => spindle-at-speed.in2

# the output from spindle-at-speed is sent to motion.spindle-at-speed
# and when this is true motion will start
net spindle-ready <= spindle-at-speed.out => motion.spindle-at-speed
----

== Spindle Feedback[[spindle-feedback]]

(((Spindle Feedback)))

=== Spindle Synchronized Motion[[sec:Spindle-Synchronized-Motion]]

(((Spindle Synchronized Motion)))

Spindle feedback is needed by LinuxCNC to perform any spindle coordinated
motions like threading and constant surface speed. The StepConf Wizard
can perform the connections for you if you select Encoder Phase A and
Encoder Index as inputs.

Hardware assumptions:

* An encoder is connected to the spindle and puts out 100 pulses per
   revolution on phase A
* The encoder A phase is connected to the parallel port pin 10
* The encoder index pulse is connected to the parallel port pin 11

Basic Steps to add the components and configure them:

----
# add the encoder to HAL and attach it to threads.footnote:[In this 
example, we will assume that some encoders have already been issued 
to axes/joints 0, 1, and 2. So the next encoder available for us to 
attach to the spindle would be number 3. Your situation may differ.] 
loadrt encoder num_chan=1
addf encoder.update-counters base-thread
addf encoder.capture-position servo-thread

# set the HAL encoder to 100 pulses per revolution.
setp encoder.3.position-scale 100

# set the HAL encoder to non-quadrature simple counting using A only.
setp encoder.3.counter-mode true

# connect the HAL encoder outputs to LinuxCNC.footnote:[The HAL encoder 
index-enable is an exception to the rule in that it behaves 
as both an input and an output, see manual for details]
net spindle-position encoder.3.position => motion.spindle-revs
net spindle-velocity encoder.3.velocity => motion.spindle-speed-in
net spindle-index-enable encoder.3.index-enable <=> motion.spindle-index-enable

# connect the HAL encoder inputs to the real encoder.
net spindle-phase-a encoder.3.phase-A <= parport.0.pin-10-in
net spindle-phase-b encoder.3.phase-B footnote:[It is because 
we selected 'non-quadrature simple counting...' above that we 
can get away with 'quadrature' counting without having any 
B quadrature input.] 
net spindle-index encoder.3.phase-Z <= parport.0.pin-11-in
----

=== Spindle At Speed[[sec:Spindle-At-Speed]]

(((Spindle At Speed)))

To enable LinuxCNC to wait for the spindle to be at speed before executing
a series of moves you need to set motion.spindle-at-speed to true when
the spindle is at the commanded speed. To do this you need spindle
feedback from an encoder. Since the feedback and the commanded speed
are not usually 'exactly' the same you need to use the 'near'
component to say that the two numbers are close enough. 

The connections needed are from the spindle
velocity command signal to near.n.in1 and from the spindle velocity
from the encoder to near.n.in2. Then the near.n.out is connected to
motion.spindle-at-speed. The near.n.scale needs to be set to say how
close the two numbers must be before turning on the output. Depending
on your setup you may need to adjust the scale to work with your
hardware. 

The following is typical of the additions needed to your HAL
file to enable Spindle At Speed. If you already have near in your HAL
file then increase the count and adjust code to suit. Check to make
sure the signal names are the same in your HAL file.

----
# load a near component and attach it to a thread
loadrt near
addf near.0 servo-thread

# connect one input to the commanded spindle speed
net spindle-cmd => near.0.in1

# connect one input to the encoder-measured spindle speed
net spindle-velocity => near.0.in2

# connect the output to the spindle-at-speed input
net spindle-at-speed motion.spindle-at-speed <= near.0.out

# set the spindle speed inputs to agree if within 1%
setp near.0.scale 1.01
----