crubyflie 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dcb4305a5d9ca33ec60adc1e2ac1efa103a270c3
4
- data.tar.gz: 8a32e7d1490631d90684e2d7374abc87c0acc9c1
3
+ metadata.gz: c53014aa0e2af1f0f401853e934227e5f2950f38
4
+ data.tar.gz: 6729d96811026479a1a0984aa1316506be35af75
5
5
  SHA512:
6
- metadata.gz: 2e692d61776ec93d8d934a9db2c6ac3119fe52b9793448ff1568c1ceae964963a27c554cac2dc62f83e53958b08cbb10e7ac26291de6f6664a5745a348840800
7
- data.tar.gz: ab59aedbfb39348edbc44f5cde67866cd91f54c233fb94d071e4eed71407732948b115e1494b370bb49abc3f7d11dfdf0a53920b579a871fc027cf4e3fd1674b
6
+ metadata.gz: 81452b7995d89199f233b55c132bded7b8790875754d020ada0831bef8cf9b100b4aa439c4ae340b197e8a3a3add072d9ee9cfb19ffbabc8d278b7bb35641cfe
7
+ data.tar.gz: a4ca9a64c904644c1dd756c77a9f47875da126cc1ea72844b2a5a191ec2d849481645c33e64f733054df54425c04e1faeb3fe6dbd84f0d361f6e4f90fb7ca01f
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - 2.0.0
6
+ before_install:
7
+ - sudo apt-get update -qq
8
+ - sudo apt-get install -qq libsdl1.2-dev
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
- Crubyflie - A Ruby client and libraries for Crazyflie
2
- =====================================================
1
+ Crubyflie - A Ruby client for Crazyflie
2
+ =======================================
3
+
4
+ [![Build Status](https://travis-ci.org/hsanjuan/crubyflie.png?branch=master)](https://travis-ci.org/hsanjuan/crubyflie) [![Coverage Status](https://coveralls.io/repos/hsanjuan/crubyflie/badge.png)](https://coveralls.io/r/hsanjuan/crubyflie)
3
5
 
4
6
  Crubyflie is a Ruby rewrite of the [Crazyflie quadcopter](http://www.bitcraze.se/category/crazyflie/) Python [client libraries](https://bitbucket.org/bitcraze/crazyflie-pc-client), with some customizations.
5
7
 
data/crubyflie.gemspec CHANGED
@@ -47,4 +47,5 @@ EOF
47
47
  spec.add_development_dependency "rspec"
48
48
  spec.add_development_dependency "yard"
49
49
  spec.add_development_dependency "simplecov"
50
+ spec.add_development_dependency "coveralls"
50
51
  end
@@ -285,7 +285,7 @@ module Crubyflie
285
285
  sleep 0.2
286
286
  else
287
287
  logger.debug("Log on #{packet.channel}. Cannot handle")
288
- ## @in_queue << packet
288
+ ## in_queue << packet
289
289
  end
290
290
  end
291
291
  end
@@ -18,13 +18,43 @@
18
18
 
19
19
 
20
20
  require 'thread'
21
- require 'uri'
22
21
 
23
22
  require 'exceptions'
24
23
  require 'driver/crtp_packet'
25
24
  require 'crazyradio/crazyradio'
26
25
 
26
+
27
+
27
28
  module Crubyflie
29
+ # Small URI class since Ruby URI < 1.9.3 gives problems parsing
30
+ # Crazyflie URIs
31
+ class CrubyflieURI
32
+ attr_reader :scheme, :dongle, :channel, :rate
33
+ # Initialize an URI
34
+ # @param uri_str [String] the URI
35
+ def initialize(uri_str)
36
+ @uri_str = uri_str
37
+ @scheme, @dongle, @channel, @rate = split()
38
+ if @scheme.nil? || @dongle.nil? || @channel.nil? || @rate.nil? ||
39
+ @scheme != 'radio'
40
+ raise InvalidURIException.new('Bad URI')
41
+ end
42
+ end
43
+
44
+ # Return URI as string
45
+ # @return [String] a string representation of the URI
46
+ def to_s
47
+ @uri_str
48
+ end
49
+
50
+ # Quick, dirty uri split
51
+ def split
52
+ @uri_str.sub(':', '').sub('//','/').split('/')
53
+ end
54
+ private :split
55
+ end
56
+
57
+
28
58
  # This layer takes care of connecting to the crazyradio and
29
59
  # managing the incoming and outgoing queues. This is done
30
60
  # by spawing a thread.
@@ -64,7 +94,7 @@ module Crubyflie
64
94
  # :out_queue_max_size (defaults to 50)
65
95
  # @raise [CallbackMissing] when a necessary callback is not provided
66
96
  # (see CALLBACKS constant values)
67
- # @raise [InvalidURIType] when the URI is not a valid radio URI
97
+ # @raise [InvalidURIException] when the URI is not a valid radio URI
68
98
  # @raise [OpenLink] when a link is already open
69
99
  def connect(uri_s, callbacks={}, opts={})
70
100
  # Check if apparently there is an open link
@@ -76,12 +106,12 @@ module Crubyflie
76
106
 
77
107
  # Parse URI to initialize Crazyradio
78
108
  # @todo: better control input. It defaults to 0
79
- @uri = URI(uri_s)
80
- dongle_number = @uri.host.to_i
81
- channel, rate = @uri.path.split('/')[1..-1] # remove leading /
82
- channel = channel.to_i
83
- # @todo this should be taken care of in crazyradio
109
+ @uri = CrubyflieURI.new(uri_s)
110
+ dongle_number = @uri.dongle.to_i
111
+ channel = @uri.channel.to_i
112
+ rate = @uri.rate
84
113
 
114
+ # @todo this should be taken care of in crazyradio
85
115
  case rate
86
116
  when "250K"
87
117
  rate = CrazyradioConstants::DR_250KPS
@@ -90,7 +120,7 @@ module Crubyflie
90
120
  when "2M"
91
121
  rate = CrazyradioConstants::DR_2MPS
92
122
  else
93
- raise InvalidURIType.new("Bad radio rate")
123
+ raise InvalidURIException.new("Bad radio rate")
94
124
  end
95
125
 
96
126
  # Fill in the callbacks Hash
@@ -18,7 +18,7 @@
18
18
 
19
19
  module Crubyflie
20
20
  # Raised when the radio URI is invalid
21
- class InvalidURIType < Exception; end
21
+ class InvalidURIException < Exception; end
22
22
  # Raised when an radio link is already open
23
23
  class OpenLink < Exception; end
24
24
  # Raised when a radio driver callback parameter is missing
@@ -268,8 +268,8 @@ module Crubyflie
268
268
  # @return [Float] the linear-corresponding value in the destination
269
269
  # range
270
270
  def normalize(value, from_range, to_range)
271
- from_w = from_range.size.to_f - 1
272
- to_w = to_range.size.to_f - 1
271
+ from_w = from_range.to_a.size.to_f - 1
272
+ to_w = to_range.to_a.size.to_f - 1
273
273
  from_min = from_range.first.to_f
274
274
  to_min = to_range.first.to_f
275
275
  # puts "#{to_min}+(#{value.to_f}-#{from_min})*(#{to_w}/#{from_w})
@@ -18,5 +18,5 @@
18
18
 
19
19
  module Crubyflie
20
20
  # Current gem version
21
- VERSION = "0.1.0"
21
+ VERSION = "0.1.1"
22
22
  end
@@ -38,7 +38,7 @@ describe Crazyflie do
38
38
  allow(@link).to receive(:connect)
39
39
  allow(@link).to receive(:disconnect)
40
40
  allow(@link).to receive(:receive_packet)
41
- allow(@link).to receive(:uri).and_return(URI(@uri))
41
+ allow(@link).to receive(:uri).and_return(CrubyflieURI.new(@uri))
42
42
 
43
43
  #allow_any_instance_of(CrubyflieLogger).to receive(:info)
44
44
 
@@ -106,16 +106,18 @@ describe Crazyradio do
106
106
 
107
107
  describe "#factory" do
108
108
  it "should raise an exception if no dongles are found" do
109
- do_this = receive(:devices).and_return([])
110
- allow_any_instance_of(LIBUSB::Context).to do_this
109
+ context = double("Context")
110
+ expect(LIBUSB::Context).to receive(:new).and_return(context)
111
+ expect(context).to receive(:devices).and_return([])
111
112
 
112
113
  expect { Crazyradio.factory() }.to raise_error(USBDongleException,
113
114
  "No dongles found")
114
115
  end
115
116
 
116
117
  it "should provide a new crazyradio item" do
117
- do_this = receive(:devices).and_return([@device])
118
- allow_any_instance_of(LIBUSB::Context).to do_this
118
+ context = double("Context")
119
+ expect(LIBUSB::Context).to receive(:new).and_return(context)
120
+ expect(context).to receive(:devices).and_return([@device])
119
121
  Crazyradio.factory()
120
122
  end
121
123
  end
@@ -16,5 +16,6 @@
16
16
  # You should have received a copy of the GNU General Public License
17
17
  # along with Crubyflie. If not, see <http://www.gnu.org/licenses/>
18
18
 
19
+ $: << File.dirname(__FILE__)
19
20
  require 'rspec'
20
- require_relative 'spec_helper'
21
+ require 'spec_helper'
data/spec/spec_helper.rb CHANGED
@@ -17,6 +17,8 @@
17
17
  # along with Crubyflie. If not, see <http://www.gnu.org/licenses/>
18
18
 
19
19
  require 'simplecov'
20
+ require 'coveralls'
21
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
20
22
  SimpleCov.at_exit do
21
23
  SimpleCov.minimum_coverage 95
22
24
  SimpleCov.result.format!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crubyflie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hector Sanjuan
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - '>='
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: coveralls
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  description: |
126
140
  Client library to control a Crazyflie. This library allows to talk to a
127
141
  crazyflie using the USB radio dongle.
@@ -133,6 +147,7 @@ extensions: []
133
147
  extra_rdoc_files: []
134
148
  files:
135
149
  - .gitignore
150
+ - .travis.yml
136
151
  - Gemfile
137
152
  - LICENSE.txt
138
153
  - README.md