BBB 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,86 +0,0 @@
1
- require 'bbb'
2
-
3
- module Thunderball
4
- class Copter << BBB::Application
5
- ##
6
- # Use the BBB as the board, allows for possible ports to e.g. the Pi
7
- #
8
- board BBB::Board.new
9
-
10
- ##
11
- # Load the thunderball layout
12
- #
13
- layout Thunderball::Circuit.new
14
-
15
- attr_reader :stabalizer, :mover
16
-
17
- def initialize
18
- @stabalizer = Stabalizer.new(escs: escs,
19
- gyro: gyro,
20
- accelerometer: acc)
21
-
22
- @mover = Mover.new(escs: escs)
23
- end
24
-
25
- ##
26
- # Once start is called the run function will be called in a loop
27
- #
28
- def run
29
- stabalizer
30
- move(:forward=>20, :right=>10)
31
- end
32
-
33
- ##
34
- # Stabalize function is just syntactic sugar to make the run method look nice.
35
- #
36
- def stabilize
37
- stabalizer.update
38
- end
39
-
40
- ##
41
- # move function is just syntactic sugar to make the run method look nice.
42
- #
43
- def move
44
- mover.update
45
- end
46
- end # Copter
47
-
48
- class Circuit < BBB::Circuit
49
- def initialize
50
- attach_escs
51
- attach_led
52
- end
53
-
54
- def attach_escs
55
- attach ESC, :pins=>[:P8_1, :P8_2], :as=>:esc_1, :group=>:escs
56
- attach ESC, :pins=>[:P9_1, :P9_2], :as=>:esc_2, :group=>:escs
57
- end
58
-
59
- def attach_leds
60
- attach Led, :pin=>:P9_12
61
- end
62
- end # Circuit
63
-
64
- class Mover
65
- def initialize(opts={})
66
- @escs = opts[:escs]
67
- end
68
-
69
- def move
70
- # Do some complex logic here with the escs
71
- end
72
- end # Mover
73
-
74
- def Stabalizer
75
- def initialize(opts={})
76
- @escs = opts[:escs]
77
- @gyo = opts[:gyro]
78
- @accelerometer = opts[:accelerometer]
79
- end
80
-
81
- def stabalize
82
- # Do someting complex with all the components
83
- # and update all values
84
- end
85
- end #Stabalizer
86
- end
@@ -1,40 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Blinking a Led" do
4
-
5
- ##
6
- # Setup the actual Application
7
- #
8
- class LedExampleApplication < BBB::Application
9
- # Connect the led
10
- attach BBB::Components::Led, as: :led
11
-
12
- def initialize
13
- led.connect(:P8_10, mock: true)
14
- end
15
-
16
- # This is the basic run loop
17
- def run
18
- led.on! # this does what you think it does
19
- sleep(1) # sleep for 1 second, kind of blunt, since it blocks everthing.
20
- led.off!
21
- sleep(1)
22
- end
23
- end
24
-
25
- # Initialize and run the LedExampleApplication
26
-
27
- it "should initialize" do
28
- lambda{ LedExampleApplication.new}.should_not raise_error
29
- end
30
-
31
- it "should respond to led" do
32
- app = LedExampleApplication.new
33
- app.respond_to?(:led).should be_true
34
- end
35
-
36
- it "should be able to turn led on" do
37
- app = LedExampleApplication.new
38
- lambda {app.led.on!}.should_not raise_error
39
- end
40
- end