hybridgroup-crubyflie 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.travis.yml +8 -0
  4. data/Gemfile +5 -0
  5. data/LICENSE.txt +674 -0
  6. data/README.md +127 -0
  7. data/Rakefile +15 -0
  8. data/bin/crubyflie +94 -0
  9. data/configs/joystick_default.yaml +106 -0
  10. data/crubyflie.gemspec +50 -0
  11. data/examples/params_and_logging.rb +87 -0
  12. data/lib/crubyflie/crazyflie/commander.rb +54 -0
  13. data/lib/crubyflie/crazyflie/console.rb +67 -0
  14. data/lib/crubyflie/crazyflie/log.rb +383 -0
  15. data/lib/crubyflie/crazyflie/log_conf.rb +57 -0
  16. data/lib/crubyflie/crazyflie/param.rb +220 -0
  17. data/lib/crubyflie/crazyflie/toc.rb +239 -0
  18. data/lib/crubyflie/crazyflie/toc_cache.rb +87 -0
  19. data/lib/crubyflie/crazyflie.rb +282 -0
  20. data/lib/crubyflie/crazyradio/crazyradio.rb +301 -0
  21. data/lib/crubyflie/crazyradio/radio_ack.rb +48 -0
  22. data/lib/crubyflie/crubyflie_logger.rb +74 -0
  23. data/lib/crubyflie/driver/crtp_packet.rb +146 -0
  24. data/lib/crubyflie/driver/radio_driver.rb +363 -0
  25. data/lib/crubyflie/exceptions.rb +36 -0
  26. data/lib/crubyflie/input/input_reader.rb +190 -0
  27. data/lib/crubyflie/input/joystick_input_reader.rb +328 -0
  28. data/lib/crubyflie/version.rb +22 -0
  29. data/lib/crubyflie.rb +36 -0
  30. data/spec/commander_spec.rb +67 -0
  31. data/spec/console_spec.rb +76 -0
  32. data/spec/crazyflie_spec.rb +176 -0
  33. data/spec/crazyradio_spec.rb +228 -0
  34. data/spec/crtp_packet_spec.rb +79 -0
  35. data/spec/crubyflie_logger_spec.rb +39 -0
  36. data/spec/crubyflie_spec.rb +21 -0
  37. data/spec/input_reader_spec.rb +136 -0
  38. data/spec/joystick_cfg.yaml +44 -0
  39. data/spec/joystick_input_reader_spec.rb +323 -0
  40. data/spec/log_spec.rb +266 -0
  41. data/spec/param_spec.rb +166 -0
  42. data/spec/radio_ack_spec.rb +43 -0
  43. data/spec/radio_driver_spec.rb +227 -0
  44. data/spec/spec_helper.rb +53 -0
  45. data/spec/toc_cache_spec.rb +87 -0
  46. data/spec/toc_spec.rb +187 -0
  47. data/tools/sdl-joystick-axis.rb +69 -0
  48. metadata +225 -0
data/spec/toc_spec.rb ADDED
@@ -0,0 +1,187 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2013 Hector Sanjuan
3
+
4
+ # This file is part of Crubyflie.
5
+
6
+ # Crubyflie is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+
11
+ # Crubyflie is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Crubyflie. If not, see <http://www.gnu.org/licenses/>
18
+
19
+ require 'crazyflie/toc'
20
+
21
+ describe TOCElement do
22
+ describe "#initialize" do
23
+ it "should assign the variables correctly" do
24
+ te = TOCElement.new({
25
+ :ident => 1,
26
+ :group => 2,
27
+ :name => 3,
28
+ :ctype => 4,
29
+ :directive => 'C*',
30
+ :access => 6
31
+ })
32
+ te.ident.should == 1
33
+ te.group.should == 2
34
+ te.name.should == 3
35
+ te.ctype.should == 4
36
+ te.directive.should == 'C*'
37
+ te.access.should == 6
38
+ end
39
+ end
40
+ end
41
+
42
+ describe TOC do
43
+ before :each do
44
+ @cache = double("TOCCache")
45
+ allow(TOCCache).to receive(:new).and_return(@cache)
46
+ @toc = TOC.new()
47
+ @element = TOCElement.new({
48
+ :ident => 1,
49
+ :group => "mygroup",
50
+ :name => "myname",
51
+ :ctype => 4,
52
+ :rtype => 5,
53
+ :access => 6
54
+ })
55
+ @logger = @toc.logger
56
+ end
57
+
58
+ describe "#initialize" do
59
+ it "should setup the cache" do
60
+ expect(TOCCache).to receive(:new).with('abc')
61
+ toc = TOC.new('abc')
62
+ end
63
+ end
64
+
65
+ describe "#[]" do
66
+ it "should find an element by name only" do
67
+ @toc.insert(@element)
68
+ @toc["myname",:by_name].should == @element
69
+ @toc["mygroup.myname",:by_name].should == @element
70
+ @toc[1,:by_name].should be_nil
71
+ end
72
+
73
+ it "should find an element by id only" do
74
+ @toc.insert(@element)
75
+ @toc["myname",:by_id].should be_nil
76
+ @toc[1,:by_id].should == @element
77
+ end
78
+
79
+ it "should find an element by both name and id" do
80
+ @toc.insert(@element)
81
+ @toc["myname"].should == @element
82
+ @toc[1].should == @element
83
+ end
84
+
85
+ it "should return nil when the element is not found" do
86
+ @toc.insert(@element)
87
+ @toc["baa"].should be_nil
88
+ end
89
+ end
90
+
91
+ describe "#insert" do
92
+ it "should insert correctly an element" do
93
+ @toc[1].should be_nil
94
+ @toc.insert(@element)
95
+ @toc[1].should == @element
96
+ end
97
+ end
98
+
99
+ describe "#import/#export" do
100
+ it "should import and export" do
101
+ expect(@cache).to receive(:insert).with('abc', @toc.toc)
102
+ expect(@cache).to receive(:fetch).with('abc').and_return({:a => 3})
103
+
104
+ @toc.insert(@element)
105
+ @toc.export_to_cache('abc')
106
+ @toc.import_from_cache('abc')
107
+ @toc.toc.should == {:a => 3}
108
+ end
109
+ end
110
+
111
+ describe "#fetch_from_crazyflie" do
112
+ it "should import from cache when the TOC is in it" do
113
+ cf = double("Crazyflie")
114
+ queue = Queue.new
115
+ resp = CRTPPacket.new()
116
+ resp.modify_header(nil, 0, TOC_CHANNEL)
117
+ resp.data = [0, 5, 0x01, 0x00, 0x00, 0x00, 0x00]
118
+ bad_resp = CRTPPacket.new()
119
+ bad_resp.modify_header(nil, 0, 33)
120
+
121
+ allow(@cache).to receive(:fetch).and_return({:abc => "def"}).once
122
+
123
+ expect(queue).to receive(:pop).and_return(bad_resp, resp).twice
124
+ expect(queue).to receive(:<<).with(bad_resp)
125
+ expect(cf).to receive(:send_packet).with(anything, true).once
126
+ m = "Got a non-TOC packet. Requeueing..."
127
+ m2 = "TOC crc #{1}, 5 items"
128
+ m3 = "TOC found in cache"
129
+ expect(@logger).to receive(:debug).with(m)
130
+ expect(@logger).to receive(:debug).with(m2)
131
+ expect(@logger).to receive(:debug).with(m3)
132
+
133
+ @toc.fetch_from_crazyflie(cf, 0, queue)
134
+ end
135
+
136
+ it "should request the elements in the TOC when it is not in cache" do
137
+ cf = double("Crazyflie")
138
+ queue = Queue.new
139
+ resp = CRTPPacket.new()
140
+ resp.modify_header(nil, 0, TOC_CHANNEL)
141
+ resp.data = [0, 5, 0x01, 0x00, 0x00, 0x00, 0x00]
142
+
143
+ resp_elem = CRTPPacket.new()
144
+ resp_elem.modify_header(nil, 0, TOC_CHANNEL)
145
+ resp_elem.data = [0, 0, 0xFF, 0xFF]
146
+
147
+ allow(@cache).to receive(:fetch).and_return(nil).once
148
+
149
+ do_this = receive(:pop).and_return(resp,
150
+ resp_elem).exactly(6).times
151
+ expect(queue).to do_this
152
+ expect(cf).to receive(:send_packet).with(anything,
153
+ true).exactly(6).times
154
+
155
+ mw = "Not in cache"
156
+ m = "TOC crc 1, 5 items"
157
+ m0 = "Added 0 to TOC"
158
+ m1 = "Added 1 to TOC"
159
+ m2 = "Added 2 to TOC"
160
+ m3 = "Added 3 to TOC"
161
+ m4 = "Added 4 to TOC"
162
+
163
+ expect(@logger).to receive(:debug).with(mw)
164
+ expect(@logger).to receive(:debug).with(m)
165
+ expect(@logger).to receive(:debug).with(m0)
166
+ expect(@logger).to receive(:debug).with(m1)
167
+ expect(@logger).to receive(:debug).with(m2)
168
+ expect(@logger).to receive(:debug).with(m3)
169
+ expect(@logger).to receive(:debug).with(m4)
170
+
171
+ one = { :ident => 0 }
172
+ two = { :ident => 1 }
173
+ three = { :ident => 2 }
174
+ four = { :ident => 3 }
175
+ five = { :ident => 4 }
176
+ allow(TOCElement).to receive(:new).and_return(
177
+ TOCElement.new(one),
178
+ TOCElement.new(two),
179
+ TOCElement.new(three),
180
+ TOCElement.new(four),
181
+ TOCElement.new(five))
182
+
183
+ expect(@cache).to receive(:insert).with("1", anything)
184
+ @toc.fetch_from_crazyflie(cf, 0, queue)
185
+ end
186
+ end
187
+ end
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright (C) 2013 Hector Sanjuan
3
+
4
+ # This file is part of Crubyflie.
5
+
6
+ # Crubyflie is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+
11
+ # Crubyflie is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Crubyflie. If not, see <http://www.gnu.org/licenses/>
18
+
19
+ # A simple script to list SDL axis/button numbering and read values
20
+
21
+ require 'sdl'
22
+ require 'pp'
23
+
24
+ warn "Welcome to Crubyflie joystick utility. Ctrl-C to exit."
25
+ warn "--"
26
+ Signal.trap("SIGINT") do
27
+ warn "\n\n"
28
+ warn "Bye bye!"
29
+ SDL.quit
30
+ exit 0
31
+ end
32
+
33
+ SDL.init(SDL::INIT_JOYSTICK)
34
+ n_joy = SDL::Joystick.num
35
+ if n_joy == 0
36
+ warn "No joysticks found"
37
+ exit 1
38
+ end
39
+
40
+
41
+ warn "Total number of Joysticks: #{n_joy}"
42
+ n_joy.times do |i|
43
+ warn "#{i}: #{SDL::Joystick.index_name(i)}"
44
+ end
45
+ warn "--"
46
+ print "Which one should we use (0-#{n_joy-1}): "
47
+ joy_id = gets.to_i
48
+ joy = SDL::Joystick.open(joy_id)
49
+ warn "Opened Joystick #{joy_id}"
50
+ warn "Name: SDL::Joystick.index_name(#{joy_id})"
51
+ warn "Number of Axes: #{joy.num_axes}"
52
+ warn "Number of buttons: #{joy.num_buttons}"
53
+ warn "Here is the reading for axis and buttons:"
54
+ loop {
55
+ SDL::Joystick.update_all
56
+ joy.num_axes.times do |i|
57
+ print "A##{i}: #{joy.axis(i)} | "
58
+ end
59
+
60
+ print " || "
61
+
62
+ button_read = []
63
+ joy.num_buttons.times do |i|
64
+ print "B##{i}: #{joy.button(i) ? 1 : 0} | "
65
+ end
66
+ print "\r"
67
+ $stdout.flush
68
+ sleep 0.05
69
+ }
metadata ADDED
@@ -0,0 +1,225 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hybridgroup-crubyflie
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: ruby
6
+ authors:
7
+ - Hector Sanjuan
8
+ - Adrian Zankich
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: libusb
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: trollop
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: '1.3'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: '1.3'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: yard
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: simplecov
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: coveralls
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: |
127
+ Client library to control a Crazyflie. This library allows to talk to a
128
+ crazyflie using the USB radio dongle.
129
+ email:
130
+ - hector@convivencial.org
131
+ - adrian@hybridgroup.com
132
+ executables:
133
+ - crubyflie
134
+ extensions: []
135
+ extra_rdoc_files: []
136
+ files:
137
+ - .gitignore
138
+ - .travis.yml
139
+ - Gemfile
140
+ - LICENSE.txt
141
+ - README.md
142
+ - Rakefile
143
+ - bin/crubyflie
144
+ - configs/joystick_default.yaml
145
+ - crubyflie.gemspec
146
+ - examples/params_and_logging.rb
147
+ - lib/crubyflie.rb
148
+ - lib/crubyflie/crazyflie.rb
149
+ - lib/crubyflie/crazyflie/commander.rb
150
+ - lib/crubyflie/crazyflie/console.rb
151
+ - lib/crubyflie/crazyflie/log.rb
152
+ - lib/crubyflie/crazyflie/log_conf.rb
153
+ - lib/crubyflie/crazyflie/param.rb
154
+ - lib/crubyflie/crazyflie/toc.rb
155
+ - lib/crubyflie/crazyflie/toc_cache.rb
156
+ - lib/crubyflie/crazyradio/crazyradio.rb
157
+ - lib/crubyflie/crazyradio/radio_ack.rb
158
+ - lib/crubyflie/crubyflie_logger.rb
159
+ - lib/crubyflie/driver/crtp_packet.rb
160
+ - lib/crubyflie/driver/radio_driver.rb
161
+ - lib/crubyflie/exceptions.rb
162
+ - lib/crubyflie/input/input_reader.rb
163
+ - lib/crubyflie/input/joystick_input_reader.rb
164
+ - lib/crubyflie/version.rb
165
+ - spec/commander_spec.rb
166
+ - spec/console_spec.rb
167
+ - spec/crazyflie_spec.rb
168
+ - spec/crazyradio_spec.rb
169
+ - spec/crtp_packet_spec.rb
170
+ - spec/crubyflie_logger_spec.rb
171
+ - spec/crubyflie_spec.rb
172
+ - spec/input_reader_spec.rb
173
+ - spec/joystick_cfg.yaml
174
+ - spec/joystick_input_reader_spec.rb
175
+ - spec/log_spec.rb
176
+ - spec/param_spec.rb
177
+ - spec/radio_ack_spec.rb
178
+ - spec/radio_driver_spec.rb
179
+ - spec/spec_helper.rb
180
+ - spec/toc_cache_spec.rb
181
+ - spec/toc_spec.rb
182
+ - tools/sdl-joystick-axis.rb
183
+ homepage: https://github.com/hybridgroup/crubyflie
184
+ licenses:
185
+ - GPLv3
186
+ metadata: {}
187
+ post_install_message:
188
+ rdoc_options: []
189
+ require_paths:
190
+ - lib
191
+ required_ruby_version: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - '>='
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ required_rubygems_version: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - '>='
199
+ - !ruby/object:Gem::Version
200
+ version: '0'
201
+ requirements: []
202
+ rubyforge_project:
203
+ rubygems_version: 2.1.5
204
+ signing_key:
205
+ specification_version: 4
206
+ summary: A Ruby client for the Crazyflie quadcopter
207
+ test_files:
208
+ - spec/commander_spec.rb
209
+ - spec/console_spec.rb
210
+ - spec/crazyflie_spec.rb
211
+ - spec/crazyradio_spec.rb
212
+ - spec/crtp_packet_spec.rb
213
+ - spec/crubyflie_logger_spec.rb
214
+ - spec/crubyflie_spec.rb
215
+ - spec/input_reader_spec.rb
216
+ - spec/joystick_cfg.yaml
217
+ - spec/joystick_input_reader_spec.rb
218
+ - spec/log_spec.rb
219
+ - spec/param_spec.rb
220
+ - spec/radio_ack_spec.rb
221
+ - spec/radio_driver_spec.rb
222
+ - spec/spec_helper.rb
223
+ - spec/toc_cache_spec.rb
224
+ - spec/toc_spec.rb
225
+ has_rdoc: