Crazyradio sees URI as '-f'

Post here to get support
Post Reply
DM7299
Member
Posts: 31
Joined: Sat Jun 05, 2021 6:04 pm

Crazyradio sees URI as '-f'

Post by DM7299 »

When trying to fly a Crazyflie using the multiranger_push.py code (found here https://github.com/bitcraze/crazyflie-l ... er_push.py), the code prints "Connecting to -f", followed by "Connection to -f failed: No driver found or malformed URI: -f". This is peculiar, as I am able to get other code to run smoothly, but have problems only with this particular python file.

Is there anything that might be causing this? Perhaps an outdated repository, or a library I've forgotten to install? Thanks for any help!
(The CF talks on radio://0/100/2M/E7E7E7E702 normally to other programs, by the way. This name should not be the problem.)

Code below:

import logging
import sys
import time

import cflib.crtp
from cflib.crazyflie import Crazyflie
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
from cflib.positioning.motion_commander import MotionCommander
from cflib.utils import uri_helper
from cflib.utils.multiranger import Multiranger

URI = uri_helper.uri_from_env(default='radio://0/100/2M/E7E7E7E702')

if len(sys.argv) > 1:
URI = sys.argv[1]

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


def is_close(range):
MIN_DISTANCE = 0.2 # m

if range is None:
return False
else:
return range < MIN_DISTANCE


if __name__ == '__main__':
# Initialize the low-level drivers
cflib.crtp.init_drivers()

cf = Crazyflie(rw_cache='./cache')
with SyncCrazyflie(URI, cf=cf) as scf:
with MotionCommander(scf) as motion_commander:
with Multiranger(scf) as multiranger:
keep_flying = True

while keep_flying:
VELOCITY = 0.5
velocity_x = 0.0
velocity_y = 0.0

if is_close(multiranger.front):
velocity_x -= VELOCITY
if is_close(multiranger.back):
velocity_x += VELOCITY

if is_close(multiranger.left):
velocity_y -= VELOCITY
if is_close(multiranger.right):
velocity_y += VELOCITY

if is_close(multiranger.up):
keep_flying = False

motion_commander.start_linear_motion(
velocity_x, velocity_y, 0)

time.sleep(0.1)

print('Demo terminated!')

Error response:
Attachments
Screen Shot 2021-07-08 at 10.59.07 AM.png
jonasdn
Expert
Posts: 132
Joined: Mon Mar 01, 2021 3:13 pm

Re: Crazyradio sees URI as '-f'

Post by jonasdn »

Hi DM7299!

How are you executing this example?

Looking at the start of the script there are two ways of setting URI.

Code: Select all

URI = uri_helper.uri_from_env(default='radio://0/80/2M/E7E7E7E7E7')

if len(sys.argv) > 1:
    URI = sys.argv[1]
First the script till look at an environment variable "CFLIB_URI" if that does not exist, it will set the defautlt uri of radio://0/80/2M/E7E7E7E7E7 and below that the script checks if there are any argument to the script, if there is it will override the URI with the first argument to the script.

So it depends on what arguments the script has. If you modift the cood to read:

Code: Select all

URI = uri_helper.uri_from_env(default='radio://0/80/2M/E7E7E7E7E7')

print(f'{sys.argv} - {URI}')

if len(sys.argv) > 1:
    URI = sys.argv[1]
What output do you get?
Jonas
DM7299
Member
Posts: 31
Joined: Sat Jun 05, 2021 6:04 pm

Re: Crazyradio sees URI as '-f'

Post by DM7299 »

In addition to the other errors from before, this gives

['/Users/david/opt/anaconda3/lib/python3.8/site-packages/ipykernel_launcher.py', '-f', '/Users/david/Library/Jupyter/runtime/kernel-ece51ab0-1a51-4425-a89b-3b604e34c2cb.json'] - radio://0/100/2M/E7E7E7E702
DM7299
Member
Posts: 31
Joined: Sat Jun 05, 2021 6:04 pm

Re: Crazyradio sees URI as '-f'

Post by DM7299 »

Issue solved: Simply removing this section:

URI = uri_helper.uri_from_env(default='radio://0/100/2M/E7E7E7E704')

if len(sys.argv) > 1:
URI = sys.argv[1]

And replacing it with:

URI = 'radio://0/100/2M/E7E7E7E704'

or another equivalent URI allows the code to run. Perhaps this suggests a problem with the uri_helper code? But easy to work around.
kimberly
Bitcraze
Posts: 1050
Joined: Fri Jul 06, 2018 11:13 am

Re: Crazyradio sees URI as '-f'

Post by kimberly »

hi!

Yes that is how the example used to be... but the urihelper was supposed to be better as it was harmonizing the URI handling for all the examples (see this PR).

I've made an issue to make us remember to thoroughly test this again: https://github.com/bitcraze/crazyflie-l ... issues/251
Post Reply