capoblo 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 529e7df166f38fdc75da10d979b9749430f6f947
4
+ data.tar.gz: 2ed170a3f5ba9907193951930982c7b4ca8fc49a
5
+ SHA512:
6
+ metadata.gz: 39b7b5b6dcbba55786b6cff2faab7358d463370426181dd358f4218c01eb11ce4fcb62cfbcb8f4d61facfc06cdf28ec4671256f294caa1acf6c293b0728bc186
7
+ data.tar.gz: 4975e1ccdd48187620904cf4411bd72c008b538a8fd7adf8f88ea052303031a2dfb718346b52d00c6f4efd90f672f5c85864a7e8b797faaf363101e88eceaa16
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.idea
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capoblo.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Oguzhan ilhan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Capoblo
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/capoblo`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'capoblo'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install capoblo
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/capoblo. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/capoblo ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ $:.unshift File.expand_path '../lib', File.dirname(__FILE__)
4
+
5
+ require "capoblo"
6
+
7
+
8
+ ## Connected Arduinos Information
9
+ ARDUINO_ONE_PORT = "/dev/ttyACM0"
10
+ puts ARDUINO_ONE_PORT
11
+
12
+
13
+ ## Setting Up and connect Arduinos
14
+ ARDUINO_ONE = InterfaceConnection.get_interface
15
+
16
+ #Rack::Server.start :app => WebInterface
17
+ sleep 1
data/capoblo.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capoblo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "capoblo"
8
+ spec.version = Capoblo::VERSION
9
+ spec.authors = ["Oguzhan ilhan"]
10
+ spec.email = ["ilhanoguzhan@gmail.com"]
11
+
12
+ spec.summary = %q{Two motor robot library.}
13
+ spec.description = %q{Two motor robot library for raspberry pi or others.}
14
+ spec.homepage = "https://github.com/ilhanoguzhan."
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($/).reject{|i| i=="Gemfile.lock" }
18
+ spec.executables = spec.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+
25
+ spec.add_dependency "arduino_firmata", "~> 0.3"
26
+ end
@@ -0,0 +1,164 @@
1
+ class ArduinoMoves
2
+
3
+ attr_accessor :arduino
4
+
5
+ MIN_POWER = 60
6
+
7
+ ## For Two Motors
8
+ LEFT_DIGITAL_BACKWARD = 5 # Input3 connected to pin 5
9
+ LEFT_DIGITAL_FORWARD = 4 # Input4 connected to pin 4
10
+ LEFT_ANALOG_SIGNAL = 3 # ENB connected to pin 3 of Arduino
11
+ RIGHT_DIGITAL_BACKWARD = 8 # Input3 connected to pin 5
12
+ RIGHT_DIGITAL_FORWARD = 7 # Input4 connected to pin 4
13
+ RIGHT_ANALOG_SIGNAL = 6 # ENB connected to pin 3 of Arduino
14
+
15
+
16
+ def initialize
17
+ super
18
+ self.arduino = ARDUINO_ONE
19
+
20
+ ## For Two Motors
21
+ self.arduino.pin_mode LEFT_DIGITAL_BACKWARD, ArduinoFirmata::OUTPUT
22
+ self.arduino.pin_mode LEFT_DIGITAL_FORWARD, ArduinoFirmata::OUTPUT
23
+ self.arduino.pin_mode LEFT_ANALOG_SIGNAL, ArduinoFirmata::OUTPUT
24
+ self.arduino.pin_mode RIGHT_DIGITAL_BACKWARD, ArduinoFirmata::OUTPUT
25
+ self.arduino.pin_mode RIGHT_DIGITAL_FORWARD, ArduinoFirmata::OUTPUT
26
+ self.arduino.pin_mode RIGHT_ANALOG_SIGNAL, ArduinoFirmata::OUTPUT
27
+
28
+ end
29
+
30
+ def run_forward(power = MIN_POWER, times = 0)
31
+ set_all_forward
32
+ if times == 0
33
+ soft_run true, power
34
+ else
35
+ soft_run true, power
36
+ sleep times
37
+ stop_all
38
+ end
39
+ end
40
+
41
+ def run_backward(power = MIN_POWER, times = 0)
42
+ set_all_backward
43
+ if times == 0
44
+ soft_run true, power
45
+ else
46
+ soft_run true, power
47
+ sleep times
48
+ stop_all
49
+ end
50
+ end
51
+
52
+ def rotate_clockwise
53
+ set_left_forward
54
+ set_right_backward
55
+ soft_run
56
+ end
57
+
58
+ def rotate_anticlockwise
59
+ set_left_backward
60
+ set_right_forward
61
+ soft_run
62
+ end
63
+
64
+ def turn_right(times = 3)
65
+ set_left_forward
66
+ set_right_forward
67
+ run(LEFT_ANALOG_SIGNAL, 125)
68
+ run(RIGHT_ANALOG_SIGNAL, 65)
69
+ sleep times
70
+ end
71
+
72
+
73
+ def turn_left(times = 3)
74
+ set_left_forward
75
+ set_right_forward
76
+ run(LEFT_ANALOG_SIGNAL, 65)
77
+ run(RIGHT_ANALOG_SIGNAL, 125)
78
+ sleep times
79
+ end
80
+
81
+ def turn_back_right(times = 3)
82
+ set_left_backward
83
+ set_right_backward
84
+ run(LEFT_ANALOG_SIGNAL, 125)
85
+ run(RIGHT_ANALOG_SIGNAL, 65)
86
+ sleep times
87
+ end
88
+
89
+ def turn_back_left(times = 3)
90
+ set_left_backward
91
+ set_right_backward
92
+ run(LEFT_ANALOG_SIGNAL, 65)
93
+ run(RIGHT_ANALOG_SIGNAL, 125)
94
+ sleep times
95
+ end
96
+
97
+
98
+ def stop_all
99
+ run(LEFT_ANALOG_SIGNAL, 0)
100
+ run(RIGHT_ANALOG_SIGNAL, 0)
101
+ arduino.digital_write LEFT_DIGITAL_BACKWARD, false
102
+ arduino.digital_write LEFT_DIGITAL_FORWARD, true
103
+ arduino.digital_write RIGHT_DIGITAL_BACKWARD, false
104
+ arduino.digital_write RIGHT_DIGITAL_FORWARD, true
105
+ end
106
+
107
+ private
108
+ def soft_run(is_continues = false, max_power = 145)
109
+ if is_continues
110
+ MIN_POWER.upto(max_power).each do |val|
111
+ run(LEFT_ANALOG_SIGNAL, val)
112
+ run(RIGHT_ANALOG_SIGNAL, val)
113
+ sleep 0.01
114
+ end
115
+ else
116
+ MIN_POWER.upto(max_power).each do |val|
117
+ run(LEFT_ANALOG_SIGNAL, val)
118
+ run(RIGHT_ANALOG_SIGNAL, val)
119
+ sleep 0.01
120
+ end
121
+ max_power.downto(MIN_POWER).each do |val|
122
+ run(LEFT_ANALOG_SIGNAL, val)
123
+ run(RIGHT_ANALOG_SIGNAL, val)
124
+ sleep 0.01
125
+ end
126
+ stop_all
127
+ end
128
+ end
129
+
130
+ def run(depending_pin, power = MIN_POWER)
131
+ arduino.analog_write depending_pin, power
132
+ end
133
+
134
+ def set_left_forward
135
+ arduino.digital_write LEFT_DIGITAL_BACKWARD, false
136
+ arduino.digital_write LEFT_DIGITAL_FORWARD, true
137
+ end
138
+
139
+ def set_right_forward
140
+ arduino.digital_write RIGHT_DIGITAL_BACKWARD, false
141
+ arduino.digital_write RIGHT_DIGITAL_FORWARD, true
142
+ end
143
+
144
+ def set_all_forward
145
+ set_left_forward
146
+ set_right_forward
147
+ end
148
+
149
+ def set_left_backward
150
+ arduino.digital_write LEFT_DIGITAL_BACKWARD, true
151
+ arduino.digital_write LEFT_DIGITAL_FORWARD, false
152
+ end
153
+
154
+ def set_right_backward
155
+ arduino.digital_write RIGHT_DIGITAL_BACKWARD, true
156
+ arduino.digital_write RIGHT_DIGITAL_FORWARD, false
157
+ end
158
+
159
+ def set_all_backward
160
+ set_left_backward
161
+ set_right_backward
162
+ end
163
+
164
+ end
@@ -0,0 +1,39 @@
1
+ class ArduinoSensors
2
+ attr_accessor :arduino, :front_distance, :rear_distance
3
+
4
+ ULTRASONIC_TRIGGER = 11
5
+ ULTRASONIC_ECHO = 12
6
+ AVOIDANCE_SENSOR_PIN = 2
7
+
8
+
9
+ def initialize
10
+ super
11
+ self.arduino = ARDUINO_ONE
12
+
13
+ self.arduino.pin_mode ULTRASONIC_TRIGGER, ArduinoFirmata::OUTPUT
14
+ self.arduino.pin_mode ULTRASONIC_ECHO, ArduinoFirmata::INPUT
15
+ self.arduino.pin_mode AVOIDANCE_SENSOR_PIN, ArduinoFirmata::INPUT
16
+ end
17
+
18
+
19
+ def front_distance
20
+ @front_distance = 0
21
+ ## For senfor is reading
22
+
23
+ arduino.digital_write ULTRASONIC_TRIGGER, false
24
+ sleep 0.005
25
+ arduino.digital_write ULTRASONIC_TRIGGER, true
26
+ sleep 0.01
27
+ arduino.digital_write ULTRASONIC_TRIGGER, false
28
+
29
+
30
+ puts arduino.sysex 0x74, [ULTRASONIC_ECHO, 1]
31
+ end
32
+
33
+ def rear_distance
34
+ @rear_distance = arduino.digital_read 2
35
+ @rear_distance
36
+ end
37
+
38
+
39
+ end
@@ -0,0 +1,29 @@
1
+ class InterfaceConnection
2
+ #simplest ruby program to read from arduino serial,
3
+ #using the SerialPort gem
4
+ #(http://rubygems.org/gems/serialport)
5
+ require "rubygems"
6
+ require "arduino_firmata"
7
+ require 'rubyserial'
8
+
9
+ #require "date"
10
+
11
+ attr_accessor :port_str, :baud_rate, :data_bits, :stop_bits, :parity
12
+ #params for serial port
13
+
14
+ def initialize
15
+ super
16
+ self.port_str = "/dev/ttyACM0" #may be different for you
17
+ self.baud_rate = 9600
18
+ self.data_bits = 8
19
+ self.stop_bits = 1
20
+ self.parity = SerialPort::NONE
21
+ end
22
+
23
+ def self.get_interface
24
+ conn = InterfaceConnection.new
25
+ arduino = ArduinoFirmata.connect conn.port_str
26
+ arduino
27
+ end
28
+
29
+ end
@@ -0,0 +1,3 @@
1
+ module Capoblo
2
+ VERSION = "0.1.0"
3
+ end
data/lib/capoblo.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "capoblo/version"
2
+ require "capoblo/interface_connection"
3
+ require "capoblo/arduino_moves"
4
+ require "capoblo/arduino_sensors"
5
+
6
+
7
+ module Capoblo
8
+ # Your code goes here...
9
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capoblo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Oguzhan ilhan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: arduino_firmata
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.3'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.3'
55
+ description: Two motor robot library for raspberry pi or others.
56
+ email:
57
+ - ilhanoguzhan@gmail.com
58
+ executables:
59
+ - capoblo
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - CODE_OF_CONDUCT.md
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/capoblo
70
+ - capoblo.gemspec
71
+ - lib/capoblo.rb
72
+ - lib/capoblo/arduino_moves.rb
73
+ - lib/capoblo/arduino_sensors.rb
74
+ - lib/capoblo/interface_connection.rb
75
+ - lib/capoblo/version.rb
76
+ homepage: https://github.com/ilhanoguzhan.
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.4.8
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Two motor robot library.
100
+ test_files: []