rotor 0.0.10 → 0.0.11

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: 749e70524d5cd517fec84abfafd70ea35791a3b6
4
- data.tar.gz: 8f3f7295f4423fedeeb579fb99e1085408f40499
3
+ metadata.gz: ea578664f5569731916a449d5ee2f5999ec2c2ce
4
+ data.tar.gz: 33ff525b796c230b42cd0c07cb63dc1fdcc0f9b2
5
5
  SHA512:
6
- metadata.gz: cf6377a70975b031edac451120b6d7ae201f5acb937481e1ce3f3f8c16c8bc039f74bd901dc68823acb67b09ec24645713c537f1cba8d7973c33a42a5aabb826
7
- data.tar.gz: 473517bc860cff6ebc4f71bcb3c956eb676523725ba7d7bdd26c4bbd4adb19ae3ed03526c306000c92bc7b57f8c244ab359e1c97753b8f116ea2731a0aa3fcf3
6
+ metadata.gz: d795f73d03848701ea4de85154950e946ec1b0f3ab60554d3db58c37e748d2d82bd573c0d0b69928d934e8d451d2494d628c04aecc7ac621e17083ffca43f5a7
7
+ data.tar.gz: 48834b2946c416bfa62ae4b284615df87bd0a79876a71e74677d70e9d7a0b12c72a52e321e409f6c327e5e3f2283cdfb3a3904dc334d371c664626fb52edf59a
data/README.md CHANGED
@@ -21,6 +21,28 @@ or ULN2800 Integrated Controllers.
21
21
  The goal of this gem is to make controlling your robotics easier than
22
22
  other solutions.
23
23
 
24
+ Added Homing Switch options where you can add the GPIO of the switch
25
+ and indicate if it is normally open or normally closed. I have my homing
26
+ switches on each axis configured in parallel since I know the direction
27
+ that the panel is moving in and therefore know which side it has hit. This
28
+ was to reduce the number of GPIO pins required.
29
+
30
+ stepper_x = Rotor::Stepper.new(23,12,17,24,nil,13,LOW)
31
+ stepper_y = Rotor::Stepper.new(25, 4,21,22,nil,19,LOW)
32
+
33
+ You can use a servo to control the marker (or leave blank if you're using a Z Axis Stepper)
34
+ This will be built out so that the strength control of the servo (for laser power) can be
35
+ adjusted and inputs sent in. However, for development purposes, I recommend not playing with
36
+ lasers, but rather get the machine and code working properly first.
37
+
38
+ servo = Rotor::Servo.new(18)
39
+
40
+ You can send the stepper motor to the outter edges of the board.
41
+
42
+ # stepper_x.set_home(:backwards)
43
+ # stepper_x.forward(1,100)
44
+ # stepper_y.set_home(:forward)
45
+
24
46
  stepper_x = Rotor::Stepper.new(4,17,23,24,18)
25
47
  stepper_y = Rotor::Stepper.new(25,12,16,21,18)
26
48
 
@@ -40,6 +62,21 @@ or ULN2800 Integrated Controllers.
40
62
  stepper_y.backwards(5,text.to_i)
41
63
  end
42
64
 
65
+ # GCode Simulation
66
+
67
+ GCode can be simulated (this is my latest part of the project) where
68
+ a file can be read in and the movements interpreted. I'm still working
69
+ on the ARC movement on G02 and G03, but have gotten G0 and G1 working.
70
+
71
+ Enter each stepper motor (or nil if you do not have that particular axis)
72
+ along with the scale (multiplies all coordinates by this. Typically you will
73
+ keep this at 1).
74
+
75
+ #gcode = Rotor::Gcode.new(stepper_x,stepper_y,stepper_z,1,servo)
76
+ gcode = Rotor::Gcode.new(nil,nil,nil,1,nil)
77
+ gcode.open('sample.nc')
78
+ gcode.simulate
79
+
43
80
  # Asynchronous Movement
44
81
 
45
82
  By default, if you run the first motor and then the second motor commands,
data/lib/rotor/.DS_Store CHANGED
Binary file
data/lib/rotor/gcode.rb CHANGED
@@ -1,8 +1,11 @@
1
1
  module Rotor
2
2
  class Gcode
3
- def initialize(stepper_x=nil,stepper_y=nil)
3
+ def initialize(stepper_x=nil,stepper_y=nil,stepper_z=nil,scale=1,servo=nil)
4
4
  @stepper_x = stepper_x
5
5
  @stepper_y = stepper_y
6
+ @stepper_z = stepper_z
7
+ @scale = scale
8
+ @servo = servo
6
9
  end
7
10
 
8
11
  def open(file)
@@ -10,20 +13,89 @@ module Rotor
10
13
  end
11
14
 
12
15
  def simulate
16
+ @x = 0
17
+ @y = 0
18
+ @z = 0
19
+
13
20
  @file.each_line do |line|
14
- case line[0]
15
- when "G"
16
- puts "GLINE"
17
- when "M"
18
- puts "MLINE"
21
+ parsed_line = parse_line(line)
22
+ if parsed_line[:g]
23
+ #Move to this origin point.
24
+ if parsed_line[:g] == 0
25
+ move_stepper(parsed_line,1)
26
+ elsif parsed_line[:g] == 1
27
+ move_stepper(parsed_line,10)
28
+ else
29
+ # puts "GLINE - Something else"
30
+ end
31
+ elsif parsed_line[:m]
32
+ if line[0..2] == "M03"
33
+ puts "Lowering marker"
34
+ @servo.rotate(:down) if @servo
35
+ elsif line[0..2] == "M05"
36
+ puts "Lifting marker"
37
+ @servo.rotate(:up) if @servo
38
+ else
39
+ # puts "MLINE - Something else"
40
+ end
19
41
  else
20
- puts "something else"
42
+ # puts "Something else"
21
43
  end
22
44
  end
23
45
  end
24
- end
25
- end
26
46
 
27
- gcode = Rotor::Gcode.new
28
- gcode.open('sample.nc')
29
- gcode.simulate
47
+ def move_stepper(parsed_line,delay)
48
+ threads = []
49
+ [:x,:y,:z].each do |element|
50
+ ets = element.to_s
51
+ instance_variable_set(:"@#{ets}_move",nil)
52
+ if parsed_line[element]
53
+ instance_variable_set(:"@#{ets}_move",parsed_line[element])
54
+ instance_variable_set(:"@#{ets}_move",0) unless instance_variable_get(:"@#{ets}_move")
55
+ instance_variable_set(:"@#{ets}_move",instance_variable_get(:"@#{ets}_move") * @scale)
56
+
57
+ instance_variable_set(:"@#{ets}_movement", (instance_variable_get(:"@#{ets}_move") - instance_variable_get(:"@#{ets}")).abs)
58
+
59
+ if instance_variable_get(:"@#{ets}_move").to_f > instance_variable_get(:"@#{ets}") #move to the right
60
+ if instance_variable_get(:"@stepper_#{ets}") && instance_variable_get(:"@stepper_#{ets}").at_safe_area?
61
+ threads << Thread.new { instance_variable_get(:"@stepper_#{ets}").forward(1, instance_variable_get(:"@#{ets}_movement")) }
62
+ end
63
+ elsif instance_variable_get(:"@#{ets}_move").to_f < instance_variable_get(:"@#{ets}") #move to the left
64
+ if instance_variable_get(:"@stepper_#{ets}") && instance_variable_get(:"@stepper_#{ets}").at_safe_area?
65
+ threads << Thread.new { instance_variable_get(:"@stepper_#{ets}").backwards(1, instance_variable_get(:"@#{ets}_movement")) }
66
+ end
67
+ end
68
+ instance_variable_set(:"@#{ets}",instance_variable_get(:"@#{ets}_move"))
69
+ end
70
+ end
71
+
72
+ puts "Moving to G#{parsed_line[:g]} #{instance_variable_get(:"@x_move")}, #{instance_variable_get(:"@y_move")}, #{instance_variable_get(:"@z_move")}"
73
+ threads.each { |thr| thr.join }
74
+ end
75
+
76
+ def parse_line(line)
77
+ returned_json = {}
78
+ values = [:g,:x,:y,:z,:i,:j,:m,:f]
79
+ values.each do |element|
80
+ returned_json[element] = find_value(element,line)
81
+ end
82
+ return returned_json
83
+ end
84
+
85
+ def find_value(element,line)
86
+ node = element.to_s.upcase
87
+ data = line.match /#{node}(?<data>\d+[,.]\d+)/
88
+ data ||= line.match /#{node}(?<data>\d+)/
89
+ if data
90
+ case element
91
+ when :g, :m
92
+ return data[:data].to_i
93
+ when :x,:y,:z,:i,:k,:f
94
+ return data[:data].to_f
95
+ end
96
+ else
97
+ return nil
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,29 @@
1
+ require 'wiringpi'
2
+
3
+ module Rotor
4
+ class Servo
5
+ def initialize(pin=18)
6
+ @io = WiringPi::GPIO.new(WPI_MODE_GPIO)
7
+ @pin = pin
8
+ @io.mode @pin, OUTPUT
9
+ end
10
+
11
+ def pulser(freq,dur)
12
+ @io.write @pin, HIGH
13
+ sleep (freq/1000)
14
+ @io.write @pin, LOW
15
+ sleep ((dur-freq)/1000)
16
+ end
17
+
18
+ def rotate(direction)
19
+ if direction == :up
20
+ freq = 1.0
21
+ elsif direction == :down
22
+ freq = 2.0
23
+ else
24
+ freq = 0.0
25
+ end
26
+ 25.times do;pulser(freq,20.0);end
27
+ end
28
+ end
29
+ end
data/lib/rotor/stepper.rb CHANGED
@@ -12,6 +12,7 @@ module Rotor
12
12
 
13
13
  @homing_switch = homing_switch
14
14
  @homing_normally = homing_normally
15
+
15
16
  [@coil_A_1_pin, @coil_A_2_pin, @coil_B_1_pin, @coil_B_2_pin].each do |pin|
16
17
  `echo #{pin} > /sys/class/gpio/unexport`
17
18
  @io.mode(pin,OUTPUT)
@@ -24,6 +25,11 @@ module Rotor
24
25
  @io.write(@enable_pin,LOW)
25
26
  @io.write(@enable_pin,HIGH)
26
27
  end
28
+
29
+ unless @homing_switch == nil
30
+ `echo #{@homing_switch} > /sys/class/gpio/unexport`
31
+ @io.mode(@homing_switch,INPUT)
32
+ end
27
33
  end
28
34
 
29
35
  def forward(delay=5,steps=100)
@@ -62,14 +68,29 @@ module Rotor
62
68
  end
63
69
 
64
70
  def set_home(direction)
65
- `echo #{@homing_switch} > /sys/class/gpio/unexport`
66
- @io.mode(@homing_switch,INPUT)
71
+ puts "Setting #{direction} with Homing on GPIO #{@homing_switch}"
67
72
  @move = true
68
73
  while @move == true
69
- backwards(10,5) if direction == :backwards && @io.read(@homing_switch) == @homing_normally
70
- forward(10,5) if direction == :forward && @io.read(@homing_switch) == @homing_normally
74
+ backwards(2,1) if direction == :backwards #&& @io.read(@homing_switch) == @homing_normally
75
+ forward(2,1) if direction == :forward #&& @io.read(@homing_switch) == @homing_normally
76
+ @move = false unless @io.read(@homing_switch) == @homing_normally
71
77
  end
72
78
  end
73
79
 
80
+ def at_home?
81
+ if @io.read(@homing_switch) == @homing_normally
82
+ return true
83
+ else
84
+ return false
85
+ end
86
+ end
87
+
88
+ def at_safe_area?
89
+ if @io.read(@homing_switch) == @homing_normally
90
+ return false
91
+ else
92
+ return true
93
+ end
94
+ end
74
95
  end
75
96
  end
data/lib/rotor/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rotor
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
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.0.10
4
+ version: 0.0.11
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-17 00:00:00.000000000 Z
11
+ date: 2015-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -69,7 +69,7 @@ files:
69
69
  - lib/rotor.rb
70
70
  - lib/rotor/.DS_Store
71
71
  - lib/rotor/gcode.rb
72
- - lib/rotor/motor.rb
72
+ - lib/rotor/servo.rb
73
73
  - lib/rotor/stepper.rb
74
74
  - lib/rotor/version.rb
75
75
  - rotor.gemspec
data/lib/rotor/motor.rb DELETED
@@ -1,76 +0,0 @@
1
- require 'wiringpi'
2
-
3
- module Rotor
4
- class Stepper
5
- def initialize(coil_A_1_pin, coil_A_2_pin, coil_B_1_pin, coil_B_2_pin, enable_pin=nil, homing_switch, homing_normally)
6
- @io = WiringPi::GPIO.new(WPI_MODE_GPIO)
7
- @coil_A_1_pin = coil_A_1_pin
8
- @coil_A_2_pin = coil_A_2_pin
9
- @coil_B_1_pin = coil_B_1_pin
10
- @coil_B_2_pin = coil_B_2_pin
11
- @enable_pin = enable_pin
12
-
13
- @homing_switch = homing_switch
14
- @homing_normally = homing_normally
15
- [@coil_A_1_pin, @coil_A_2_pin, @coil_B_1_pin, @coil_B_2_pin].each do |pin|
16
- `echo #{pin} > /sys/class/gpio/unexport`
17
- @io.mode(pin,OUTPUT)
18
- @io.write(pin,LOW)
19
- end
20
-
21
- unless @enable_pin == nil
22
- `echo #{@enable_pin} > /sys/class/gpio/unexport`
23
- @io.mode(@enable_pin,OUTPUT)
24
- @io.write(@enable_pin,LOW)
25
- @io.write(@enable_pin,HIGH)
26
- end
27
- end
28
-
29
- def forward(delay=5,steps=100)
30
- delay_time = delay/1000.0
31
- (0..steps).each do |i|
32
- set_step(1, 0, 1, 0)
33
- sleep delay_time
34
- set_step(0, 1, 1, 0)
35
- sleep delay_time
36
- set_step(0, 1, 0, 1)
37
- sleep delay_time
38
- set_step(1, 0, 0, 1)
39
- sleep delay_time
40
- end
41
- end
42
-
43
- def backwards(delay=5,steps=100)
44
- delay_time = delay/1000.0
45
- (0..steps).each do |i|
46
- set_step(1, 0, 0, 1)
47
- sleep delay_time
48
- set_step(0, 1, 0, 1)
49
- sleep delay_time
50
- set_step(0, 1, 1, 0)
51
- sleep delay_time
52
- set_step(1, 0, 1, 0)
53
- sleep delay_time
54
- end
55
- end
56
-
57
- def set_step(w1, w2, w3, w4)
58
- @io.write(@coil_A_1_pin, w1)
59
- @io.write(@coil_A_2_pin, w2)
60
- @io.write(@coil_B_1_pin, w3)
61
- @io.write(@coil_B_2_pin, w4)
62
- end
63
-
64
- def set_home(direction)
65
- `echo #{@homing_switch} > /sys/class/gpio/unexport`
66
- @io.mode(@homing_switch,INPUT)
67
- @move = true
68
- while @move == true
69
- backwards(2,1) if direction == :backwards #&& @io.read(@homing_switch) == @homing_normally
70
- forward(2,1) if direction == :forward #&& @io.read(@homing_switch) == @homing_normally
71
- @move = false unless @io.read(@homing_switch) == @homing_normally
72
- end
73
- end
74
-
75
- end
76
- end