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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 055300c3ef4b8bee15608cdd8db5346ef80ca1be
4
- data.tar.gz: f83b5630dbff6e8b5913c8d4ff5adc4d7f5b1efe
3
+ metadata.gz: 4e48e610c2097d68d9a98bbf70151730a9957875
4
+ data.tar.gz: be5914357afb26ab29806eb649f1f00196fa8267
5
5
  SHA512:
6
- metadata.gz: db3770db1d43f03fc0026addb7c0642b5e962bce74fb95dc08517bec68e36e1ad28a83a1f6468b74178d53c7dc8e4e689c7b397756a3f6dab3e538f29a56aa85
7
- data.tar.gz: 2620dbb8c796e25ab0a155a1e74d42c6ab49f873e588a12adadf4ef823b15fe1b28ebc8bf49a01c6fc9ddcbedfb111d10fb2db7f212ddeae0c57706b19478ad9
6
+ metadata.gz: c35be0d4fbde64f072d1405913058437be150c37842f42afbd24a50df9f4258089d23c9801d6d877cfa1c95e02a375db2f2feaa67da2716a5f889910ba9a69e5
7
+ data.tar.gz: e00420f6330260ee0bf2f5ec49e0e84d60fc8ea78457610ae0cc7536f38bab87e087a12982822ea5b2532d9f3928879937df20b2658980d4d94351e4a8ce9916
data/.gitignore CHANGED
@@ -12,4 +12,5 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
- *.gem
15
+ *.gem
16
+ .DS_Store
data/README.md CHANGED
@@ -1,220 +1,285 @@
1
- # Rotor (Ruby Motor)
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
- can use this gem to run both Bipolar and Unipolar motors with either L293D
7
- or ULN2800 Integrated Controllers.
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
- ## Installation
10
+ Installation
11
+ ------------
10
12
 
11
- Make sure that you have WiringPi installed first
13
+ ### WiringPi
12
14
 
13
- gem install wiringpi
15
+ Make sure that you have WiringPi installed first
14
16
 
15
- If you are using GPIO Pins from a A+/B+, you may need to update your
16
- WiringPi libraries. You can pull from my repo https://github.com/kobaltz/WiringPi-Ruby
17
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18
+ gem install wiringpi
19
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17
20
 
18
- I did not write any of the WiringPi-Ruby platform. I simply pulled the latest C libraries
19
- and recompiled the gem.
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
- Install Rotor
25
+ [1]: <https://github.com/kobaltz/WiringPi-Ruby >
22
26
 
23
- gem install rotor
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
- # Notes
30
+ ### Rotor
26
31
 
27
- This gem has been built for my personal project. I do not and cannot know if this will
28
- work with your setup. However, put in an issue if you're having troubles with this gem
29
- and I will try to help you as best as I can.
32
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33
+ gem install rotor
34
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
30
35
 
31
- I am using two stepper motors (NEMA17 Bipolar 20Ncm 12V) and two L293D motor drivers. This
32
- gem has also been tested with a small 5V Unipolar Stepper Motor and 12V Unipolar Stepper Motor.
36
+ Notes
37
+ =====
33
38
 
34
- My Steps Per MM is based on a 200 step per revolution motor and a threaded rod with 20 threads per inch.
35
- This means that I will have to step 4000 times to move the coupler one inch.
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
- # Usage
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
- ## Class Stepper
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
- MAKE SURE THAT YOU HAVE CONFIGURED THE Rotor::Stepper WITH THE CORRECT GPIO PIN NUMBERS. CHECK AND
42
- DOUBLE CHECK THESE BEFORE RUNNING YOUR CODE.
51
+ Usage
52
+ =====
43
53
 
44
- 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)
45
- stepper.forward(delay=5,steps=100) # stepper.forward(1,100)
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
- After running your GCode, you may want to consider to power down the motor by sending a
52
- LOW to each step.
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
- stepper.power_down
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
- ## Class Servo
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
- servo = Rotor::Servo.new(pin=18)
59
- servo.rotate(direction) # :up or :down
73
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
74
+ stepper.power_down
75
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
60
76
 
61
- ## Class GCode
77
+ Class Servo
78
+ -----------
62
79
 
63
- There was a bug when calculating the start and end angles. This has been fixed.
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
- The plot points are streamed to output.txt file on your computer.
86
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
87
+ servo = Rotor::Servo.new(pin=18)# Rotor::Servo.new(18)
88
+ servo.rotate(direction) # :up or :down
89
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
66
90
 
67
- You can test the outputs of your GCODE and the XY plots it creates by Rotor.
91
+ Class GCode
92
+ -----------
68
93
 
69
- File.open("output.txt", 'wb') { |file| file.write("x,y,xm,ym\n") }
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
- The goal of this gem is to make controlling your robotics easier than
75
- other solutions.
96
+ You can test the outputs of your GCODE and the XY plots it creates by Rotor.
76
97
 
77
- Added Homing Switch options where you can add the GPIO of the switch
78
- and indicate if it is normally open or normally closed. I have my homing
79
- switches on each axis configured in parallel since I know the direction
80
- that the panel is moving in and therefore know which side it has hit. This
81
- was to reduce the number of GPIO pins required.
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
- stepper_x = Rotor::Stepper.new(23,12,17,24,nil,13,0,157.48)
84
- stepper_y = Rotor::Stepper.new(25, 4,21,22,nil,19,0,157.48)
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
- You can use a servo to control the marker (or leave blank if you're using a Z Axis Stepper)
87
- This will be built out so that the strength control of the servo (for laser power) can be
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
- servo = Rotor::Servo.new(18)
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
- You can send the stepper motor to the outter edges of the board.
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
- # stepper_x.set_home(:backwards)
96
- # stepper_x.forward(1,100)
97
- # stepper_y.set_home(:forward)
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
- stepper_x = Rotor::Stepper.new(23,12,17,24,nil,13,LOW,157.48)
100
- stepper_y = Rotor::Stepper.new(25, 4,21,22,nil,19,LOW,157.48)
101
-
102
- loop do
103
- puts "Enter steps forward::"
104
- text = gets.chomp
105
-
106
- threads = []
107
- threads << Thread.new { stepper_x.forward(5,text.to_i) }
108
- threads << Thread.new { stepper_y.forward(5,text.to_i) }
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
- Here is the real world sample code that I am using to plot
153
-
154
- require 'rotor'
155
- begin
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
- Before wasting more materials, I try to plot my points to a file and view them in Excel.
188
- Within the root of this repository, there is an Excel file, called Visual.xlsx, and
189
- you can import the output.txt into the first four columns. By doing so, you can see the
190
- plot points and the scatter of movements.
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
- File.open("output.txt", 'wb') { |file| file.write("x,y,xm,ym\n") }
193
- gcode = Rotor::Gcode.new(nil,nil,nil,1,nil)
194
- gcode.open('output.nc')
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
- # License
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
- a copy of this software and associated documentation files (the
205
- "Software"), to deal in the Software without restriction, including
206
- without limitation the rights to use, copy, modify, merge, publish,
207
- distribute, sublicense, and/or sell copies of the Software, and to
208
- permit persons to whom the Software is furnished to do so, subject to
209
- the following conditions:
210
-
211
- The above copyright notice and this permission notice shall be
212
- included in all copies or substantial portions of the Software.
213
-
214
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
215
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
216
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
217
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
218
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
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,1)
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,1)
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,4].max
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,1)
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
- # puts "Moving to G#{parsed_line[:g]} #{@x_move}(#{@x_movement}), #{@y_move}(#{@y_movement}), #{@z_move}(#{@z_movement})"
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,158) if direction == :backwards #&& @io.read(@homing_switch) == @homing_normally
65
- forward(1,158) if direction == :forward #&& @io.read(@homing_switch) == @homing_normally
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
@@ -1,3 +1,3 @@
1
1
  module Rotor
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.5"
3
3
  end
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.2
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-23 00:00:00.000000000 Z
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