brick-pi 0.2.0 → 0.3.0
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 +4 -4
- data/README.md +90 -35
- data/lib/brick_pi/bot.rb +22 -8
- data/lib/brick_pi/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3978e422e7aef842b14c7fa85775465b3de0c2b
|
4
|
+
data.tar.gz: e4a48cd6cf90ef8fb77ebe2ec3a0a884580ebecb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73681522c98b6d7c0536730f95d51992d0279ee45d39d093485c95b77a7e9c890459882525adc3b66fb1b902c70b01bc45de98274d44695e4d711c2bc5cd44fc
|
7
|
+
data.tar.gz: 78ef2add72b15a2c63038406c74d6946d83b2df7b5ba586cddbfae2bab5838517ca59cd0a5d85d6c1f96c5d1f08b391e08733fe1b1845e009c4ee87c124624fd
|
data/README.md
CHANGED
@@ -2,12 +2,6 @@
|
|
2
2
|
|
3
3
|
ruby wrappers for the BrickPi Lego Mindstorms C library
|
4
4
|
|
5
|
-
## Issues
|
6
|
-
|
7
|
-
I use HuBoard to manage GitHub issues. It's pretty awesome, check it out here:
|
8
|
-
|
9
|
-
https://huboard.com/tehviking/brick_pi_ruby/
|
10
|
-
|
11
5
|
## What you need:
|
12
6
|
|
13
7
|
You need to have a few things to use this:
|
@@ -18,7 +12,10 @@ You need to have a few things to use this:
|
|
18
12
|
|
19
13
|
## Installation
|
20
14
|
|
21
|
-
**Note: This gem will currently only install on a Raspberry Pi set up with BrickPi software
|
15
|
+
**Note: This gem will currently only install on a Raspberry Pi set up with BrickPi software.** It relies on the `WiringPi.h` C program to function and compile.
|
16
|
+
|
17
|
+
You'll first need Ruby installed on your Raspberry Pi. If you need help, this Stack Overflow answer may be of service:
|
18
|
+
http://raspberrypi.stackexchange.com/questions/1010/can-i-install-the-ruby-version-manager
|
22
19
|
|
23
20
|
Add this line to your application's Gemfile:
|
24
21
|
|
@@ -51,17 +48,17 @@ bot = BrickPi.create do |bot|
|
|
51
48
|
end
|
52
49
|
|
53
50
|
# Get this party started
|
54
|
-
bot.
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
# Run the motor for 1 second
|
60
|
-
sleep 1
|
51
|
+
bot.start do
|
52
|
+
schedule do
|
53
|
+
# Set the speed for a motor, on a scale of 0 - 100
|
54
|
+
bot.motor_A.spin 50
|
61
55
|
|
62
|
-
|
63
|
-
|
56
|
+
# Run the motor for 1 second
|
57
|
+
sleep 1
|
64
58
|
|
59
|
+
# Stop a single motor
|
60
|
+
bot.motor_A.stop
|
61
|
+
end
|
65
62
|
end
|
66
63
|
```
|
67
64
|
|
@@ -72,6 +69,7 @@ Here's a really yucky script I hacked together to let you drive a 2-tracked vehi
|
|
72
69
|
It requires the Highline gem, so on the BrickPi you'll need to run `gem install highline`.
|
73
70
|
|
74
71
|
```ruby
|
72
|
+
require "brick_pi"
|
75
73
|
require "highline/system_extensions"
|
76
74
|
include HighLine::SystemExtensions
|
77
75
|
HighLine::SystemExtensions.raw_no_echo_mode
|
@@ -80,39 +78,89 @@ HighLine::SystemExtensions.raw_no_echo_mode
|
|
80
78
|
bot = BrickPi.create do |bot|
|
81
79
|
bot.motor :port_A
|
82
80
|
bot.motor :port_B
|
81
|
+
bot.ultrasonic_sensor :port_3
|
83
82
|
end
|
84
83
|
|
85
|
-
bot.
|
84
|
+
bot.singleton_class.class_eval do
|
85
|
+
attr_accessor :speed
|
86
|
+
|
87
|
+
def move_forward
|
88
|
+
schedule do |op|
|
89
|
+
motor_A.spin speed
|
90
|
+
motor_B.spin speed
|
91
|
+
end
|
92
|
+
end
|
86
93
|
|
87
|
-
|
94
|
+
def move_backward
|
95
|
+
schedule do
|
96
|
+
motor_A.spin 0 - speed
|
97
|
+
motor_B.spin 0 - speed
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def turn_left
|
102
|
+
schedule do
|
103
|
+
motor_A.spin speed
|
104
|
+
motor_B.spin 0 - speed
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def turn_right
|
109
|
+
schedule do
|
110
|
+
motor_A.spin 0 - speed
|
111
|
+
motor_B.spin speed
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def increase_speed
|
116
|
+
schedule do
|
117
|
+
if speed >=0 && speed <= 80
|
118
|
+
self.speed += 20
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def decrease_speed
|
124
|
+
schedule do
|
125
|
+
if speed > 20 && speed <= 100
|
126
|
+
self.speed -= 20
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def stop_motors
|
132
|
+
schedule do
|
133
|
+
motor_A.stop
|
134
|
+
motor_B.stop
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
|
140
|
+
bot.start do
|
141
|
+
bot.speed = 60
|
88
142
|
loop do
|
143
|
+
unless bot.sensor_3.distance == 0
|
144
|
+
puts "*****SENSOR DISTANCE:*****"
|
145
|
+
puts bot.sensor_3.distance
|
146
|
+
end
|
89
147
|
char = HighLine::SystemExtensions.get_character
|
90
148
|
case char.chr
|
91
149
|
when 'w'
|
92
|
-
bot.
|
93
|
-
bot.motor_B.spin speed
|
150
|
+
bot.move_forward
|
94
151
|
when 'd'
|
95
|
-
bot.
|
96
|
-
bot.motor_B.spin 0 - speed
|
152
|
+
bot.turn_left
|
97
153
|
when 'a'
|
98
|
-
bot.
|
99
|
-
bot.motor_B.spin speed
|
154
|
+
bot.turn_right
|
100
155
|
when 'x'
|
101
|
-
bot.
|
102
|
-
bot.motor_B.spin 0 - speed
|
156
|
+
bot.move_backward
|
103
157
|
when 'o'
|
104
|
-
|
105
|
-
speed += 20
|
106
|
-
end
|
158
|
+
bot.increase_speed
|
107
159
|
when 'l'
|
108
|
-
|
109
|
-
speed -= 20
|
110
|
-
end
|
160
|
+
bot.decrease_speed
|
111
161
|
when 'e', 'c', 'z', 'q'
|
112
|
-
bot.
|
113
|
-
bot.motor_B.stop
|
162
|
+
bot.stop_motors
|
114
163
|
end
|
115
|
-
sleep(5 / 1000)
|
116
164
|
end
|
117
165
|
end
|
118
166
|
```
|
@@ -140,3 +188,10 @@ See the scripts in the `examples` directory for more details.
|
|
140
188
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
141
189
|
4. Push to the branch (`git push origin my-new-feature`)
|
142
190
|
5. Create a new Pull Request
|
191
|
+
|
192
|
+
## Issues
|
193
|
+
|
194
|
+
I use HuBoard to manage GitHub issues. It's pretty awesome, check it out here:
|
195
|
+
|
196
|
+
https://huboard.com/tehviking/brick_pi_ruby/
|
197
|
+
|
data/lib/brick_pi/bot.rb
CHANGED
@@ -13,6 +13,7 @@ module BrickPi
|
|
13
13
|
Native.BrickPiSetup()
|
14
14
|
Native::Address[0] = 1
|
15
15
|
Native::Address[1] = 2
|
16
|
+
@queue = Queue.new
|
16
17
|
end
|
17
18
|
|
18
19
|
def start
|
@@ -20,24 +21,37 @@ module BrickPi
|
|
20
21
|
Native.ClearTick()
|
21
22
|
Native.Timeout = 50
|
22
23
|
Native.BrickPiSetTimeout()
|
23
|
-
|
24
24
|
Thread.new do
|
25
25
|
until @stop do
|
26
26
|
Native.BrickPiUpdateValues()
|
27
|
-
sleep
|
27
|
+
sleep 50/1000
|
28
|
+
end
|
29
|
+
end
|
30
|
+
Thread.new do
|
31
|
+
until @stop do
|
32
|
+
code = @queue.pop
|
33
|
+
begin
|
34
|
+
code.call
|
35
|
+
rescue => e
|
36
|
+
$stderr.puts e.message
|
37
|
+
$stderr.puts e.backtrace.join("\n")
|
38
|
+
end
|
28
39
|
end
|
29
40
|
end
|
41
|
+
Thread.new do
|
42
|
+
yield
|
43
|
+
end.join
|
44
|
+
stop
|
30
45
|
end
|
31
46
|
|
32
47
|
def stop
|
33
|
-
|
48
|
+
schedule do
|
49
|
+
@stop = true
|
50
|
+
end
|
34
51
|
end
|
35
52
|
|
36
|
-
def
|
37
|
-
|
38
|
-
yield
|
39
|
-
stop
|
53
|
+
def schedule(&block)
|
54
|
+
@queue.push block
|
40
55
|
end
|
41
|
-
|
42
56
|
end
|
43
57
|
end
|
data/lib/brick_pi/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brick-pi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Hays
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-09-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|