rotor 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62d8ac2a05984d3d5d1db744a7dec78f88003e98
4
- data.tar.gz: 98c73074be6a11b631df7351c4add650bb05d447
3
+ metadata.gz: 055300c3ef4b8bee15608cdd8db5346ef80ca1be
4
+ data.tar.gz: f83b5630dbff6e8b5913c8d4ff5adc4d7f5b1efe
5
5
  SHA512:
6
- metadata.gz: 4c037e8f5cf5f319e20fcd8f317f0cf363617e187c09b7af23a3b564476d70017930ecc87e371a9d80a30237df5ec24d4dc540a5c266578d8a4ecff70d8ad0e1
7
- data.tar.gz: bcf1702711ce5959aff917e5cf1562fc8cdc5ff262a2be2998325488bd06cbef1e43e2f2a2627af63977ae869788c833f83f67058f881d6324fabb36e82ca161
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
- ## Class Servo
56
+ ## Class Servo
57
57
 
58
58
  servo = Rotor::Servo.new(pin=18)
59
59
  servo.rotate(direction) # :up or :down
60
60
 
61
- ## Class GCode
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
- ## Production (Moving Stepper and Servo)
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
- ## Development (Exporting Plot Points for Graphing)
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,10)
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
- x_offset = parsed_line[:i]
67
- x_offset = 0.0001 if x_offset == 0.0
68
- x_offset = -0.0001 if x_offset == -0.0
69
- y_offset = parsed_line[:j]
70
- y_offset = 0.0001 if y_offset == 0.0
71
- y_offset = -0.0001 if y_offset == -0.0
72
-
73
- x_origin = x_offset + x_start
74
- y_origin = y_offset + y_start
75
-
76
- radius = Math.sqrt((x_start - x_origin) ** 2 + (y_start - y_origin) ** 2)
77
-
78
- start_angle = Math.atan2((y_start - y_origin),(x_start - x_origin))
79
- end_angle = Math.atan2((y_end - y_origin),(x_end - x_origin))
80
-
81
- number_of_precision = 5
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
- current_degrees = start_angle
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
- # unless i == (number_of_precision - 1)
89
- current_degrees += steps
90
- arc_line = {}
91
- arc_line[:g] = parsed_line[:g]
92
- arc_line[:x] = radius * Math.cos(current_degrees) + x_origin
93
- arc_line[:y] = radius * Math.sin(current_degrees) + y_origin
94
- arc_line[:z] = nil
95
- puts "Move Arc Stepper (#{line_num})::#{arc_line},#{current_degrees}::#{y_offset}"
96
- move_stepper(arc_line,10)
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 > @x #move to the right
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 < @x #move to the left
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 > @y #move to the right
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 < @y #move to the left
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 > @z #move to the right
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 < @z #move to the left
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,:m,:f]
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,1) if direction == :backwards #&& @io.read(@homing_switch) == @homing_normally
65
- forward(1,1) if direction == :forward #&& @io.read(@homing_switch) == @homing_normally
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
@@ -1,3 +1,3 @@
1
1
  module Rotor
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rotor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - kobaltz