rotor 0.1.2 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/README.md +241 -176
- data/lib/rotor/gcode.rb +10 -17
- data/lib/rotor/stepper.rb +2 -2
- data/lib/rotor/version.rb +1 -1
- metadata +2 -5
- data/.DS_Store +0 -0
- data/lib/.DS_Store +0 -0
- data/lib/rotor/.DS_Store +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e48e610c2097d68d9a98bbf70151730a9957875
|
4
|
+
data.tar.gz: be5914357afb26ab29806eb649f1f00196fa8267
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c35be0d4fbde64f072d1405913058437be150c37842f42afbd24a50df9f4258089d23c9801d6d877cfa1c95e02a375db2f2feaa67da2716a5f889910ba9a69e5
|
7
|
+
data.tar.gz: e00420f6330260ee0bf2f5ec49e0e84d60fc8ea78457610ae0cc7536f38bab87e087a12982822ea5b2532d9f3928879937df20b2658980d4d94351e4a8ce9916
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,220 +1,285 @@
|
|
1
|
-
|
1
|
+
Rotor (Ruby Motor)
|
2
|
+
==================
|
2
3
|
|
3
4
|
Tested on RaspberryPi Model B+ but should work for any Raspberry Pi.
|
4
5
|
|
5
|
-
This Ruby gem allows you to control different kinds of stepper motors. You
|
6
|
-
|
7
|
-
|
6
|
+
This Ruby gem allows you to control different kinds of stepper motors. You can
|
7
|
+
use this gem to run both Bipolar and Unipolar motors with either L293D or
|
8
|
+
ULN2800 Integrated Controllers.
|
8
9
|
|
9
|
-
|
10
|
+
Installation
|
11
|
+
------------
|
10
12
|
|
11
|
-
|
13
|
+
### WiringPi
|
12
14
|
|
13
|
-
|
15
|
+
Make sure that you have WiringPi installed first
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
18
|
+
gem install wiringpi
|
19
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
17
20
|
|
18
|
-
|
19
|
-
|
21
|
+
If you are using GPIO Pins from a A+/B+, you may need to update your WiringPi
|
22
|
+
libraries. You can pull from my repo
|
23
|
+
[https://github.com/kobaltz/WiringPi-Ruby][1]
|
20
24
|
|
21
|
-
|
25
|
+
[1]: <https://github.com/kobaltz/WiringPi-Ruby >
|
22
26
|
|
23
|
-
|
27
|
+
I did not write any of the WiringPi-Ruby platform. I simply pulled the latest C
|
28
|
+
libraries and recompiled the gem.
|
24
29
|
|
25
|
-
|
30
|
+
### Rotor
|
26
31
|
|
27
|
-
|
28
|
-
|
29
|
-
|
32
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
33
|
+
gem install rotor
|
34
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
30
35
|
|
31
|
-
|
32
|
-
|
36
|
+
Notes
|
37
|
+
=====
|
33
38
|
|
34
|
-
|
35
|
-
|
39
|
+
This gem has been built for my personal project. I do not and cannot know if
|
40
|
+
this will work with your setup. However, put in an issue if you're having
|
41
|
+
troubles with this gem and I will try to help you as best as I can.
|
36
42
|
|
37
|
-
|
43
|
+
I am using two stepper motors (NEMA17 Bipolar 20Ncm 12V) and two L293D motor
|
44
|
+
drivers. This gem has also been tested with a small 5V Unipolar Stepper Motor
|
45
|
+
and 12V Unipolar Stepper Motor.
|
38
46
|
|
39
|
-
|
47
|
+
My Steps Per MM is based on a 200 step per revolution motor and a threaded rod
|
48
|
+
with 20 threads per inch. This means that I will have to step 4000 times to move
|
49
|
+
the coupler one inch.
|
40
50
|
|
41
|
-
|
42
|
-
|
51
|
+
Usage
|
52
|
+
=====
|
43
53
|
|
44
|
-
|
45
|
-
|
46
|
-
stepper.backwards(delay=5,steps=100)
|
47
|
-
stepper.set_home(direction) #:forward or :backwards
|
48
|
-
stepper.at_home?
|
49
|
-
stepper.at_safe_area? # opposite of at_home?
|
54
|
+
Class Stepper
|
55
|
+
-------------
|
50
56
|
|
51
|
-
|
52
|
-
|
57
|
+
MAKE SURE THAT YOU HAVE CONFIGURED THE Rotor::Stepper WITH THE CORRECT GPIO PIN
|
58
|
+
NUMBERS. CHECK AND DOUBLE CHECK THESE BEFORE RUNNING YOUR CODE. This has been
|
59
|
+
tested with both Bipolar and Unipolar Stepper Motors
|
53
60
|
|
54
|
-
|
61
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
62
|
+
stepper = Rotor::Stepper.new(coil_A_1_pin, coil_A_2_pin, coil_B_1_pin, coil_B_2_pin, enable_pin=nil, homing_switch, homing_normally, steps_per_mm)
|
63
|
+
stepper.forward(delay=5,steps=100) # stepper.forward(5,100)
|
64
|
+
stepper.backwards(delay=5,steps=100)# stepper.backwards(5,100)
|
65
|
+
stepper.set_home(direction) #:forward or :backwards
|
66
|
+
stepper.at_home?
|
67
|
+
stepper.at_safe_area? # opposite of at_home?
|
68
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
55
69
|
|
56
|
-
|
70
|
+
After running your GCode, you may want to consider to power down the motor by
|
71
|
+
sending a LOW to each step.
|
57
72
|
|
58
|
-
|
59
|
-
|
73
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
74
|
+
stepper.power_down
|
75
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
60
76
|
|
61
|
-
|
77
|
+
Class Servo
|
78
|
+
-----------
|
62
79
|
|
63
|
-
|
80
|
+
You can use a servo to control the marker (or leave blank if you're using a Z
|
81
|
+
Axis Stepper) This will be built out so that the strength control of the servo
|
82
|
+
(for laser power) can be adjusted and inputs sent in. However, for development
|
83
|
+
purposes, I recommend not playing with lasers, but rather get the machine and
|
84
|
+
code working properly first.
|
64
85
|
|
65
|
-
|
86
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
87
|
+
servo = Rotor::Servo.new(pin=18)# Rotor::Servo.new(18)
|
88
|
+
servo.rotate(direction) # :up or :down
|
89
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
66
90
|
|
67
|
-
|
91
|
+
Class GCode
|
92
|
+
-----------
|
68
93
|
|
69
|
-
|
70
|
-
gcode = Rotor::Gcode.new(nil,nil,nil,1,nil)
|
71
|
-
gcode.open('output.nc')
|
72
|
-
gcode.simulate
|
94
|
+
The plot points are streamed to output.txt file on your computer.
|
73
95
|
|
74
|
-
|
75
|
-
other solutions.
|
96
|
+
You can test the outputs of your GCODE and the XY plots it creates by Rotor.
|
76
97
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
98
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
99
|
+
File.open("output.txt", 'wb') { |file| file.write("x,y,xm,ym\n") }
|
100
|
+
gcode = Rotor::Gcode.new(nil,nil,nil,1,nil)
|
101
|
+
gcode.open('output.nc')
|
102
|
+
gcode.simulate(accuracy=8,speed=1)
|
103
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
82
104
|
|
83
|
-
|
84
|
-
|
105
|
+
When using the simulate option on the Gcode class, you can now enter additional
|
106
|
+
parameters which will increase accuracy as well as speed. The accuracy
|
107
|
+
parameter will be used in the logic of determining how many steps in the arc
|
108
|
+
will occur. The Max of the distance calculation and accuracy variable will be
|
109
|
+
the number of steps on a given arc. The speed parameter is in ms and will be
|
110
|
+
the delay between steps.
|
85
111
|
|
86
|
-
|
87
|
-
|
88
|
-
adjusted and inputs sent in. However, for development purposes, I recommend not playing with
|
89
|
-
lasers, but rather get the machine and code working properly first.
|
112
|
+
The goal of this gem is to make controlling your robotics easier than other
|
113
|
+
solutions.
|
90
114
|
|
91
|
-
|
115
|
+
Added Homing Switch options where you can add the GPIO of the switch and
|
116
|
+
indicate if it is normally open or normally closed. I have my homing switches on
|
117
|
+
each axis configured in parallel since I know the direction that the panel is
|
118
|
+
moving in and therefore know which side it has hit. This was to reduce the
|
119
|
+
number of GPIO pins required.
|
92
120
|
|
93
|
-
|
121
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
122
|
+
stepper_x = Rotor::Stepper.new(23,12,17,24,nil,13,0,157.48)
|
123
|
+
stepper_y = Rotor::Stepper.new(25, 4,21,22,nil,19,0,157.48)
|
124
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
94
125
|
|
95
|
-
|
96
|
-
|
97
|
-
|
126
|
+
You can send the stepper motor to the outter edges of the board. You will want
|
127
|
+
to play with the :backwards and :forward options to make sure that they’re
|
128
|
+
moving in the correct direction for your stepper motor.
|
98
129
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
threads.each { |thr| thr.join }
|
110
|
-
|
111
|
-
puts "Enter steps backward::"
|
112
|
-
text = gets.chomp
|
113
|
-
|
114
|
-
stepper_x.backwards(5,text.to_i)
|
115
|
-
stepper_y.backwards(5,text.to_i)
|
116
|
-
end
|
117
|
-
|
118
|
-
# GCode Simulation
|
119
|
-
|
120
|
-
GCode can be simulated (this is my latest part of the project) where
|
121
|
-
a file can be read in and the movements interpreted. I'm still working
|
122
|
-
on the ARC movement on G02 and G03, but have gotten G0 and G1 working.
|
123
|
-
|
124
|
-
Enter each stepper motor (or nil if you do not have that particular axis)
|
125
|
-
along with the scale (multiplies all coordinates by this. Typically you will
|
126
|
-
keep this at 1).
|
127
|
-
|
128
|
-
#gcode = Rotor::Gcode.new(stepper_x,stepper_y,stepper_z,1,servo)
|
129
|
-
gcode = Rotor::Gcode.new(nil,nil,nil,1,nil)
|
130
|
-
gcode.open('sample.nc')
|
131
|
-
gcode.simulate
|
132
|
-
|
133
|
-
# Asynchronous Movement
|
134
|
-
|
135
|
-
By default, if you run the first motor and then the second motor commands,
|
136
|
-
the first command will execute first and the second one will execute afterwards.
|
137
|
-
This may not always be the desired result as your plot/laser/mill may get ruined
|
138
|
-
by having nonsynchronous movements.
|
139
|
-
|
140
|
-
Since Ruby by default will not asynchronously execute commands, you can combine
|
141
|
-
the X/Y/Z movements into their own threads.
|
142
|
-
|
143
|
-
threads = []
|
144
|
-
threads << Thread.new { stepper_x.forward(5,text.to_i) }
|
145
|
-
threads << Thread.new { stepper_y.forward(5,text.to_i) }
|
146
|
-
threads.each { |thr| thr.join }
|
147
|
-
|
148
|
-
# Sample Code
|
149
|
-
|
150
|
-
## Production (Moving Stepper and Servo)
|
130
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
131
|
+
stepper_x = Rotor::Stepper.new(23,12,17,24,nil,13,LOW,157.48)
|
132
|
+
stepper_y = Rotor::Stepper.new(25, 4,21,22,nil,19,LOW,157.48)
|
133
|
+
|
134
|
+
stepper_x.set_home(:backwards)
|
135
|
+
stepper_y.set_home(:forward)
|
136
|
+
|
137
|
+
loop do
|
138
|
+
puts "Enter steps forward::"
|
139
|
+
text = gets.chomp
|
151
140
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
stepper_x = Rotor::Stepper.new(23,12,17,24,nil,13,0,157.48)
|
157
|
-
stepper_y = Rotor::Stepper.new(25, 4,21,22,nil,19,0,157.48)
|
158
|
-
servo = Rotor::Servo.new(18)
|
159
|
-
|
160
|
-
stepper_x.set_home(:backwards)
|
161
|
-
stepper_y.set_home(:backwards)
|
162
|
-
stepper_x.forward(1,4000)
|
163
|
-
stepper_y.forward(1,4000)
|
164
|
-
|
165
|
-
gcode = Rotor::Gcode.new(stepper_x,stepper_y,nil,1,servo)
|
166
|
-
gcode.open('output.nc')
|
167
|
-
gcode.simulate
|
168
|
-
|
169
|
-
ensure
|
170
|
-
servo.rotate(:up)
|
171
|
-
|
172
|
-
stepper_x.set_home(:backwards)
|
173
|
-
stepper_y.set_home(:backwards)
|
174
|
-
stepper_x.forward(1,4000)
|
175
|
-
stepper_y.forward(1,4000)
|
176
|
-
|
177
|
-
stepper_x.power_down
|
178
|
-
stepper_y.power_down
|
179
|
-
|
180
|
-
[23,12,17,24,13,25,4,21,22,19,13].each do |pin|
|
181
|
-
`echo #{pin} > /sys/class/gpio/unexport`
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
## Development (Exporting Plot Points for Graphing)
|
141
|
+
threads = []
|
142
|
+
threads << Thread.new { stepper_x.forward(5,text.to_i) }
|
143
|
+
threads << Thread.new { stepper_y.forward(5,text.to_i) }
|
144
|
+
threads.each { |thr| thr.join }
|
186
145
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
146
|
+
puts "Enter steps backward::"
|
147
|
+
text = gets.chomp
|
148
|
+
|
149
|
+
stepper_x.backwards(5,text.to_i)
|
150
|
+
stepper_y.backwards(5,text.to_i)
|
151
|
+
end
|
152
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
153
|
+
|
154
|
+
GCode Simulation
|
155
|
+
================
|
156
|
+
|
157
|
+
GCode can be simulated (this is my latest part of the project) where a file can
|
158
|
+
be read in and the movements interpreted. Right now, G02 and G03 will work with
|
159
|
+
I and J offsets. Radius is not currently supported.
|
160
|
+
|
161
|
+
Enter each stepper motor (or nil if you do not have that particular axis) along
|
162
|
+
with the scale (multiplies all coordinates by this. Typically you will keep this
|
163
|
+
at 1).
|
164
|
+
|
165
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
166
|
+
#gcode = Rotor::Gcode.new(stepper_x,stepper_y,stepper_z,1,servo)
|
167
|
+
gcode = Rotor::Gcode.new(nil,nil,nil,1,nil)
|
168
|
+
gcode.open('sample.nc')
|
169
|
+
gcode.simulate(accuracy=8,speed=1)
|
170
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
171
|
+
|
172
|
+
By passing nil into each stepper motor and servo, you can simulate the GCode
|
173
|
+
execution.
|
174
|
+
|
175
|
+
Asynchronous Movement
|
176
|
+
=====================
|
177
|
+
|
178
|
+
By default, if you run the first motor and then the second motor commands, the
|
179
|
+
first command will execute first and the second one will execute afterwards.
|
180
|
+
This may not always be the desired result as your plot/laser/mill may get ruined
|
181
|
+
by having nonsynchronous movements.
|
182
|
+
|
183
|
+
Since Ruby by default will not asynchronously execute commands, you can combine
|
184
|
+
the X/Y/Z movements into their own threads.
|
185
|
+
|
186
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
187
|
+
threads = []
|
188
|
+
threads << Thread.new { stepper_x.forward(5,text.to_i) }
|
189
|
+
threads << Thread.new { stepper_y.forward(5,text.to_i) }
|
190
|
+
threads.each { |thr| thr.join }
|
191
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
192
|
+
|
193
|
+
Sample Code
|
194
|
+
===========
|
195
|
+
|
196
|
+
Production (Moving Stepper and Servo)
|
197
|
+
-------------------------------------
|
198
|
+
|
199
|
+
Here is the real world sample code that I am using to plot
|
200
|
+
|
201
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
202
|
+
require 'rotor'
|
203
|
+
begin
|
204
|
+
stepper_x = Rotor::Stepper.new(23,12,17,24,nil,13,0,157.48)
|
205
|
+
stepper_y = Rotor::Stepper.new(25, 4,21,22,nil,19,0,157.48)
|
206
|
+
servo = Rotor::Servo.new(18)
|
207
|
+
|
208
|
+
stepper_x.set_home(:backwards)
|
209
|
+
stepper_y.set_home(:backwards)
|
210
|
+
|
211
|
+
#My threaded rods move 1 inch per 4000 steps (Stepper Motor has 200 steps/rev and the rod has 20 threads per inch)
|
212
|
+
|
213
|
+
stepper_x.forward(1,40)
|
214
|
+
stepper_y.forward(1,40)
|
215
|
+
|
216
|
+
gcode = Rotor::Gcode.new(stepper_x,stepper_y,nil,1,servo)
|
217
|
+
gcode.open('output.nc')
|
218
|
+
gcode.simulate(accuracy=8,speed=5)
|
219
|
+
|
220
|
+
ensure
|
221
|
+
servo.rotate(:up)
|
222
|
+
|
223
|
+
stepper_x.set_home(:backwards)
|
224
|
+
stepper_y.set_home(:backwards)
|
225
|
+
stepper_x.forward(1,4000)
|
226
|
+
stepper_y.forward(1,4000)
|
227
|
+
|
228
|
+
stepper_x.power_down
|
229
|
+
stepper_y.power_down
|
230
|
+
|
231
|
+
[23,12,17,24,13,25,4,21,22,19,13].each do |pin|
|
232
|
+
`echo #{pin} > /sys/class/gpio/unexport`
|
233
|
+
end
|
234
|
+
end
|
235
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
236
|
+
|
237
|
+
Based on the code above, my origin (0,0) is one inch from the backwards X and
|
238
|
+
one inch from the backwards Y
|
239
|
+
|
240
|
+
Development (Exporting Plot Points for Graphing)
|
241
|
+
------------------------------------------------
|
242
|
+
|
243
|
+
Before wasting more materials, I try to plot my points to a file and view them
|
244
|
+
in Excel. Within the root of this repository, there is an Excel file, called
|
245
|
+
Visual.xlsx, and you can import the output.txt into the first four columns. By
|
246
|
+
doing so, you can see the plot points and the scatter of movements. Go to the
|
247
|
+
data tab and click Refresh Data. Select the output.txt file that you generated
|
248
|
+
and it will show the plot points. If you see some crazy stray points, you can
|
249
|
+
put in a issue and I will look at it. Please include the GCode that you’re using
|
250
|
+
that is causing problems.
|
191
251
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
gcode.simulate
|
252
|
+
Keep in mind that this keeps track of the coordinates, so you will see the entry
|
253
|
+
and exit points as lines. This is expected behavior since I like to see where my
|
254
|
+
marker is entering into an object.
|
196
255
|
|
197
|
-
|
256
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
257
|
+
File.open("output.txt", 'wb') { |file| file.write("x,y,xm,ym\n") }
|
258
|
+
gcode = Rotor::Gcode.new(nil,nil,nil,1,nil)
|
259
|
+
gcode.open('output.nc')
|
260
|
+
gcode.simulate
|
261
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
262
|
+
|
263
|
+
License
|
264
|
+
=======
|
198
265
|
|
199
266
|
Copyright (c) 2015 kobaltz
|
200
267
|
|
201
268
|
MIT License
|
202
269
|
|
203
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
220
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
270
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
271
|
+
this software and associated documentation files (the "Software"), to deal in
|
272
|
+
the Software without restriction, including without limitation the rights to
|
273
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
274
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
275
|
+
subject to the following conditions:
|
276
|
+
|
277
|
+
The above copyright notice and this permission notice shall be included in all
|
278
|
+
copies or substantial portions of the Software.
|
279
|
+
|
280
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
281
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
282
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
283
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
284
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
285
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/rotor/gcode.rb
CHANGED
@@ -12,19 +12,14 @@ module Rotor
|
|
12
12
|
@file = File.open(file)
|
13
13
|
end
|
14
14
|
|
15
|
-
def simulate
|
15
|
+
def simulate(accuracy=8,speed=1)
|
16
16
|
@x = 0
|
17
17
|
@y = 0
|
18
18
|
@z = 0
|
19
19
|
|
20
20
|
line_num = 0
|
21
|
-
last_parsed_line = nil
|
22
21
|
|
23
22
|
@file.each_line do |line|
|
24
|
-
# puts "last_parsed_line::#{last_parsed_line}"
|
25
|
-
# line = line.gsub("J-0.000000","J-0.000001") if last_parsed_line && last_parsed_line[:j] && last_parsed_line[:j] > 0.0
|
26
|
-
# line = line.gsub("J-0.000000","J0.000001") if last_parsed_line && last_parsed_line[:j] && last_parsed_line[:j] < 0.0
|
27
|
-
|
28
23
|
parsed_line = parse_line(line)
|
29
24
|
|
30
25
|
line_num += 1
|
@@ -34,29 +29,32 @@ module Rotor
|
|
34
29
|
if parsed_line[:z] && parsed_line[:f] && parsed_line[:x].nil? && parsed_line[:y].nil?
|
35
30
|
puts "Lowering marker"
|
36
31
|
@servo.rotate(:down) if @servo
|
32
|
+
@stepper_z.forward(5,25) if @stepper_z
|
37
33
|
elsif parsed_line[:z] && parsed_line[:f].nil? && parsed_line[:x].nil? && parsed_line[:y].nil?
|
38
34
|
puts "Raising marker::#{parsed_line}"
|
35
|
+
@stepper_z.backwards(5,25) if @stepper_z
|
39
36
|
@servo.rotate(:up) if @servo
|
40
37
|
else
|
41
38
|
puts "Move Stepper::#{parsed_line}"
|
42
|
-
move_stepper(parsed_line,
|
39
|
+
move_stepper(parsed_line,speed)
|
43
40
|
end
|
44
41
|
elsif parsed_line[:g] == 1
|
45
42
|
if parsed_line[:z] && parsed_line[:f] && parsed_line[:x].nil? && parsed_line[:y].nil?
|
46
43
|
puts "Lowering marker"
|
47
44
|
@servo.rotate(:down) if @servo
|
45
|
+
@stepper_z.forward(5,25) if @stepper_z
|
48
46
|
elsif parsed_line[:z] && parsed_line[:f].nil? && parsed_line[:x].nil? && parsed_line[:y].nil?
|
49
47
|
puts "Raising marker::#{parsed_line}"
|
48
|
+
@stepper_z.backwards(5,25) if @stepper_z
|
50
49
|
@servo.rotate(:up) if @servo
|
51
50
|
elsif parsed_line[:z].nil? && parsed_line[:f] && parsed_line[:x].nil? && parsed_line[:y].nil?
|
52
51
|
# Set feed/spin rate
|
53
52
|
else
|
54
53
|
puts "Move Stepper::#{parsed_line}"
|
55
|
-
move_stepper(parsed_line,
|
54
|
+
move_stepper(parsed_line,speed)
|
56
55
|
end
|
57
56
|
elsif parsed_line[:g] == 2 || parsed_line[:g] == 3
|
58
57
|
# Get my ARC on
|
59
|
-
# puts "DEBUG::#{parsed_line}"
|
60
58
|
ignore = false
|
61
59
|
|
62
60
|
x_start = @x
|
@@ -67,11 +65,7 @@ module Rotor
|
|
67
65
|
|
68
66
|
if parsed_line[:i] && parsed_line[:j] && parsed_line[:r].nil?
|
69
67
|
x_offset = parsed_line[:i]
|
70
|
-
# x_offset = 0.0001 if x_offset == 0.0
|
71
|
-
# x_offset = -0.0001 if x_offset == -0.0
|
72
68
|
y_offset = parsed_line[:j]
|
73
|
-
# y_offset = 0.0001 if y_offset == 0.0
|
74
|
-
# y_offset = -0.0001 if y_offset == -0.0
|
75
69
|
|
76
70
|
x_origin = x_offset + x_start
|
77
71
|
y_origin = y_offset + y_start
|
@@ -84,7 +78,7 @@ module Rotor
|
|
84
78
|
|
85
79
|
unless ignore
|
86
80
|
distance = Math.sqrt((x_start - x_end) ** 2 + (y_start - y_end) ** 2)
|
87
|
-
number_of_precision = [distance.to_i,
|
81
|
+
number_of_precision = [distance.to_i,8].max
|
88
82
|
start_angle = Math.atan2((y_start - y_origin),(x_start - x_origin))
|
89
83
|
end_angle = Math.atan2((y_end - y_origin),(x_end - x_origin))
|
90
84
|
|
@@ -108,7 +102,7 @@ module Rotor
|
|
108
102
|
arc_line[:y] = radius * Math.sin(current_degrees) + y_origin
|
109
103
|
arc_line[:z] = nil
|
110
104
|
puts "Move Arc Stepper (#{line_num})::#{arc_line}::#{start_angle},#{end_angle}"
|
111
|
-
move_stepper(arc_line,
|
105
|
+
move_stepper(arc_line,speed)
|
112
106
|
end unless ignore
|
113
107
|
|
114
108
|
else
|
@@ -130,7 +124,6 @@ module Rotor
|
|
130
124
|
# puts "Something else"
|
131
125
|
puts "DEBUG::????? - Something else::#{parsed_line}"
|
132
126
|
end
|
133
|
-
last_parsed_line = parsed_line
|
134
127
|
end
|
135
128
|
end
|
136
129
|
|
@@ -197,7 +190,7 @@ module Rotor
|
|
197
190
|
end
|
198
191
|
@z = @z_move
|
199
192
|
end
|
200
|
-
|
193
|
+
puts "Moving to G#{parsed_line[:g]} #{@x_move}(#{@x_movement}), #{@y_move}(#{@y_movement}), #{@z_move}(#{@z_movement})"
|
201
194
|
threads.each { |thr| thr.join }
|
202
195
|
File.open("output.txt", 'a') { |file| file.write("#{@x_move},#{@y_move},#{@x_movement},#{@y_movement}\n") } if File.exists?("output.txt")
|
203
196
|
end
|
data/lib/rotor/stepper.rb
CHANGED
@@ -61,8 +61,8 @@ module Rotor
|
|
61
61
|
puts "Setting #{direction} with Homing on GPIO #{@homing_switch}"
|
62
62
|
@move = true
|
63
63
|
while @move == true
|
64
|
-
backwards(1,
|
65
|
-
forward(1,
|
64
|
+
backwards(1,1) if direction == :backwards && @io.read(@homing_switch) == @homing_normally
|
65
|
+
forward(1,1) if direction == :forward && @io.read(@homing_switch) == @homing_normally
|
66
66
|
@move = false unless @io.read(@homing_switch) == @homing_normally
|
67
67
|
end
|
68
68
|
end
|
data/lib/rotor/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rotor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kobaltz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -59,15 +59,12 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
- ".DS_Store"
|
63
62
|
- ".gitignore"
|
64
63
|
- Gemfile
|
65
64
|
- LICENSE.txt
|
66
65
|
- README.md
|
67
66
|
- Rakefile
|
68
|
-
- lib/.DS_Store
|
69
67
|
- lib/rotor.rb
|
70
|
-
- lib/rotor/.DS_Store
|
71
68
|
- lib/rotor/gcode.rb
|
72
69
|
- lib/rotor/servo.rb
|
73
70
|
- lib/rotor/stepper.rb
|
data/.DS_Store
DELETED
Binary file
|
data/lib/.DS_Store
DELETED
Binary file
|
data/lib/rotor/.DS_Store
DELETED
Binary file
|