Skip to content

Commit 9aa50e5

Browse files
Update user guides (#586)
--------- Co-authored-by: Enya <enyaannaida@gmail.com>
1 parent 99ad0e3 commit 9aa50e5

4 files changed

Lines changed: 100 additions & 88 deletions

File tree

docs/user-guides/sbs_connect_log_param.md

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ On this step by step guide we will show you how to connect to your Crazyflie thr
1111
We will assume that you already know this before you start with the tutorial:
1212

1313
* 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/).
1515
* 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/)).
1616

1717

@@ -23,7 +23,7 @@ Make sure that you have [python3](https://www.python.org), which should contain
2323

2424
This should have been installed if you installed the cfclient already (on a linux system), but it is always good to double check this :)
2525

26-
## Step 1. Connecting with the crazyflie
26+
## Step 1. Connecting with the Crazyflie
2727

2828
### Begin the python script
2929

@@ -32,7 +32,7 @@ Open up a python script anywhere that is convenient for you. We use Visual Studi
3232
* For python editor: select file->new
3333
* For VS code: select file-> new file
3434

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).
3636

3737
Then you would need to start with the following standard python libraries.
3838

@@ -66,7 +66,7 @@ After these imports, start the script with:
6666
uri = uri_helper.uri_from_env(default='radio://0/80/2M/E7E7E7E7E7')
6767
```
6868

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).
7070

7171
### Main
7272

@@ -83,7 +83,7 @@ if __name__ == '__main__':
8383

8484
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.
8585

86-
### Function for connecting with the crazyflie
86+
### Function for connecting with the Crazyflie
8787

8888
Start a function above the main function (but below the URI) which you call simple connect:
8989

@@ -99,6 +99,7 @@ def simple_connect():
9999

100100
### Run the script
101101

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).
102103
Now run the script in your terminal:
103104

104105

@@ -111,12 +112,12 @@ Now I will disconnect :'(
111112
```
112113

113114

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.
115116

116117
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.
117118

118119

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!
120121

121122
```python
122123
import logging
@@ -125,9 +126,10 @@ import time
125126
import cflib.crtp
126127
from cflib.crazyflie import Crazyflie
127128
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
129+
from cflib.utils import uri_helper
128130

129131
# 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')
131133

132134
def simple_connect():
133135

@@ -148,13 +150,13 @@ if __name__ == '__main__':
148150

149151

150152

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!
152154

153155

154156

155157
### More imports
156158

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:
158160

159161
```python
160162
...
@@ -167,7 +169,7 @@ from cflib.crazyflie.syncLogger import SyncLogger
167169
from the Crazyflie
168170
* The SyncLogger class provides synchronous access to log data from the Crazyflie.
169171

170-
Also add the following underneath URI
172+
Also add the following underneath URI:
171173

172174
```python
173175
# Only output errors from the logging framework
@@ -205,7 +207,7 @@ Notice that now you will need to include the SyncCrazyflie instance (`scf`) and
205207

206208
Now the logging instances will be inserted by adding the following after you configured the lg_stab:
207209
```python
208-
with SyncLogger(scf, lg_stab) as logger:
210+
with SyncLogger(scf, logconf) as logger:
209211

210212
for log_entry in logger:
211213

@@ -221,14 +223,14 @@ Now the logging instances will be inserted by adding the following after you con
221223

222224
### Test the script:
223225

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.
225227

226228
If everything is fine it should continuously print the logging variables, like this:
227229

228230
`[1486704][<cflib.crazyflie.log.LogConfig object at 0x7ffb3384a1d0>]: {'stabilizer.roll': -0.054723262786865234, 'stabilizer.pitch': 0.006269464734941721, 'stabilizer.yaw': -0.008503230288624763}`
229231

230232

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_.
232234

233235
If you are getting errors, check if your script corresponds with the full code:
234236
```python
@@ -238,12 +240,13 @@ import time
238240
import cflib.crtp
239241
from cflib.crazyflie import Crazyflie
240242
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
243+
from cflib.utils import uri_helper
241244

242245
from cflib.crazyflie.log import LogConfig
243246
from cflib.crazyflie.syncLogger import SyncLogger
244247

245248
# 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')
247250

248251
# Only output errors from the logging framework
249252
logging.basicConfig(level=logging.ERROR)
@@ -296,7 +299,7 @@ def simple_log_async(scf, logconf):
296299
cf.log.add_config(logconf)
297300
```
298301

299-
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:
300303

301304
`KeyError: 'Variable not.real not in TOC'`
302305

@@ -308,7 +311,7 @@ def log_stab_callback(timestamp, data, logconf):
308311
print('[%d][%s]: %s' % (timestamp, logconf.name, data))
309312
```
310313

311-
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(..)`:
312315

313316
```python
314317
logconf.data_received_cb.add_callback(log_stab_callback)
@@ -328,7 +331,7 @@ Make sure to replace the `simple_log(...)` to `simple_log_async(...)` in the `__
328331

329332
`[18101][Stabilizer]: {'stabilizer.roll': -174.58396911621094, 'stabilizer.pitch': 42.82120132446289, 'stabilizer.yaw': 166.29837036132812}`
330333

331-
If something went wrong, check if your script corresponds to the this:
334+
If something went wrong, check if your script corresponds to this:
332335

333336
```python
334337
import logging
@@ -337,12 +340,13 @@ import time
337340
import cflib.crtp
338341
from cflib.crazyflie import Crazyflie
339342
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
343+
from cflib.utils import uri_helper
340344

341345
from cflib.crazyflie.log import LogConfig
342346
from cflib.crazyflie.syncLogger import SyncLogger
343347

344348
# URI to the Crazyflie to connect to
345-
uri = 'radio://0/80/2M/E7E7E7E7E7'
349+
uri = uri_helper.uri_from_env(default='radio://0/80/2M/E7E7E7E7E7')
346350

347351
# Only output errors from the logging framework
348352
logging.basicConfig(level=logging.ERROR)
@@ -355,7 +359,7 @@ def simple_log_async(scf, logconf):
355359
cf.log.add_config(logconf)
356360
logconf.data_received_cb.add_callback(log_stab_callback)
357361
logconf.start()
358-
time.sleep(5)
362+
time.sleep(5) # Your possibility to interact with the Crazyflie
359363
logconf.stop()
360364

361365
(...)
@@ -430,7 +434,7 @@ If you would run the script now you will also get this message:
430434

431435
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.
432436

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:
434438

435439
`AttributeError: cpu.flash is read-only!`
436440

@@ -454,9 +458,10 @@ from cflib.crazyflie import Crazyflie
454458
from cflib.crazyflie.log import LogConfig
455459
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
456460
from cflib.crazyflie.syncLogger import SyncLogger
461+
from cflib.utils import uri_helper
457462

458463
# 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')
460465

461466
# Only output errors from the logging framework
462467
logging.basicConfig(level=logging.ERROR)

0 commit comments

Comments
 (0)