crubyflie 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -7
- data/bin/crubyflie +11 -3
- data/crubyflie.gemspec +1 -1
- data/examples/params_and_logging.rb +1 -1
- data/lib/crubyflie.rb +1 -1
- data/lib/crubyflie/crazyflie.rb +5 -7
- data/lib/crubyflie/crazyflie/commander.rb +1 -1
- data/lib/crubyflie/crazyflie/console.rb +1 -1
- data/lib/crubyflie/crazyflie/log.rb +1 -1
- data/lib/crubyflie/crazyflie/log_conf.rb +1 -1
- data/lib/crubyflie/crazyflie/param.rb +1 -1
- data/lib/crubyflie/crazyflie/toc.rb +1 -1
- data/lib/crubyflie/crazyflie/toc_cache.rb +1 -1
- data/lib/crubyflie/crazyradio/crazyradio.rb +1 -1
- data/lib/crubyflie/crazyradio/radio_ack.rb +1 -1
- data/lib/crubyflie/crubyflie_logger.rb +1 -1
- data/lib/crubyflie/driver/crtp_packet.rb +1 -1
- data/lib/crubyflie/driver/radio_driver.rb +29 -6
- data/lib/crubyflie/exceptions.rb +1 -1
- data/lib/crubyflie/input/input_reader.rb +1 -1
- data/lib/crubyflie/input/joystick_input_reader.rb +1 -1
- data/lib/crubyflie/version.rb +2 -2
- data/spec/commander_spec.rb +1 -1
- data/spec/console_spec.rb +1 -1
- data/spec/crazyflie_spec.rb +1 -2
- data/spec/crazyradio_spec.rb +1 -1
- data/spec/crtp_packet_spec.rb +1 -1
- data/spec/crubyflie_logger_spec.rb +1 -1
- data/spec/crubyflie_spec.rb +1 -1
- data/spec/input_reader_spec.rb +1 -1
- data/spec/joystick_input_reader_spec.rb +1 -1
- data/spec/log_spec.rb +1 -1
- data/spec/param_spec.rb +1 -1
- data/spec/radio_ack_spec.rb +1 -1
- data/spec/radio_driver_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -1
- data/spec/toc_cache_spec.rb +1 -1
- data/spec/toc_spec.rb +1 -1
- data/tools/sdl-joystick-axis.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: 08447332b055df7c6adb7b6fdbf17a0e90c409a4
|
4
|
+
data.tar.gz: fe925bfbfb26b505e06fdf09dcbc70e3c1928227
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97f8beddba2702aa515c6bfc94c08ac8538ecb2488b9542a8591a6e3a361a77059837db9ec78619625084a0310485eb8625c0c10058800c7fdccdb87c658424b
|
7
|
+
data.tar.gz: 438c227603fa2deccb6749bca207157be70d43bb3003181b9ea7f61be01f14f49b49d06ae039f6dfa3a36ff0bd1d00b42cce317c6f78dfeab6e663eef58c57f0
|
data/README.md
CHANGED
@@ -46,13 +46,14 @@ The easiest way to do it is to `gem install crubyflie` and then run the `crubyfl
|
|
46
46
|
|
47
47
|
> crubyflie -h
|
48
48
|
Options:
|
49
|
-
--joystick-id
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
49
|
+
-j, --joystick-id=<i> Joystick ID (default: 0)
|
50
|
+
-f, --cf-uri=<s> Crazyflie URI (defaults to first one found in scan)
|
51
|
+
-c, --config=<s> Joystick configuration, defaults to default cfg in configs/ (default: /path/to/joystick_default.yaml)
|
52
|
+
-r, --packet-retries=<i> Number of retries when copter fails to ack a packet (-1 == forever) (default: 100)
|
53
|
+
-d, --debug Enable debug messages
|
54
|
+
-h, --help Show this message
|
55
|
+
|
56
|
+
There is a [template/default configuration file](https://github.com/hsanjuan/crubyflie/blob/master/configs/joystick_default.yaml) with instructions (similar to PS3 standard assignments from the official app). You should modify this file to fit it to your needs (configuration parameters are well explained). The most tricky parameter in axis is the `:max_change_rate`. Depending on your controller, you will find the input is excessively throotled or not. I recommend that you play with this value.
|
56
57
|
|
57
58
|
If you are wondering about your Joystick's axis IDs, ranges etc, you will find a `sdl-joystick-axis.rb` script under `tools` that lets you open a joystick and check what the SDL library can read from it. It might come handy.
|
58
59
|
|
data/bin/crubyflie
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
# Copyright (C)
|
3
|
+
# Copyright (C) 2015 Hector Sanjuan
|
4
4
|
|
5
5
|
# This file is part of Crubyflie.
|
6
6
|
|
@@ -38,6 +38,10 @@ opts = Trollop::options do
|
|
38
38
|
:type => :string,
|
39
39
|
:default => Crubyflie::Joystick::DEFAULT_CONFIG_PATH,
|
40
40
|
:short => '-c')
|
41
|
+
opt(:packet_retries, "Number of retries when copter fails to ack a packet (-1 == forever)",
|
42
|
+
:type => :int,
|
43
|
+
:default => 100,
|
44
|
+
:short => '-r')
|
41
45
|
opt(:debug, "Enable debug messages",
|
42
46
|
:short => '-d')
|
43
47
|
end
|
@@ -45,7 +49,11 @@ end
|
|
45
49
|
include Crubyflie
|
46
50
|
$debug = true if opts[:debug]
|
47
51
|
|
48
|
-
|
52
|
+
radio_opts = {}
|
53
|
+
if r = opts[:packet_retries]
|
54
|
+
radio_opts[:retries_before_disconnect] = r
|
55
|
+
end
|
56
|
+
cf = Crazyflie.new('/tmp/crubyflie', radio_opts)
|
49
57
|
|
50
58
|
# Before opening any link, scan for interfaces
|
51
59
|
uris = cf.scan_interface
|
@@ -91,6 +99,6 @@ while cf.active? && !exit do
|
|
91
99
|
end
|
92
100
|
|
93
101
|
joystick.quit()
|
94
|
-
cf.close_link()
|
102
|
+
cf.close_link() if cf.active?
|
95
103
|
warn "\n"
|
96
104
|
logger.info("Bye bye!")
|
data/crubyflie.gemspec
CHANGED
data/lib/crubyflie.rb
CHANGED
data/lib/crubyflie/crazyflie.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
-
# Copyright (C)
|
2
|
+
# Copyright (C) 2015 Hector Sanjuan
|
3
3
|
|
4
4
|
# This file is part of Crubyflie.
|
5
5
|
|
@@ -50,12 +50,12 @@ module Crubyflie
|
|
50
50
|
|
51
51
|
attr_accessor :callbacks
|
52
52
|
attr_reader :cache_folder, :commander, :console, :param, :log
|
53
|
-
attr_reader :crtp_queues, :link
|
53
|
+
attr_reader :crtp_queues, :link, :radio_opts
|
54
54
|
# Initialize a Crazyflie by registering default received-packet
|
55
55
|
# callbacks and intializing Queues for every facility.
|
56
56
|
# Packets will be queued for each facility depending on their port
|
57
57
|
# @param cache_folder [String] folder path to store logging TOC cache
|
58
|
-
def initialize(cache_folder=nil)
|
58
|
+
def initialize(cache_folder=nil, radio_opts={})
|
59
59
|
@cache_folder = cache_folder
|
60
60
|
# Callbacks will fire in some specific situations
|
61
61
|
# Specially when receiving packages
|
@@ -83,6 +83,7 @@ module Crubyflie
|
|
83
83
|
@log = Log.new(self)
|
84
84
|
|
85
85
|
@link = nil
|
86
|
+
@radio_opts = radio_opts
|
86
87
|
end
|
87
88
|
|
88
89
|
|
@@ -97,7 +98,7 @@ module Crubyflie
|
|
97
98
|
:link_error_cb => @callbacks[:link][:error]
|
98
99
|
}
|
99
100
|
|
100
|
-
@link.connect(uri, link_cbs)
|
101
|
+
@link.connect(uri, link_cbs, @radio_opts)
|
101
102
|
@callbacks[:received_packet][:connected] = Proc.new do |packet|
|
102
103
|
logger.info "Connected!"
|
103
104
|
@callbacks[:received_packet].delete(:connected)
|
@@ -115,8 +116,6 @@ module Crubyflie
|
|
115
116
|
# Close the link and clean up
|
116
117
|
# Attemps to disconnect from the crazyflie.
|
117
118
|
def close_link
|
118
|
-
@commander.send_setpoint(0,0,0,0) if @link
|
119
|
-
sleep 0.05
|
120
119
|
uri = @link ? @link.uri.to_s : "nowhere"
|
121
120
|
@link.disconnect(force=true) if @link
|
122
121
|
@link = nil
|
@@ -263,7 +262,6 @@ module Crubyflie
|
|
263
262
|
logger.error "Link error: #{m}"
|
264
263
|
close_link()
|
265
264
|
end
|
266
|
-
|
267
265
|
end
|
268
266
|
private :register_default_callbacks
|
269
267
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
-
# Copyright (C)
|
2
|
+
# Copyright (C) 2015 Hector Sanjuan
|
3
3
|
|
4
4
|
# This file is part of Crubyflie.
|
5
5
|
|
@@ -150,6 +150,10 @@ module Crubyflie
|
|
150
150
|
@out_queue_max_size = opts[:out_queue_max_size] ||
|
151
151
|
OUT_QUEUE_MAX_SIZE
|
152
152
|
|
153
|
+
@retry_forever = @retries_before_disconnect < 0
|
154
|
+
m = "Radio driver will retry forever and never disconnect"
|
155
|
+
logger.warn(m) if @retry_forever
|
156
|
+
|
153
157
|
# Initialize Crazyradio and run thread
|
154
158
|
cradio_opts = {
|
155
159
|
:channel => channel,
|
@@ -180,9 +184,20 @@ module Crubyflie
|
|
180
184
|
def send_packet(packet)
|
181
185
|
return if !@crazyradio
|
182
186
|
if (s = @out_queue.size) >= @out_queue_max_size
|
183
|
-
|
184
|
-
|
185
|
-
|
187
|
+
if @retry_forever
|
188
|
+
m = "Outgoing queue full (#{s} elements) but retry_forever "
|
189
|
+
m << "enabled: clearing queue"
|
190
|
+
logger.warn(m)
|
191
|
+
@out_queue.clear()
|
192
|
+
else
|
193
|
+
m = "Reached maximum #{s} elements in outgoing queue"
|
194
|
+
@callbacks[:link_error_cb].call(m)
|
195
|
+
# Force shutdown, otherwise we will hit this error again
|
196
|
+
# and go into stack overflow
|
197
|
+
# (tecnnically, the link_error_cb should have made sure
|
198
|
+
# we are disconnected, but it does not hurt to re-do it)
|
199
|
+
disconnect(true)
|
200
|
+
end
|
186
201
|
end
|
187
202
|
|
188
203
|
@out_queue << packet if !@shutdown_thread
|
@@ -292,8 +307,14 @@ module Crubyflie
|
|
292
307
|
|
293
308
|
# Retry if we have not reached the limit
|
294
309
|
if !ack.ack
|
295
|
-
retries
|
296
|
-
|
310
|
+
# If we have retries left, or we always want to retry
|
311
|
+
if retries > 0 || @retry_forever
|
312
|
+
retries -= 1 if !@retry_forever
|
313
|
+
m = "No ack from copter: retries left #{retries}"
|
314
|
+
logger.debug(m)
|
315
|
+
next
|
316
|
+
end
|
317
|
+
# else just kill the thread
|
297
318
|
error = "Too many packets lost"
|
298
319
|
break
|
299
320
|
else
|
@@ -342,9 +363,11 @@ module Crubyflie
|
|
342
363
|
def kill_radio_thread(force=false)
|
343
364
|
if @radio_thread
|
344
365
|
if force
|
366
|
+
logger.debug("Killing radio thread")
|
345
367
|
@radio_thread.kill()
|
346
368
|
else
|
347
369
|
@shutdown_thread = true
|
370
|
+
logger.debug("Shutting down radio thread")
|
348
371
|
@radio_thread.join()
|
349
372
|
end
|
350
373
|
@radio_thread = nil
|
data/lib/crubyflie/exceptions.rb
CHANGED
data/lib/crubyflie/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
-
# Copyright (C)
|
2
|
+
# Copyright (C) 2015 Hector Sanjuan
|
3
3
|
|
4
4
|
# This file is part of Crubyflie.
|
5
5
|
|
@@ -18,5 +18,5 @@
|
|
18
18
|
|
19
19
|
module Crubyflie
|
20
20
|
# Current gem version
|
21
|
-
VERSION = "0.
|
21
|
+
VERSION = "0.3.0"
|
22
22
|
end
|
data/spec/commander_spec.rb
CHANGED
data/spec/console_spec.rb
CHANGED
data/spec/crazyflie_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
-
# Copyright (C)
|
2
|
+
# Copyright (C) 2015 Hector Sanjuan
|
3
3
|
|
4
4
|
# This file is part of Crubyflie.
|
5
5
|
|
@@ -96,7 +96,6 @@ describe Crazyflie do
|
|
96
96
|
|
97
97
|
describe "#close_link" do
|
98
98
|
it "should close the link" do
|
99
|
-
expect(@facility).to receive(:send_setpoint)
|
100
99
|
expect(@link).to receive(:disconnect)
|
101
100
|
m1 = "Connection initiated to radio://0/0/1M"
|
102
101
|
m2 = "Connection ready!"
|
data/spec/crazyradio_spec.rb
CHANGED
data/spec/crtp_packet_spec.rb
CHANGED
data/spec/crubyflie_spec.rb
CHANGED
data/spec/input_reader_spec.rb
CHANGED
data/spec/log_spec.rb
CHANGED
data/spec/param_spec.rb
CHANGED
data/spec/radio_ack_spec.rb
CHANGED
data/spec/radio_driver_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
-
# Copyright (C)
|
2
|
+
# Copyright (C) 2015 Hector Sanjuan
|
3
3
|
|
4
4
|
# This file is part of Crubyflie.
|
5
5
|
|
@@ -115,7 +115,7 @@ describe RadioDriver do
|
|
115
115
|
expect(@radiodriver).to receive(:start_radio_thread)
|
116
116
|
@radiodriver.connect(*@connect_params)
|
117
117
|
max = @radiodriver.out_queue_max_size
|
118
|
-
m = "Reached #{max} elements in outgoing queue"
|
118
|
+
m = "Reached maximum #{max} elements in outgoing queue"
|
119
119
|
# When it reaches 50 it disconnects and not send anymore
|
120
120
|
expect(@link_error_cb).to receive(:call).with(m).once
|
121
121
|
(1..52).each do
|
data/spec/spec_helper.rb
CHANGED
data/spec/toc_cache_spec.rb
CHANGED
data/spec/toc_spec.rb
CHANGED
data/tools/sdl-joystick-axis.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crubyflie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hector Sanjuan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: libusb
|