rintcore 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rint_core/cli.rb +2 -1
- data/lib/rint_core/g_code/line.rb +10 -1
- data/lib/rint_core/g_code/object.rb +63 -7
- data/lib/rint_core/pretty_output.rb +17 -0
- data/lib/rint_core/printer.rb +3 -7
- data/lib/rint_core/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a20bcac1c2747c6d8933b54fa95ee260d9f73320
|
4
|
+
data.tar.gz: 71914f9bc5e24cfad1d202efa716fb73b91313aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d55c42be03827ff1a1372906335a7285149b59ce34dee145c525cc183c3f7343b4796ea0826719674116ffb9fb5bfe6b0526575e5c5dc42588cdf28197355f5a
|
7
|
+
data.tar.gz: 191454c20c3e97d2c47615736d647e5e76f5996ce92fcd8ebaf3a3e01b33151bdbfdd0168b80047f9b995ee703e3b0764e6548f935952fa18d2588515cf3cfe3
|
data/lib/rint_core/cli.rb
CHANGED
@@ -41,7 +41,8 @@ module RintCore
|
|
41
41
|
@object.filament_used.each_with_index do |filament,extruder|
|
42
42
|
puts "\tExtruder #{extruder+1}: #{filament.round(decimals)}mm"
|
43
43
|
end
|
44
|
-
puts "
|
44
|
+
puts "\nNumber of layers: #{@object.layers}\n\n"\
|
45
|
+
"Estimated duration: #{@object.durration_in_words}\n\n"\
|
45
46
|
"#{@object.raw_data.length} lines / #{@object.lines.length} commands"
|
46
47
|
end
|
47
48
|
|
@@ -60,8 +60,17 @@ module RintCore
|
|
60
60
|
# @!attribute [r] $12
|
61
61
|
# @return [nil] if there's no E parameter of the command.
|
62
62
|
# @return [Float] E parameter of the command.
|
63
|
+
# @!attribute [r] $12
|
64
|
+
# @return [nil] if there's no S parameter of the command.
|
65
|
+
# @return [Fixnum] S parameter of the command.
|
66
|
+
# @!attribute [r] $13
|
67
|
+
# @return [nil] if there's no P parameter of the command.
|
68
|
+
# @return [Fixnum] P parameter of the command.
|
69
|
+
# @!attribute [r] $14
|
70
|
+
# @return [nil] if there's no string dta for the command.
|
71
|
+
# @return [Fixnum] extra string data for the command (ex. "filename.gco" in "M23 filename.gco").
|
63
72
|
attr_reader :raw, :matches, :line, :command, :command_letter, :command_number,
|
64
|
-
:s_data, :p_data, :x, :y, :z, :e
|
73
|
+
:s_data, :p_data, :x, :y, :z, :e, :s, :p, :string_data
|
65
74
|
|
66
75
|
# Creates a {Line}
|
67
76
|
# @param line [String] a line of GCode.
|
@@ -1,11 +1,13 @@
|
|
1
1
|
require 'rint_core/g_code/codes'
|
2
2
|
require 'rint_core/g_code/line'
|
3
|
+
require 'rint_core/pretty_output'
|
3
4
|
|
4
5
|
module RintCore
|
5
6
|
module GCode
|
6
7
|
# A class that represents a processed GCode file.
|
7
8
|
class Object
|
8
9
|
include RintCore::GCode::Codes
|
10
|
+
include RintCore::PrettyOutput
|
9
11
|
|
10
12
|
# An array of the raw Gcode with each line as an element.
|
11
13
|
# @return [Array] of raw GCode without the comments stripped out.
|
@@ -43,25 +45,29 @@ module RintCore
|
|
43
45
|
# @!attribute [r] $15
|
44
46
|
# @return [Float] the height of the print.
|
45
47
|
# @!attribute [r] $16
|
46
|
-
#
|
48
|
+
# @return [Fixnum] the number of layers in the print.
|
49
|
+
# @!attribute [r] $17
|
50
|
+
# @return [Float] the estimated durration of the print in seconds.
|
47
51
|
attr_reader :lines, :x_min, :x_max, :y_min, :y_max, :z_min, :z_max,
|
48
52
|
:filament_used, :x_travel, :y_travel, :z_travel, :e_travel,
|
49
|
-
:width, :depth, :height, :layers
|
53
|
+
:width, :depth, :height, :layers, :total_duration
|
50
54
|
|
51
55
|
# Creates a GCode {Object}.
|
52
56
|
# @param data [String] path to a GCode file on the system.
|
53
57
|
# @param data [Array] with each element being a line of GCode.
|
54
|
-
# @param default_speed [Float] the default speed (in mm/minute) for moves that don't have one declared.
|
55
58
|
# @param auto_process [Boolean] enable/disable auto processing.
|
59
|
+
# @param default_speed [Float] the default speed (in mm/minute) for moves that don't have one declared.
|
60
|
+
# @param acceleration [Float] the acceleration rate set in the printer' firmware.
|
56
61
|
# @return [Object] if data is valid, returns a GCode {Object}.
|
57
62
|
# @return [false] if data is not an array, path, didn't contain GCode or default_speed wasn't a number grater than 0.
|
58
|
-
def initialize(data = nil, default_speed = 2400, auto_process = true)
|
59
|
-
return false if
|
63
|
+
def initialize(data = nil, default_speed = 2400, auto_process = true, acceleration = 1500)
|
64
|
+
return false if positive_number?(default_speed)
|
65
|
+
return false if positive_number?(acceleration)
|
60
66
|
if data.class == String && self.class.is_file?(data)
|
61
67
|
data = self.class.get_file(data)
|
62
68
|
end
|
63
69
|
return false if data.nil? || data.class != Array
|
64
|
-
set_variables(data, default_speed)
|
70
|
+
set_variables(data, default_speed, acceleration)
|
65
71
|
data.each do |line|
|
66
72
|
line = RintCore::GCode::Line.new(line)
|
67
73
|
@lines << set_line_properties(line) if line && !line.command.nil?
|
@@ -112,6 +118,12 @@ module RintCore
|
|
112
118
|
@filament_used.length > 1
|
113
119
|
end
|
114
120
|
|
121
|
+
# Returns estimated durration of the print in a human readable format.
|
122
|
+
# @return [String] human readable estimated durration of the print.
|
123
|
+
def durration_in_words
|
124
|
+
seconds_to_words(@total_duration)
|
125
|
+
end
|
126
|
+
|
115
127
|
private
|
116
128
|
|
117
129
|
def process
|
@@ -136,6 +148,9 @@ private
|
|
136
148
|
when CONTROLLED_MOVE
|
137
149
|
count_layers(line)
|
138
150
|
movement_line(line)
|
151
|
+
calculate_time(line)
|
152
|
+
when DWELL
|
153
|
+
@total_duration += line.p/1000 unless line.p.nil?
|
139
154
|
end
|
140
155
|
end
|
141
156
|
|
@@ -148,14 +163,33 @@ private
|
|
148
163
|
@height = @z_max - @z_min
|
149
164
|
end
|
150
165
|
|
166
|
+
def calculate_time(line)
|
167
|
+
@speed_per_second = line.f / 60
|
168
|
+
current_travel = hypot3d(@current_x, @current_y, @current_z, @last_x, @last_y, @last_z)
|
169
|
+
distance = (2*((@last_speed_per_second+@speed_per_second)*(@speed_per_second-@last_speed_per_second)*0.5)/@acceleration).abs
|
170
|
+
if distance <= current_travel && !(@last_speed_per_second+@speed_per_second).zero? && !@speed_per_second.zero?
|
171
|
+
move_duration = 2*distance/(@last_speed_per_second+@speed_per_second)
|
172
|
+
current_travel -= distance
|
173
|
+
move_duration += current_travel/@speed_per_second
|
174
|
+
else
|
175
|
+
move_duration = Math.sqrt(2*distance/@acceleration)
|
176
|
+
end
|
177
|
+
@total_duration += move_duration
|
178
|
+
end
|
179
|
+
|
151
180
|
def count_layers(line)
|
152
181
|
if !line.z.nil? && line.z > @current_z
|
153
182
|
@layers += 1
|
154
183
|
end
|
155
184
|
end
|
156
185
|
|
186
|
+
def hypot3d(x1, y1, z1, x2 = 0.0, y2 = 0.0, z2 = 0.0)
|
187
|
+
return Math.hypot(x2-x1, Math.hypot(y2-y1, z2-z1))
|
188
|
+
end
|
189
|
+
|
157
190
|
def movement_line(line)
|
158
191
|
measure_travel(line)
|
192
|
+
set_last_values
|
159
193
|
set_current_position(line)
|
160
194
|
set_limits(line)
|
161
195
|
end
|
@@ -187,6 +221,17 @@ private
|
|
187
221
|
end
|
188
222
|
end
|
189
223
|
|
224
|
+
def positive_number?(number, grater_than = 0)
|
225
|
+
number.nil? && (number.is_a?(Fixnum) || number.is_a?(Float)) && number >= grater_than
|
226
|
+
end
|
227
|
+
|
228
|
+
def set_last_values
|
229
|
+
@last_x = @current_x
|
230
|
+
@last_y = @current_y
|
231
|
+
@last_z = @current_z
|
232
|
+
@last_speed_per_second = @speed_per_second
|
233
|
+
end
|
234
|
+
|
190
235
|
def set_positions(line)
|
191
236
|
@current_x = to_mm(line.x) unless line.x.nil?
|
192
237
|
@current_y = to_mm(line.y) unless line.y.nil?
|
@@ -245,6 +290,10 @@ private
|
|
245
290
|
@current_y = 0
|
246
291
|
@current_z = 0
|
247
292
|
@current_e = 0
|
293
|
+
@last_x = 0
|
294
|
+
@last_y = 0
|
295
|
+
@last_z = 0
|
296
|
+
@last_e = 0
|
248
297
|
@x_min = 999999999
|
249
298
|
@y_min = 999999999
|
250
299
|
@z_min = 0
|
@@ -253,14 +302,21 @@ private
|
|
253
302
|
@z_max = -999999999
|
254
303
|
@filament_used = []
|
255
304
|
@layers = 0
|
305
|
+
# Time
|
306
|
+
@speed_per_second = 0.0
|
307
|
+
@last_speed_per_second = 0.0
|
308
|
+
@move_duration = 0.0
|
309
|
+
@total_duration = 0.0
|
310
|
+
@acceleration = 1500.0 #mm/s/s ASSUMING THE DEFAULT FROM SPRINTER !!!!
|
256
311
|
end
|
257
312
|
|
258
|
-
def set_variables(data, default_speed)
|
313
|
+
def set_variables(data, default_speed, acceleration)
|
259
314
|
@raw_data = data
|
260
315
|
@imperial = false
|
261
316
|
@relative = false
|
262
317
|
@tool_number = 0
|
263
318
|
@speed = default_speed.to_f
|
319
|
+
@acceleration = acceleration
|
264
320
|
@lines = []
|
265
321
|
end
|
266
322
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module RintCore
|
2
|
+
# provides methods to make human readable output.
|
3
|
+
module PrettyOutput
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
def seconds_to_words(seconds)
|
8
|
+
[[60, :seconds], [60, :minutes], [24, :hours], [1000, :days]].map{ |count, name|
|
9
|
+
if seconds > 0
|
10
|
+
seconds, n = seconds.divmod(count)
|
11
|
+
"#{n.to_i} #{name}"
|
12
|
+
end
|
13
|
+
}.compact.reverse.join(' ')
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
data/lib/rint_core/printer.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
require 'rint_core/driver'
|
2
2
|
require 'active_support/configurable'
|
3
|
+
require 'rint_core/pretty_output'
|
3
4
|
|
4
5
|
module RintCore
|
5
6
|
# Interface for directly intereacting with the printer.
|
6
7
|
class Printer
|
7
8
|
include RintCore::Driver
|
9
|
+
include RintCore::PrettyOutput
|
8
10
|
include ActiveSupport::Configurable
|
9
11
|
|
10
12
|
# @!macro config_accessor
|
@@ -94,13 +96,7 @@ module RintCore
|
|
94
96
|
# @return [String] human readable time since print started, or "0 seconds" if not printing.
|
95
97
|
def time_from_start
|
96
98
|
@start_time = Time.now unless printing?
|
97
|
-
|
98
|
-
[[60, :seconds], [60, :minutes], [24, :hours], [1000, :days]].map{ |count, name|
|
99
|
-
if secs > 0
|
100
|
-
secs, n = secs.divmod(count)
|
101
|
-
"#{n.to_i} #{name}"
|
102
|
-
end
|
103
|
-
}.compact.reverse.join(' ')
|
99
|
+
seconds_to_words(Time.now-@start_time)
|
104
100
|
end
|
105
101
|
|
106
102
|
class << self
|
data/lib/rint_core/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rintcore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kaz Walker
|
@@ -107,6 +107,7 @@ files:
|
|
107
107
|
- lib/rint_core/g_code/codes.rb
|
108
108
|
- lib/rint_core/g_code/line.rb
|
109
109
|
- lib/rint_core/g_code/object.rb
|
110
|
+
- lib/rint_core/pretty_output.rb
|
110
111
|
- lib/rint_core/printer.rb
|
111
112
|
- lib/rint_core/version.rb
|
112
113
|
- rintcore.gemspec
|