You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/user-guides/sbs_connect_log_param.md
+27-22Lines changed: 27 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ On this step by step guide we will show you how to connect to your Crazyflie thr
11
11
We will assume that you already know this before you start with the tutorial:
12
12
13
13
* Some basic experience with python
14
-
* Followed the [crazyflie getting started guide](https://www.bitcraze.io/documentation/tutorials/getting-started-with-crazyflie-2-x/).
14
+
* Followed the [Crazyflie getting started guide](https://www.bitcraze.io/documentation/tutorials/getting-started-with-crazyflie-2-x/).
15
15
* Able to connect the crazyflie to the CFClient and look at the log tabs and parameters (here is a [userguide](https://www.bitcraze.io/documentation/repository/crazyflie-clients-python/master/userguides/userguide_client/)).
16
16
17
17
@@ -23,7 +23,7 @@ Make sure that you have [python3](https://www.python.org), which should contain
23
23
24
24
This should have been installed if you installed the cfclient already (on a linux system), but it is always good to double check this :)
25
25
26
-
## Step 1. Connecting with the crazyflie
26
+
## Step 1. Connecting with the Crazyflie
27
27
28
28
### Begin the python script
29
29
@@ -32,7 +32,7 @@ Open up a python script anywhere that is convenient for you. We use Visual Studi
32
32
* For python editor: select file->new
33
33
* For VS code: select file-> new file
34
34
35
-
You can call it `connect_log_param.py` (that is what we are using in this tutorial)
35
+
You can call it `connect_log_param.py` (that is what we are using in this tutorial).
36
36
37
37
Then you would need to start with the following standard python libraries.
38
38
@@ -66,7 +66,7 @@ After these imports, start the script with:
66
66
uri = uri_helper.uri_from_env(default='radio://0/80/2M/E7E7E7E7E7')
67
67
```
68
68
69
-
This is the radio uri of the crazyflie, it can be set by setting the environment variable `CFLIB_URI`, if not set it uses the default. It should be probably fine but if you do not know what the uri of your Crazyfie is you can check that with an usb cable and looking at the config ([here](https://www.bitcraze.io/documentation/repository/crazyflie-clients-python/master/userguides/userguide_client/#firmware-configuration) are the instructions)
69
+
This is the radio uri of the Crazyflie, it can be set by setting the environment variable `CFLIB_URI`, if not set it uses the default. It should be probably fine but if you do not know what the uri of your Crazyfie is you can check that with an usb cable and looking at the config ([here](https://www.bitcraze.io/documentation/repository/crazyflie-clients-python/master/userguides/userguide_client/#firmware-configuration) are the instructions).
70
70
71
71
### Main
72
72
@@ -83,7 +83,7 @@ if __name__ == '__main__':
83
83
84
84
The `syncCrazyflie` will create a synchronous Crazyflie instance with the specified link_uri. As you can see we are currently calling an non-existing function, so you will need to make that function first before you run the script.
85
85
86
-
### Function for connecting with the crazyflie
86
+
### Function for connecting with the Crazyflie
87
87
88
88
Start a function above the main function (but below the URI) which you call simple connect:
89
89
@@ -99,6 +99,7 @@ def simple_connect():
99
99
100
100
### Run the script
101
101
102
+
Make sure your Crazyflie is on and your Crazyradio is connected to your computer, and that the Crazyflie is not connected to anything else (like the cfclient).
102
103
Now run the script in your terminal:
103
104
104
105
@@ -111,12 +112,12 @@ Now I will disconnect :'(
111
112
```
112
113
113
114
114
-
The script connected with your Crazyflie, synced and disconnected after a few seconds. You can see that the M4 LED is flashing yellow, which means that the Crazyflie is connected to the script, but as soon as it leaves the `simple_connect()` function, the LED turns of. The Crazyflie is no longer connected
115
+
The script connected with your Crazyflie, synced and disconnected after a few seconds. You can see that the M4 LED is flashing yellow, which means that the Crazyflie is connected to the script, but as soon as it leaves the `simple_connect()` function, the LED turns of. The Crazyflie is no longer connected.
115
116
116
117
Not super exciting stuff yet but it is a great start! It is also a good test if everything is correctly configured on your system.
117
118
118
119
119
-
If you are getting an error, retrace your steps or check if your code matches the entire code underneath here. Also make sure your Crazyflie is on and your crazyradio PA connected to you computer, and that the Crazyflie is not connected to anything else (like the cfclient). If everything is peachy, please continue to the next part!
120
+
If you are getting an error, retrace your steps or check if your code matches the entire code underneath here. If everything is peachy, please continue to the next part!
120
121
121
122
```python
122
123
import logging
@@ -125,9 +126,10 @@ import time
125
126
import cflib.crtp
126
127
from cflib.crazyflie import Crazyflie
127
128
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
129
+
from cflib.utils import uri_helper
128
130
129
131
# URI to the Crazyflie to connect to
130
-
uri ='radio://0/80/2M/E7E7E7E7E7'
132
+
uri =uri_helper.uri_from_env(default='radio://0/80/2M/E7E7E7E7E7')
131
133
132
134
defsimple_connect():
133
135
@@ -148,13 +150,13 @@ if __name__ == '__main__':
148
150
149
151
150
152
151
-
Alright, now taking a step up. We will now add to the script means to read out logging variables!
153
+
Alright, now taking a step up. We will now add means to read out logging variables to the script!
152
154
153
155
154
156
155
157
### More imports
156
158
157
-
Now we need to add several imports on the top of the script connect_log_param.py
159
+
Now we need to add imports to the top of the script connect_log_param.py:
158
160
159
161
```python
160
162
...
@@ -167,7 +169,7 @@ from cflib.crazyflie.syncLogger import SyncLogger
167
169
from the Crazyflie
168
170
* The SyncLogger class provides synchronous access to log data from the Crazyflie.
169
171
170
-
Also add the following underneath URI
172
+
Also add the following underneath URI:
171
173
172
174
```python
173
175
# Only output errors from the logging framework
@@ -205,7 +207,7 @@ Notice that now you will need to include the SyncCrazyflie instance (`scf`) and
205
207
206
208
Now the logging instances will be inserted by adding the following after you configured the lg_stab:
207
209
```python
208
-
with SyncLogger(scf, lg_stab) as logger:
210
+
with SyncLogger(scf, logconf) as logger:
209
211
210
212
for log_entry in logger:
211
213
@@ -221,14 +223,14 @@ Now the logging instances will be inserted by adding the following after you con
221
223
222
224
### Test the script:
223
225
224
-
First change the `simple_connect()` in _main_in`simple_log(scf, lg_stab)`. Now run the script (`python3 connect_log_param.py`) like before.
226
+
First change the `simple_connect()` in _main_to`simple_log(scf, lg_stab)`. Now run the script (`python3 connect_log_param.py`) like before.
225
227
226
228
If everything is fine it should continuously print the logging variables, like this:
227
229
228
230
`[1486704][<cflib.crazyflie.log.LogConfig object at 0x7ffb3384a1d0>]: {'stabilizer.roll': -0.054723262786865234, 'stabilizer.pitch': 0.006269464734941721, 'stabilizer.yaw': -0.008503230288624763}`
229
231
230
232
231
-
If you want to continuously receive the messages in the for loop, remove the `break`. You can stop the script with _ctrl+c_
233
+
If you want to continuously receive the messages in the for loop, remove the `break`. You can stop the script with _ctrl+c_.
232
234
233
235
If you are getting errors, check if your script corresponds with the full code:
234
236
```python
@@ -238,12 +240,13 @@ import time
238
240
import cflib.crtp
239
241
from cflib.crazyflie import Crazyflie
240
242
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
243
+
from cflib.utils import uri_helper
241
244
242
245
from cflib.crazyflie.log import LogConfig
243
246
from cflib.crazyflie.syncLogger import SyncLogger
244
247
245
248
# URI to the Crazyflie to connect to
246
-
uri ='radio://0/80/2M/E7E7E7E7E7'
249
+
uri =uri_helper.uri_from_env(default='radio://0/80/2M/E7E7E7E7E7')
Here you add the logging configuration to to the logging framework of the Crazyflie. It will check if the log configuration is part of the TOC, which is a list of all the logging variables defined in the Crazyflie. You can test this out by changing one of the `lg_stab` variables to a completely bogus name like `'not.real'`. In this case you would receive the following message:
302
+
Here you add the logging configuration to the logging framework of the Crazyflie. It will check if the log configuration is part of the TOC, which is a list of all the logging variables defined in the Crazyflie. You can test this out by changing one of the `lg_stab` variables to a completely bogus name like `'not.real'`. In this case you would receive the following message:
This callback will be called once the log variables have received it and prints the contents. The callback function added to the logging framework by adding it to the log config in `simple_log_async(..)`:
314
+
This callback will be called once the log variables have received it and prints the contents. The callback function is added to the logging framework by adding it to the log config in `simple_log_async(..)`:
time.sleep(5)# Your possibility to interact with the Crazyflie
359
363
logconf.stop()
360
364
361
365
(...)
@@ -430,7 +434,7 @@ If you would run the script now you will also get this message:
430
434
431
435
This means that the Crazyflie has changed the parameter value to 2, which is another methods it uses for state estimation. This can also be done to change the color on the ledring, or to initiate the highlevel commander.
432
436
433
-
What it can't do is to set a Read Only (RO) parameter, only Read Write (RW) parameters, which can be checked by the parameter TOC in the CFclient. You can check this by changing the parameter name to group `'CPU' ` and name `flash'`. Then you will get the following error:
437
+
What it can't do is to set a Read Only (RO) parameter, only Read Write (RW) parameters, which can be checked by the parameter TOC in the CFclient. You can check this by changing the parameter name to group `'cpu' ` and name `flash'`. Then you will get the following error:
434
438
435
439
`AttributeError: cpu.flash is read-only!`
436
440
@@ -454,9 +458,10 @@ from cflib.crazyflie import Crazyflie
454
458
from cflib.crazyflie.log import LogConfig
455
459
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
456
460
from cflib.crazyflie.syncLogger import SyncLogger
461
+
from cflib.utils import uri_helper
457
462
458
463
# URI to the Crazyflie to connect to
459
-
uri ='radio://0/80/2M/E7E7E7E7E7'
464
+
uri =uri_helper.uri_from_env(default='radio://0/80/2M/E7E7E7E7E7')
0 commit comments