crazyflie-zmq 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/crazyflie-zmq.gemspec +1 -1
- data/lib/crazyflie-zmq.rb +51 -30
- data/lib/crazyflie-zmq/version.rb +3 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: becf8bb70389291899c7fc7981149452d71a3eaef0a3219dfc5a2ddc54d80de7
|
4
|
+
data.tar.gz: 42919fa2747ac3573a8a6bb616401d7268fe363b9e9e1144d6e8171e1513351c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f21262a12bc94fc5516cdbb275801a4a6ac1d4a60f19d06e8235e4daf6a5aded83137673d61695d5734e52d850ca4bed583e4961d8c41efc4f2bbe267cb5069a
|
7
|
+
data.tar.gz: 1d42be892edecaf4b7a66a33a85b9a20bec5d7f1b086aa96296b1c9effb23923448b771efa8963a8d3fc956b2de8eaaabd81ead658eb1c57184b40c841cc482a
|
data/crazyflie-zmq.gemspec
CHANGED
data/lib/crazyflie-zmq.rb
CHANGED
@@ -5,6 +5,8 @@ require 'json'
|
|
5
5
|
require 'csv'
|
6
6
|
require 'ffi-rzmq'
|
7
7
|
|
8
|
+
require_relative 'crazyflie-zmq/version'
|
9
|
+
|
8
10
|
|
9
11
|
# Allow control of a {https://www.bitcraze.io/crazyflie-2/ Crazyflie}
|
10
12
|
# drone using the ZMQ protocol.
|
@@ -16,13 +18,24 @@ require 'ffi-rzmq'
|
|
16
18
|
#
|
17
19
|
# crazyflie-clients-python/bin/cfzmq --url tcp://* -d
|
18
20
|
#
|
21
|
+
# Small demonstration:
|
22
|
+
#
|
23
|
+
# $cf = CrazyflieZMQ.new('tcp://_ip_address_') # Connect to ZMQ sockets
|
24
|
+
# $cf.connect('radio://0/80/1M/E7E7E7E7E7') # Connect to drone
|
25
|
+
# $cf.log_create(:range, # Create log block
|
26
|
+
# 'ranging.distance0', 'ranging.distance1', 'ranging.distance2')
|
27
|
+
# $cf['posCtlPid','xKp']= 1.0 # Parameter (group, name notation)
|
28
|
+
# $cf['posCtlPid.yKp' ]= 1.0 # Paramerer (name dotted notation)
|
29
|
+
# $cf.log_start(:range, file: :csv) # Log to csv generated file
|
30
|
+
# sleep(120) # Wait 2 minutes
|
31
|
+
# $cf.log_stop(:range) # Stop logging of :range
|
32
|
+
# $cf.disconnect # Disconnect from drone
|
33
|
+
#
|
19
34
|
# @see https://wiki.bitcraze.io/doc:crazyflie:client:cfzmq:index
|
20
35
|
# @see https://wiki.bitcraze.io/doc:crazyflie:dev:arch:logparam
|
21
36
|
# @see https://wiki.bitcraze.io/projects:crazyflie:firmware:comm_protocol
|
22
37
|
# @see https://wiki.bitcraze.io/doc:crazyflie:crtp:log
|
23
38
|
class CrazyflieZMQ
|
24
|
-
VERSION = "0.1.1" # CrazyflieZMQ version
|
25
|
-
|
26
39
|
# Standard error for {CrazyflieZMQ}
|
27
40
|
class Error < StandardError ; end
|
28
41
|
|
@@ -38,7 +51,7 @@ class CrazyflieZMQ
|
|
38
51
|
|
39
52
|
|
40
53
|
|
41
|
-
# Create a CrazyflieZMQ instance
|
54
|
+
# Create a {CrazyflieZMQ} instance
|
42
55
|
#
|
43
56
|
# @param url [String] the url to connect to the ZMQ socket
|
44
57
|
def initialize(url, log: nil)
|
@@ -49,9 +62,9 @@ class CrazyflieZMQ
|
|
49
62
|
@log_count = {}
|
50
63
|
@log_blocks = nil
|
51
64
|
|
52
|
-
@param
|
53
|
-
@log
|
54
|
-
@connected
|
65
|
+
@param = {}
|
66
|
+
@log = {}
|
67
|
+
@connected = nil
|
55
68
|
|
56
69
|
@ctx = ZMQ::Context.create(1)
|
57
70
|
|
@@ -69,7 +82,7 @@ class CrazyflieZMQ
|
|
69
82
|
loop {
|
70
83
|
data = ''
|
71
84
|
@param_sock.recv_string(data)
|
72
|
-
resp = JSON.parse(data)
|
85
|
+
resp = JSON.parse(_json_fix(data))
|
73
86
|
version = resp.delete('version' )
|
74
87
|
name = resp.delete('name' )
|
75
88
|
value = resp.delete('value' )
|
@@ -89,7 +102,7 @@ class CrazyflieZMQ
|
|
89
102
|
loop {
|
90
103
|
data = ''
|
91
104
|
@log_sock.recv_string(data)
|
92
|
-
resp = JSON.parse(data)
|
105
|
+
resp = JSON.parse(_json_fix(data))
|
93
106
|
version = resp.delete('version' )
|
94
107
|
event = resp.delete('event' ).to_sym
|
95
108
|
name = resp.delete('name' ).to_sym
|
@@ -105,8 +118,9 @@ class CrazyflieZMQ
|
|
105
118
|
|
106
119
|
|
107
120
|
# Returns the list of available crazyflie
|
121
|
+
# @return [Array<Hash{String=>String}>] list of available interfaces
|
108
122
|
def scan()
|
109
|
-
_request(cmd: :scan)
|
123
|
+
_request(cmd: :scan).dig('interfaces')
|
110
124
|
end
|
111
125
|
|
112
126
|
|
@@ -117,23 +131,23 @@ class CrazyflieZMQ
|
|
117
131
|
# @return [self]
|
118
132
|
def connect(uri, log_blocks: nil)
|
119
133
|
toc = _request(cmd: :connect, uri: uri)
|
120
|
-
@param
|
121
|
-
@log
|
122
|
-
@connected
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
+
@param = toc['param'] || {}
|
135
|
+
@log = toc['log' ] || {}
|
136
|
+
@connected = Time.now.freeze
|
137
|
+
@log_blocks = log_blocks
|
138
|
+
|
139
|
+
@log_blocks&.each {|key, data|
|
140
|
+
variables, period =
|
141
|
+
case data
|
142
|
+
when Hash then [ data[:variables], data[:period] ]
|
143
|
+
when Array then [ data ]
|
144
|
+
when String then [ [ data ] ]
|
145
|
+
end
|
146
|
+
|
147
|
+
if !variables.nil? && !variables.empty?
|
134
148
|
self.log_create(key, *variables, period: period || 100)
|
135
|
-
|
136
|
-
|
149
|
+
end
|
150
|
+
}
|
137
151
|
|
138
152
|
self
|
139
153
|
end
|
@@ -166,10 +180,11 @@ class CrazyflieZMQ
|
|
166
180
|
|
167
181
|
|
168
182
|
# Create a log block
|
183
|
+
#
|
169
184
|
# @note logging is usually done through the crazyflie radio link
|
170
|
-
# so you are limited in the number of
|
185
|
+
# so you are limited in the number of variables that you
|
171
186
|
# can log at the same time as well as the minimal logging
|
172
|
-
# period that you can use
|
187
|
+
# period that you can use.
|
173
188
|
#
|
174
189
|
# @param name [Symbole,String] log block name
|
175
190
|
# @param variables [Array<String>] name of the variable to logs
|
@@ -191,7 +206,7 @@ class CrazyflieZMQ
|
|
191
206
|
#
|
192
207
|
# @param name [Symbol, String] name of the log block to start
|
193
208
|
# @param file [String, :csv, nil] name or type of file where to automatically log data
|
194
|
-
# @
|
209
|
+
# @yield log data
|
195
210
|
# @return [self]
|
196
211
|
def log_start(name, file: nil, &block)
|
197
212
|
count = (@log_count[name] || 0) + 1
|
@@ -272,7 +287,7 @@ class CrazyflieZMQ
|
|
272
287
|
# Get a parameter value from the crazyflie
|
273
288
|
#
|
274
289
|
# If a parameter group is not specified it is possible
|
275
|
-
# to use a
|
290
|
+
# to use a +.+ in the parameter name to indicate it:
|
276
291
|
# +"group.name"+
|
277
292
|
#
|
278
293
|
# @param group [String,nil] group on which the parameter belongs
|
@@ -285,6 +300,12 @@ class CrazyflieZMQ
|
|
285
300
|
|
286
301
|
private
|
287
302
|
|
303
|
+
def _json_fix(str)
|
304
|
+
str.gsub(/(?<=:)
|
305
|
+
(?:[\+\-]?Infinity|NaN)
|
306
|
+
(?=,|\})/x, 'null')
|
307
|
+
end
|
308
|
+
|
288
309
|
def _zmq_ok!(rc, msg = nil)
|
289
310
|
if !ZMQ::Util.resultcode_ok?(rc)
|
290
311
|
raise ZMQError, msg
|
@@ -296,7 +317,7 @@ class CrazyflieZMQ
|
|
296
317
|
resp = ''
|
297
318
|
@client_sock.send_string(data.to_json)
|
298
319
|
@client_sock.recv_string(resp)
|
299
|
-
resp = JSON.parse(resp)
|
320
|
+
resp = JSON.parse(_json_fix(resp))
|
300
321
|
version = resp.delete('version')
|
301
322
|
status = resp.delete('status')
|
302
323
|
unless status.nil? || status.zero?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crazyflie-zmq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephane D'Alu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi-rzmq
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- LICENSE
|
78
78
|
- crazyflie-zmq.gemspec
|
79
79
|
- lib/crazyflie-zmq.rb
|
80
|
+
- lib/crazyflie-zmq/version.rb
|
80
81
|
homepage: http://github.com/sdalu/crazyflie-zmq
|
81
82
|
licenses:
|
82
83
|
- Apache-2.0
|