crazyflie-zmq 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
  SHA256:
3
- metadata.gz: 8d66cb857aef6754e059f95c041f710ae4962788cca2cc04295d3c08918d0dc2
4
- data.tar.gz: b95bc3c3e7bde75285b918944e1595656201870b4517766d412d7ff86c53b567
3
+ metadata.gz: 72ac0134ded573f08008637f80c872a6a034de84016efc57c9195245d51be191
4
+ data.tar.gz: 1559e33582d8abf856f93e75b6e57510877e3eab544a710e4de6b28b1f3e22c5
5
5
  SHA512:
6
- metadata.gz: fe7570047d818b80e8ffe0d0cfc2638f2bb5af8fce34074a2486c25f61ce1497060928a50ad8c44c910f4447d4e9367c0bf1a598155637e15fc5e78f0622e75f
7
- data.tar.gz: d87c4ca1f8aedf65c22c3dd631e5c18df4dbb25a6b6b675a9b5ce3b0e4353420c36e3c4073f10aa724265dfa8f2b86dd4f4c0254213ba8bdfe9453b9f2e9545f
6
+ metadata.gz: 8892dd565405dba9078ad8961bb602b9fcf1f84dda6b4b03f8c7c386b2a79700ac4e3ad641b290563a2852ade6467a42f78704d7b4964083f26e5b8a01ec3f22
7
+ data.tar.gz: 11fdc478146ab16903c9eacf58905a0b51fae8860612bd7a1da3fb9ecd8543cf235a80b734cd2fcdbc3f4d0c091d8d31cb718a1fe35ebd0030ee930297655cac
@@ -14,6 +14,7 @@ Gem::Specification.new do |s|
14
14
 
15
15
  s.add_development_dependency "yard"
16
16
  s.add_development_dependency "rake"
17
+ s.add_development_dependency "redcarpet"
17
18
 
18
19
  s.has_rdoc = 'yard'
19
20
 
data/lib/crazyflie-zmq.rb CHANGED
@@ -1,19 +1,46 @@
1
+ # coding: utf-8
2
+
1
3
  require 'thread'
2
4
  require 'json'
3
5
  require 'csv'
4
6
  require 'ffi-rzmq'
5
7
 
8
+
9
+ # Allow control of a {https://www.bitcraze.io/crazyflie-2/ Crazyflie}
10
+ # drone using the ZMQ protocol.
11
+ #
12
+ # To use this you need to have a ZMQ server running, it is started
13
+ # using the crazyflie python clients API
14
+ # ({https://github.com/bitcraze/crazyflie-clients-python/
15
+ # crazyflie-clients-python}):
16
+ #
17
+ # crazyflie-clients-python/bin/cfzmq --url tcp://* -d
18
+ #
19
+ # @see https://wiki.bitcraze.io/doc:crazyflie:client:cfzmq:index
20
+ # @see https://wiki.bitcraze.io/doc:crazyflie:dev:arch:logparam
21
+ # @see https://wiki.bitcraze.io/projects:crazyflie:firmware:comm_protocol
22
+ # @see https://wiki.bitcraze.io/doc:crazyflie:crtp:log
6
23
  class CrazyflieZMQ
7
- VERSION = "0.1.0"
24
+ VERSION = "0.1.1" # CrazyflieZMQ version
8
25
 
26
+ # Standard error for {CrazyflieZMQ}
9
27
  class Error < StandardError ; end
28
+
29
+ # Error related to ZMQ protocol
10
30
  class ZMQError < Error ; end
31
+
32
+ # Error generated when trying to communicate with a crazyflie
33
+ # and the connection is not active
11
34
  class NotConnected < Error ; end
35
+
36
+ # Error while communicating with the crazyflie
12
37
  class RequestError < Error ; end
13
38
 
14
39
 
15
- attr_reader :connected
16
-
40
+
41
+ # Create a CrazyflieZMQ instance
42
+ #
43
+ # @param url [String] the url to connect to the ZMQ socket
17
44
  def initialize(url, log: nil)
18
45
  @url = url
19
46
  @log_cb = log
@@ -77,13 +104,17 @@ class CrazyflieZMQ
77
104
  end
78
105
 
79
106
 
80
-
107
+ # Returns the list of available crazyflie
81
108
  def scan()
82
109
  _request(cmd: :scan)
83
110
  end
84
111
 
85
112
 
86
-
113
+ # Establish a connection with a crazyflie
114
+ #
115
+ # @param uri [String] crazyflie URI
116
+ # @param log_blocks [Hash{Symbol=>Hash}] predefined log blocks
117
+ # @return [self]
87
118
  def connect(uri, log_blocks: nil)
88
119
  toc = _request(cmd: :connect, uri: uri)
89
120
  @param = toc['param'] || {}
@@ -107,6 +138,9 @@ class CrazyflieZMQ
107
138
  self
108
139
  end
109
140
 
141
+ # Disconnect from the crazyflie
142
+ #
143
+ # @return [self]
110
144
  def disconnect()
111
145
  @log_blocks&.each_key {|key| self.log_delete(key) }
112
146
  _request(cmd: :disconnect)
@@ -114,22 +148,51 @@ class CrazyflieZMQ
114
148
  self
115
149
  end
116
150
 
151
+ # Are we connected to the crazyflie
152
+ #
153
+ # @return [Boolean] connection status
117
154
  def is_connected?
118
155
  !@connected.nil?
119
156
  end
120
157
 
158
+ # Ensure we are in a connect state
159
+ #
160
+ # @raise [NotConnected] if not connected to a crazyflie
161
+ # @return [self]
121
162
  def is_connected!
122
163
  raise NotConnected unless is_connected?
164
+ self
123
165
  end
124
166
 
125
-
126
-
167
+
168
+ # Create a log block
169
+ # @note logging is usually done through the crazyflie radio link
170
+ # so you are limited in the number of variable that you
171
+ # can log at the same time as well as the minimal logging
172
+ # period that you can use
173
+ #
174
+ # @param name [Symbole,String] log block name
175
+ # @param variables [Array<String>] name of the variable to logs
176
+ # @param period [Integer] milliseconds between consecutive logs
177
+ # @return [self]
127
178
  def log_create(name, *variables, period: 1000)
128
179
  _request(cmd: :log, action: :create, name: name,
129
180
  variables: variables, period: period)
130
181
  self
131
182
  end
132
183
 
184
+
185
+ # Start logging information
186
+ #
187
+ # It is possible to automatically create a log file using the `file`
188
+ # parameter, in this case you can specify the file name to use for logging
189
+ # (must end in .csv as for now only CSV format is supported), or you
190
+ # can use :csv and a filename will be generated using timestamp and counter
191
+ #
192
+ # @param name [Symbol, String] name of the log block to start
193
+ # @param file [String, :csv, nil] name or type of file where to automatically log data
194
+ # @param block block called on each new log
195
+ # @return [self]
133
196
  def log_start(name, file: nil, &block)
134
197
  count = (@log_count[name] || 0) + 1
135
198
 
@@ -170,7 +233,11 @@ class CrazyflieZMQ
170
233
  @log_count[name] = count
171
234
  self
172
235
  end
173
-
236
+
237
+
238
+ # Stop logging of the specified log block
239
+ # @param name [Symbol,String] name of the log block
240
+ # @return [self]
174
241
  def log_stop(name)
175
242
  _request(cmd: :log, action: :stop, name: name)
176
243
  @log_data_cb.delete(name)
@@ -178,17 +245,38 @@ class CrazyflieZMQ
178
245
  self
179
246
  end
180
247
 
248
+ # Delete a registerd log block
249
+ # @param name [Symbol,String] name of the log block
250
+ # @return [self]
181
251
  def log_delete(name)
182
252
  _request(cmd: :log, action: :delete, name: name)
183
253
  self
184
254
  end
185
255
 
256
+
257
+ # Assign a parameter value to the crazyflie
258
+ #
259
+ # If a parameter group is not specified it is possible
260
+ # to use a +.+ in the parameter name to indicate it:
261
+ # +"group.name"+
262
+ #
263
+ # @param group [String,nil] group on which the parameter belongs
264
+ # @param name [String] parameter name
265
+ # @param value
186
266
  def []=(group=nil, name, value)
187
267
  name = [ group, name ].join('.') if group
188
268
  _request(cmd: :param, name: name, value: value)
189
269
  value
190
270
  end
191
271
 
272
+ # Get a parameter value from the crazyflie
273
+ #
274
+ # If a parameter group is not specified it is possible
275
+ # to use a +'.'+ in the parameter name to indicate it:
276
+ # +"group.name"+
277
+ #
278
+ # @param group [String,nil] group on which the parameter belongs
279
+ # @param name [String] parameter name
192
280
  def [](group=nil, name)
193
281
  group, name = name.split('.', 2) if group.nil?
194
282
  @param.dig(group, name, 'value')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crazyflie-zmq
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
  - Stephane D'Alu
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: redcarpet
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description:
56
70
  email:
57
71
  - stephane.dalu@insa-lyon.fr