rotor 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -4
- data/lib/rotor/gcode.rb +56 -42
- data/lib/rotor/stepper.rb +2 -2
- data/lib/rotor/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 055300c3ef4b8bee15608cdd8db5346ef80ca1be
|
4
|
+
data.tar.gz: f83b5630dbff6e8b5913c8d4ff5adc4d7f5b1efe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db3770db1d43f03fc0026addb7c0642b5e962bce74fb95dc08517bec68e36e1ad28a83a1f6468b74178d53c7dc8e4e689c7b397756a3f6dab3e538f29a56aa85
|
7
|
+
data.tar.gz: 2620dbb8c796e25ab0a155a1e74d42c6ab49f873e588a12adadf4ef823b15fe1b28ebc8bf49a01c6fc9ddcbedfb111d10fb2db7f212ddeae0c57706b19478ad9
|
data/README.md
CHANGED
@@ -53,12 +53,14 @@ or ULN2800 Integrated Controllers.
|
|
53
53
|
|
54
54
|
stepper.power_down
|
55
55
|
|
56
|
-
|
56
|
+
## Class Servo
|
57
57
|
|
58
58
|
servo = Rotor::Servo.new(pin=18)
|
59
59
|
servo.rotate(direction) # :up or :down
|
60
60
|
|
61
|
-
|
61
|
+
## Class GCode
|
62
|
+
|
63
|
+
There was a bug when calculating the start and end angles. This has been fixed.
|
62
64
|
|
63
65
|
The plot points are streamed to output.txt file on your computer.
|
64
66
|
|
@@ -145,7 +147,7 @@ keep this at 1).
|
|
145
147
|
|
146
148
|
# Sample Code
|
147
149
|
|
148
|
-
|
150
|
+
## Production (Moving Stepper and Servo)
|
149
151
|
|
150
152
|
Here is the real world sample code that I am using to plot
|
151
153
|
|
@@ -180,7 +182,7 @@ keep this at 1).
|
|
180
182
|
end
|
181
183
|
end
|
182
184
|
|
183
|
-
|
185
|
+
## Development (Exporting Plot Points for Graphing)
|
184
186
|
|
185
187
|
Before wasting more materials, I try to plot my points to a file and view them in Excel.
|
186
188
|
Within the root of this repository, there is an Excel file, called Visual.xlsx, and
|
data/lib/rotor/gcode.rb
CHANGED
@@ -21,9 +21,9 @@ module Rotor
|
|
21
21
|
last_parsed_line = nil
|
22
22
|
|
23
23
|
@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
|
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
27
|
|
28
28
|
parsed_line = parse_line(line)
|
29
29
|
|
@@ -52,50 +52,64 @@ module Rotor
|
|
52
52
|
# Set feed/spin rate
|
53
53
|
else
|
54
54
|
puts "Move Stepper::#{parsed_line}"
|
55
|
-
move_stepper(parsed_line,
|
55
|
+
move_stepper(parsed_line,1)
|
56
56
|
end
|
57
57
|
elsif parsed_line[:g] == 2 || parsed_line[:g] == 3
|
58
58
|
# Get my ARC on
|
59
59
|
# puts "DEBUG::#{parsed_line}"
|
60
|
+
ignore = false
|
61
|
+
|
60
62
|
x_start = @x
|
61
63
|
x_end = parsed_line[:x]
|
62
64
|
|
63
65
|
y_start = @y
|
64
66
|
y_end = parsed_line[:y]
|
65
67
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
steps = (end_angle - start_angle) / number_of_precision
|
68
|
+
if parsed_line[:i] && parsed_line[:j] && parsed_line[:r].nil?
|
69
|
+
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
|
+
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
|
+
|
76
|
+
x_origin = x_offset + x_start
|
77
|
+
y_origin = y_offset + y_start
|
78
|
+
|
79
|
+
radius = Math.sqrt((x_start - x_origin) ** 2 + (y_start - y_origin) ** 2)
|
80
|
+
|
81
|
+
elsif parsed_line[:i].nil? && parsed_line[:j].nil? && parsed_line[:r]
|
82
|
+
ignore = true
|
83
|
+
end
|
84
84
|
|
85
|
-
|
85
|
+
unless ignore
|
86
|
+
distance = Math.sqrt((x_start - x_end) ** 2 + (y_start - y_end) ** 2)
|
87
|
+
number_of_precision = [distance.to_i,4].max
|
88
|
+
start_angle = Math.atan2((y_start - y_origin),(x_start - x_origin))
|
89
|
+
end_angle = Math.atan2((y_end - y_origin),(x_end - x_origin))
|
90
|
+
|
91
|
+
if start_angle - end_angle > Math::PI
|
92
|
+
end_angle += Math::PI * 2
|
93
|
+
# puts "Move Arc Stepper (#{line_num})::Insert Fix"
|
94
|
+
elsif start_angle - end_angle < -Math::PI
|
95
|
+
end_angle *= -1
|
96
|
+
# puts "Move Arc Stepper (#{line_num})::Insert Fix 2"
|
97
|
+
end
|
98
|
+
|
99
|
+
steps = (end_angle - start_angle) / number_of_precision
|
100
|
+
current_degrees = start_angle
|
101
|
+
end
|
86
102
|
|
87
103
|
number_of_precision.times do |i|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
# end
|
98
|
-
end
|
104
|
+
current_degrees += steps
|
105
|
+
arc_line = {}
|
106
|
+
arc_line[:g] = parsed_line[:g]
|
107
|
+
arc_line[:x] = radius * Math.cos(current_degrees) + x_origin
|
108
|
+
arc_line[:y] = radius * Math.sin(current_degrees) + y_origin
|
109
|
+
arc_line[:z] = nil
|
110
|
+
puts "Move Arc Stepper (#{line_num})::#{arc_line}::#{start_angle},#{end_angle}"
|
111
|
+
move_stepper(arc_line,1)
|
112
|
+
end unless ignore
|
99
113
|
|
100
114
|
else
|
101
115
|
# puts "GLINE - Something else"
|
@@ -132,11 +146,11 @@ module Rotor
|
|
132
146
|
|
133
147
|
@x_movement = (@x_move - @x).abs
|
134
148
|
|
135
|
-
if @x_move.to_f
|
149
|
+
if @x_move.to_f < @x #move to the right
|
136
150
|
if @stepper_x # && @stepper_x.at_safe_area?
|
137
151
|
threads << Thread.new { @stepper_x.forward(delay, @x_movement) }
|
138
152
|
end
|
139
|
-
elsif @x_move.to_f
|
153
|
+
elsif @x_move.to_f > @x #move to the left
|
140
154
|
if @stepper_x # && @stepper_x.at_safe_area?
|
141
155
|
threads << Thread.new { @stepper_x.backwards(delay, @x_movement) }
|
142
156
|
end
|
@@ -152,11 +166,11 @@ module Rotor
|
|
152
166
|
|
153
167
|
@y_movement = (@y_move - @y).abs
|
154
168
|
|
155
|
-
if @y_move.to_f
|
169
|
+
if @y_move.to_f < @y #move to the right
|
156
170
|
if @stepper_y # && @stepper_y.at_safe_area?
|
157
171
|
threads << Thread.new { @stepper_y.forward(delay, @y_movement) }
|
158
172
|
end
|
159
|
-
elsif @y_move.to_f
|
173
|
+
elsif @y_move.to_f > @y #move to the left
|
160
174
|
if @stepper_y # && @stepper_y.at_safe_area?
|
161
175
|
threads << Thread.new { @stepper_y.backwards(delay, @y_movement) }
|
162
176
|
end
|
@@ -172,11 +186,11 @@ module Rotor
|
|
172
186
|
|
173
187
|
@z_movement = (@z_move - @z).abs
|
174
188
|
|
175
|
-
if @z_move.to_f
|
189
|
+
if @z_move.to_f < @z #move to the right
|
176
190
|
if @stepper_z # && @stepper_z.at_safe_area?
|
177
191
|
threads << Thread.new { @stepper_z.forward(delay, @z_movement) }
|
178
192
|
end
|
179
|
-
elsif @z_move.to_f
|
193
|
+
elsif @z_move.to_f > @z #move to the left
|
180
194
|
if @stepper_z # && @stepper_z.at_safe_area?
|
181
195
|
threads << Thread.new { @stepper_z.backwards(delay, @z_movement) }
|
182
196
|
end
|
@@ -190,7 +204,7 @@ module Rotor
|
|
190
204
|
|
191
205
|
def parse_line(line)
|
192
206
|
returned_json = {}
|
193
|
-
values = [:g,:x,:y,:z,:i,:j,:k
|
207
|
+
values = [:g,:x,:y,:z,:i,:j,:k, :r, :m,:f]
|
194
208
|
values.each do |element|
|
195
209
|
returned_json[element] = find_value(element,line)
|
196
210
|
end
|
@@ -208,7 +222,7 @@ module Rotor
|
|
208
222
|
case element
|
209
223
|
when :g, :m
|
210
224
|
return data[:data].to_i
|
211
|
-
when :x,:y,:z,:i,:j,:k,:f
|
225
|
+
when :x,:y,:z,:i,:j,:k,:r,:f
|
212
226
|
return data[:data].to_f
|
213
227
|
end
|
214
228
|
else
|
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,158) if direction == :backwards #&& @io.read(@homing_switch) == @homing_normally
|
65
|
+
forward(1,158) 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