farmbot-serial 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +46 -0
- data/Gemfile +6 -0
- data/README.md +1 -0
- data/Rakefile +9 -0
- data/farmbot-serial.gemspec +27 -0
- data/lib/arduino_default_params.rb +148 -0
- data/lib/farmbot-serial.rb +9 -0
- data/lib/hardware_interface.rb +210 -0
- data/lib/hardware_interface_arduino.rb +346 -0
- data/lib/hardware_interface_arduino_values_received.rb +56 -0
- data/lib/hardware_interface_arduino_write_status.rb +30 -0
- data/lib/hardware_interface_param.rb +218 -0
- data/lib/serial_port_sim.rb +31 -0
- data/lib/status.rb +52 -0
- data/spec/lib/ramps_arduino_spec.rb +672 -0
- data/spec/lib/ramps_arduino_values_received_spec.rb +66 -0
- data/spec/lib/ramps_arduino_write_status_spec.rb +27 -0
- data/spec/lib/ramps_param_spec.rb +555 -0
- data/spec/lib/ramps_spec.rb +289 -0
- data/spec/spec_helper.rb +17 -0
- data/testcommands.csv +25 -0
- metadata +156 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 07780e1523d04161c781211ba25173ffa6e51db0
|
4
|
+
data.tar.gz: f2677ab821c15c5664f099d7afd7e51805b2f2b2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 34dffc021c50794f21635582f35c102f6199c9ee349bb53f496ec9b15655c702ba4f01725c713366b1cd4611b588fa47212bd7346418ad08aa85b25cdbd9cc09
|
7
|
+
data.tar.gz: 6f5bc299b55e95d3083c255d0f30d13f7b7db18b3a36740a61cc4d923f6f4e14f4f73fb367d1b6198293ebcc1660b845ffd96225e0480099240fa83a6ded11c6
|
data/.gitignore
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
*.swp
|
4
|
+
.bundle/*
|
5
|
+
.DS_Store
|
6
|
+
.idea/*
|
7
|
+
.loadpath
|
8
|
+
.project
|
9
|
+
.ruby-gemset
|
10
|
+
.ruby-version
|
11
|
+
/.bundle
|
12
|
+
/.bundle/
|
13
|
+
/.yardoc/
|
14
|
+
/_yardoc/
|
15
|
+
/coverage/
|
16
|
+
/coverage/
|
17
|
+
/db/*.sqlite3
|
18
|
+
/db/*.sqlite3-journal
|
19
|
+
/doc/
|
20
|
+
/InstalledFiles
|
21
|
+
/lib/.build
|
22
|
+
/lib/bundler/man/
|
23
|
+
/log/*.log
|
24
|
+
/pkg/
|
25
|
+
/rdoc/
|
26
|
+
/spec/reports/
|
27
|
+
/test/tmp/
|
28
|
+
/test/version_tmp/
|
29
|
+
/tmp
|
30
|
+
/tmp/
|
31
|
+
config.yml
|
32
|
+
coverage/**
|
33
|
+
credentials.yml
|
34
|
+
doc/*
|
35
|
+
doc/**/*
|
36
|
+
Gemfile.lock
|
37
|
+
log/*
|
38
|
+
notes.rb
|
39
|
+
settings.rb
|
40
|
+
/lib/.build
|
41
|
+
write_db_settings.rb
|
42
|
+
snippet.coffee
|
43
|
+
snippets.rb
|
44
|
+
tmp/**/*
|
45
|
+
*.rb~
|
46
|
+
Gemfile.lock
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Under construction.
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "farmbot-serial"
|
7
|
+
spec.version = '0.0.1' # TODO: Fb::Serial::VERSION
|
8
|
+
spec.authors = ["Tim Evers", "Rick Carlino"]
|
9
|
+
spec.email = ["rick.carlino@gmail.com"]
|
10
|
+
spec.description = "Serial library for Farmbot"
|
11
|
+
spec.summary = "Serial library for Farmbot"
|
12
|
+
spec.homepage = "http://github.com/farmbot/farmbot-serial"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler"#, "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake"#, "~> 10.4"
|
22
|
+
spec.add_development_dependency "rspec"#, "~> 3.2"
|
23
|
+
spec.add_development_dependency "pry"#, "~> 0.10"
|
24
|
+
spec.add_development_dependency "simplecov"#, "~> 0.9"
|
25
|
+
|
26
|
+
spec.add_runtime_dependency "serialport"#, "~> 1.3"
|
27
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
# Put this in a module.
|
2
|
+
$arduino_default_params = [
|
3
|
+
{
|
4
|
+
:name => 'PARAM_VERSION',
|
5
|
+
:id => 0,
|
6
|
+
:value => 0
|
7
|
+
},
|
8
|
+
{
|
9
|
+
:name => 'MOVEMENT_TIMEOUT_X',
|
10
|
+
:id => 11,
|
11
|
+
:value => 15
|
12
|
+
},
|
13
|
+
{
|
14
|
+
:name => 'MOVEMENT_TIMEOUT_Y',
|
15
|
+
:id => 12,
|
16
|
+
:value => 15
|
17
|
+
},
|
18
|
+
{
|
19
|
+
:name => 'MOVEMENT_TIMEOUT_Z',
|
20
|
+
:id => 13,
|
21
|
+
:value => 15
|
22
|
+
},
|
23
|
+
{
|
24
|
+
:name => 'MOVEMENT_INVERT_ENDPOINTS_X',
|
25
|
+
:id => 21,
|
26
|
+
:value => 0
|
27
|
+
},
|
28
|
+
{
|
29
|
+
:name => 'MOVEMENT_INVERT_ENDPOINTS_Y',
|
30
|
+
:id => 22,
|
31
|
+
:value => 0
|
32
|
+
},
|
33
|
+
{
|
34
|
+
:name => 'MOVEMENT_INVERT_ENDPOINTS_Z',
|
35
|
+
:id => 23,
|
36
|
+
:value => 0
|
37
|
+
},
|
38
|
+
{
|
39
|
+
:name => 'MOVEMENT_INVERT_MOTOR_X',
|
40
|
+
:id => 31,
|
41
|
+
:value => 0
|
42
|
+
},
|
43
|
+
{
|
44
|
+
:name => 'MOVEMENT_INVERT_MOTOR_Y',
|
45
|
+
:id => 32,
|
46
|
+
:value => 0
|
47
|
+
},
|
48
|
+
{
|
49
|
+
:name => 'MOVEMENT_INVERT_MOTOR_Z',
|
50
|
+
:id => 33,
|
51
|
+
:value => 0
|
52
|
+
},
|
53
|
+
{
|
54
|
+
:name => 'MOVEMENT_STEPS_ACC_DEC_X',
|
55
|
+
:id => 41,
|
56
|
+
:value => 100
|
57
|
+
},
|
58
|
+
{
|
59
|
+
:name => 'MOVEMENT_STEPS_ACC_DEC_Y',
|
60
|
+
:id => 42,
|
61
|
+
:value => 100
|
62
|
+
},
|
63
|
+
{
|
64
|
+
:name => 'MOVEMENT_STEPS_ACC_DEC_Z',
|
65
|
+
:id => 43,
|
66
|
+
:value => 100
|
67
|
+
},
|
68
|
+
{
|
69
|
+
:name => 'MOVEMENT_HOME_UP_X',
|
70
|
+
:id => 51,
|
71
|
+
:value => 0
|
72
|
+
},
|
73
|
+
{
|
74
|
+
:name => 'MOVEMENT_HOME_UP_Y',
|
75
|
+
:id => 52,
|
76
|
+
:value => 0
|
77
|
+
},
|
78
|
+
{
|
79
|
+
:name => 'MOVEMENT_HOME_UP_Z',
|
80
|
+
:id => 53,
|
81
|
+
:value => 0
|
82
|
+
},
|
83
|
+
{
|
84
|
+
:name => 'MOVEMENT_MIN_SPD_X',
|
85
|
+
:id => 61,
|
86
|
+
:value => 200
|
87
|
+
},
|
88
|
+
{
|
89
|
+
:name => 'MOVEMENT_MIN_SPD_Y',
|
90
|
+
:id => 62,
|
91
|
+
:value => 200
|
92
|
+
},
|
93
|
+
{
|
94
|
+
:name => 'MOVEMENT_MIN_SPD_Z',
|
95
|
+
:id => 63,
|
96
|
+
:value => 200
|
97
|
+
},
|
98
|
+
{
|
99
|
+
:name => 'MOVEMENT_MAX_SPD_X',
|
100
|
+
:id => 71,
|
101
|
+
:value => 1000
|
102
|
+
},
|
103
|
+
{
|
104
|
+
:name => 'MOVEMENT_MAX_SPD_Y',
|
105
|
+
:id => 72,
|
106
|
+
:value => 1000
|
107
|
+
},
|
108
|
+
{
|
109
|
+
:name => 'MOVEMENT_MAX_SPD_Z',
|
110
|
+
:id => 73,
|
111
|
+
:value => 1000
|
112
|
+
},
|
113
|
+
{
|
114
|
+
:name => 'MOVEMENT_LENGTH_X',
|
115
|
+
:id => 101,
|
116
|
+
:value => 1000
|
117
|
+
},
|
118
|
+
{
|
119
|
+
:name => 'MOVEMENT_LENGTH_Y',
|
120
|
+
:id => 102,
|
121
|
+
:value => 1000
|
122
|
+
},
|
123
|
+
{
|
124
|
+
:name => 'MOVEMENT_LENGTH_Z',
|
125
|
+
:id => 103,
|
126
|
+
:value => 1000
|
127
|
+
},
|
128
|
+
{
|
129
|
+
:name => 'MOVEMENT_STEPS_PER_UNIT_X',
|
130
|
+
:id => 111,
|
131
|
+
:value => 5
|
132
|
+
},
|
133
|
+
{
|
134
|
+
:name => 'MOVEMENT_STEPS_PER_UNIT_Y',
|
135
|
+
:id => 112,
|
136
|
+
:value => 5
|
137
|
+
},
|
138
|
+
{
|
139
|
+
:name => 'MOVEMENT_STEPS_PER_UNIT_Z',
|
140
|
+
:id => 113,
|
141
|
+
:value => 5
|
142
|
+
},
|
143
|
+
{
|
144
|
+
:name => 'TESTING',
|
145
|
+
:id => 1,
|
146
|
+
:value => 0
|
147
|
+
}
|
148
|
+
]
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'serialport'
|
2
|
+
require 'serial_port_sim'
|
3
|
+
require 'status'
|
4
|
+
require 'arduino_default_params'
|
5
|
+
require 'hardware_interface_arduino'
|
6
|
+
require 'hardware_interface_param'
|
7
|
+
require 'hardware_interface'
|
8
|
+
require 'hardware_interface_arduino_values_received'
|
9
|
+
require 'hardware_interface_arduino_write_status'
|
@@ -0,0 +1,210 @@
|
|
1
|
+
## HARDWARE INTERFACE
|
2
|
+
## ******************
|
3
|
+
|
4
|
+
# Communicate with the arduino using a serial interface
|
5
|
+
# All information is exchanged using a variation of g-code
|
6
|
+
# Parameters are stored in the database
|
7
|
+
module Fb
|
8
|
+
class HardwareInterface
|
9
|
+
class << self
|
10
|
+
attr_accessor :current
|
11
|
+
|
12
|
+
def current
|
13
|
+
@current ||= self.new(true)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
attr_reader :ramps_param, :ramps_main, :ramps_arduino
|
18
|
+
attr_accessor :status
|
19
|
+
|
20
|
+
# initialize the interface
|
21
|
+
#
|
22
|
+
def initialize(test_mode)
|
23
|
+
@status = Fb::Status.new
|
24
|
+
@test_mode = test_mode
|
25
|
+
|
26
|
+
# create the sub processing objects
|
27
|
+
@ramps_param = Fb::HardwareInterfaceParam.new
|
28
|
+
@ramps_arduino = Fb::HardwareInterfaceArduino.new(test_mode)
|
29
|
+
|
30
|
+
@ramps_arduino.ramps_param = @ramps_param
|
31
|
+
@ramps_arduino.ramps_main = self
|
32
|
+
@ramps_param.ramps_arduino = @ramps_arduino
|
33
|
+
@ramps_param.ramps_main = self
|
34
|
+
|
35
|
+
@external_info = ""
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
## INTERFACE FUNCTIONS
|
40
|
+
## *******************
|
41
|
+
|
42
|
+
## control additional I/O (servo, pins, water)
|
43
|
+
|
44
|
+
# move a servo
|
45
|
+
#
|
46
|
+
def servo_std_move(pin, value)
|
47
|
+
@ramps_arduino.execute_command("F61 P#{pin} V#{value}", false, @status_debug_msg)
|
48
|
+
end
|
49
|
+
|
50
|
+
# set standard pin value
|
51
|
+
#
|
52
|
+
def pin_std_set_value(pin, value, mode)
|
53
|
+
@ramps_arduino.execute_command("F41 P#{pin} V#{value} M#{mode}", false, @status_debug_msg)
|
54
|
+
end
|
55
|
+
|
56
|
+
# read standard pin
|
57
|
+
#
|
58
|
+
def pin_std_read_value(pin, mode, external_info)
|
59
|
+
@ramps_arduino.external_info = external_info
|
60
|
+
@ramps_arduino.execute_command("F42 P#{pin} M#{mode}", false, @status_debug_msg)
|
61
|
+
@external_info = ''
|
62
|
+
end
|
63
|
+
|
64
|
+
# set standard pin mode
|
65
|
+
#
|
66
|
+
def pin_std_set_mode(pin, mode)
|
67
|
+
@ramps_arduino.execute_command("F43 P#{pin} M#{mode}", false, @status_debug_msg)
|
68
|
+
end
|
69
|
+
|
70
|
+
# set pulse on standard pin
|
71
|
+
#
|
72
|
+
def pin_std_pulse(pin, value1, value2, time, mode)
|
73
|
+
@ramps_arduino.execute_command("F44 P#{pin} V#{value1} W#{value2} T#{time} M#{mode}", false, @status_debug_msg)
|
74
|
+
end
|
75
|
+
|
76
|
+
# dose an amount of water (in ml)
|
77
|
+
#
|
78
|
+
def dose_water(amount)
|
79
|
+
@ramps_arduino.execute_command("F01 Q#{amount.to_i}", false, @status_debug_msg)
|
80
|
+
end
|
81
|
+
|
82
|
+
## arduino status
|
83
|
+
|
84
|
+
# read end stop status from the device
|
85
|
+
#
|
86
|
+
def read_end_stops()
|
87
|
+
@ramps_arduino.execute_command('F81', false, @status_debug_msg)
|
88
|
+
end
|
89
|
+
|
90
|
+
# read current coordinates from the device
|
91
|
+
#
|
92
|
+
def read_postition()
|
93
|
+
@ramps_arduino.execute_command('F82', false, @status_debug_msg)
|
94
|
+
end
|
95
|
+
# read current software version
|
96
|
+
#
|
97
|
+
def read_device_version()
|
98
|
+
@ramps_arduino.execute_command('F83', false, @status_debug_msg)
|
99
|
+
end
|
100
|
+
|
101
|
+
## basic movements
|
102
|
+
|
103
|
+
# move all axis home
|
104
|
+
#
|
105
|
+
def move_home_all
|
106
|
+
status.info_target_x = 0
|
107
|
+
status.info_target_y = 0
|
108
|
+
status.info_target_z = 0
|
109
|
+
@ramps_arduino.execute_command('G28', true, false)
|
110
|
+
end
|
111
|
+
|
112
|
+
# move the bot to the home position
|
113
|
+
#
|
114
|
+
def move_home_x
|
115
|
+
status.info_target_x = 0
|
116
|
+
@ramps_arduino.execute_command('F11', true, false)
|
117
|
+
end
|
118
|
+
|
119
|
+
# move the bot to the home position
|
120
|
+
#
|
121
|
+
def move_home_y
|
122
|
+
status.info_target_y = 0
|
123
|
+
@ramps_arduino.execute_command('F12', true, false)
|
124
|
+
end
|
125
|
+
|
126
|
+
# move the bot to the home position
|
127
|
+
#
|
128
|
+
def move_home_z
|
129
|
+
status.info_target_z = 0
|
130
|
+
@ramps_arduino.execute_command('F13', true, false)
|
131
|
+
end
|
132
|
+
|
133
|
+
# calibrate x axis
|
134
|
+
#
|
135
|
+
def calibrate_x
|
136
|
+
status.info_target_x = 0
|
137
|
+
@ramps_arduino.execute_command('F14', true, false)
|
138
|
+
end
|
139
|
+
|
140
|
+
# calibrate y axis
|
141
|
+
#
|
142
|
+
def calibrate_y
|
143
|
+
status.info_target_y = 0
|
144
|
+
@ramps_arduino.execute_command('F15', true, false)
|
145
|
+
end
|
146
|
+
|
147
|
+
# calibrate z axis
|
148
|
+
#
|
149
|
+
def calibrate_z
|
150
|
+
status.info_target_z = 0
|
151
|
+
@ramps_arduino.execute_command('F16', true, false)
|
152
|
+
end
|
153
|
+
|
154
|
+
# move the bot to the give coordinates
|
155
|
+
#
|
156
|
+
def move_absolute( coord_x, coord_y, coord_z)
|
157
|
+
|
158
|
+
status.info_target_x = coord_x
|
159
|
+
status.info_target_y = coord_y
|
160
|
+
status.info_target_z = coord_z
|
161
|
+
|
162
|
+
# calculate the number of steps for the motors to do
|
163
|
+
|
164
|
+
steps_x = coord_x * @ramps_param.axis_x_steps_per_unit
|
165
|
+
steps_y = coord_y * @ramps_param.axis_y_steps_per_unit
|
166
|
+
steps_z = coord_z * @ramps_param.axis_z_steps_per_unit
|
167
|
+
|
168
|
+
move_to_coord(steps_x, steps_y, steps_z )
|
169
|
+
|
170
|
+
end
|
171
|
+
|
172
|
+
# move the bot a number of units starting from the current position
|
173
|
+
#
|
174
|
+
def move_relative( amount_x, amount_y, amount_z)
|
175
|
+
|
176
|
+
# calculate the number of steps for the motors to do
|
177
|
+
|
178
|
+
status.info_target_x = status.info_current_x + amount_x
|
179
|
+
status.info_target_y = status.info_current_y + amount_y
|
180
|
+
status.info_target_z = status.info_current_z + amount_z
|
181
|
+
|
182
|
+
steps_x = amount_x * @ramps_param.axis_x_steps_per_unit + status.info_current_x_steps
|
183
|
+
steps_y = amount_y * @ramps_param.axis_y_steps_per_unit + status.info_current_y_steps
|
184
|
+
steps_z = amount_z * @ramps_param.axis_z_steps_per_unit + status.info_current_z_steps
|
185
|
+
|
186
|
+
move_to_coord( steps_x, steps_y, steps_z )
|
187
|
+
|
188
|
+
end
|
189
|
+
|
190
|
+
# drive the motors so the bot is moved a number of steps
|
191
|
+
#
|
192
|
+
def move_steps(steps_x, steps_y, steps_z)
|
193
|
+
@ramps_arduino.execute_command("G01 X#{steps_x.to_i} Y#{steps_y.to_i} Z#{steps_z.to_i}", true, false)
|
194
|
+
end
|
195
|
+
|
196
|
+
# drive the motors so the bot is moved to a set location
|
197
|
+
#
|
198
|
+
def move_to_coord(steps_x, steps_y, steps_z)
|
199
|
+
@ramps_arduino.execute_command("G00 X#{steps_x.to_i} Y#{steps_y.to_i} Z#{steps_z.to_i}", true, false)
|
200
|
+
end
|
201
|
+
|
202
|
+
## parameter hanlding
|
203
|
+
|
204
|
+
def check_parameters
|
205
|
+
@ramps_param.check_parameters()
|
206
|
+
end
|
207
|
+
|
208
|
+
end
|
209
|
+
|
210
|
+
end
|