[SOLVED] Cannot find a Crazyradio Dongle

Discussions and questions about the Crazyradio
Post Reply
CrazyGuy
Beginner
Posts: 27
Joined: Fri May 02, 2014 6:03 pm

[SOLVED] Cannot find a Crazyradio Dongle

Post by CrazyGuy »

Hi!

I got a new laptop so I copied all my crazyflie projects from my old system (Ubuntu 14.10) to my new system (Ubuntu 15.10). I managed that everything is working but the crazyradio to update the firmware on the crazyflie.

I'm using the libcflie library. This library works and I'm able to access the radio dongle and I'm able to connect to the crazyflie. But libcflie does not contain a bootloader. So I still have the python-client. On my old system everything worked but now I get (almost every time) the error "Cannot find a Crazyradio Dongle" when I want to flash a new firmware to the crazyflie. Two times the error didn't occur and it seemed like the program was waiting for me to start the crazyflie. Then I started the crazyflie but nothing happend (well, the crazyflie was on...)

That's what I found out (btw: when I started with my work there was no crazyflie 2.0. so all my code is from before)

in crazyflie-clients-python / bin / cfloader:

Code: Select all

try:
    cflib.crtp.init_drivers()	#seems to work
    link = cflib.crtp.get_link_driver("radio://0") #raises the exception
except Exception as e:
    print "Error: {}".format(str(e)) # gets printed
    if link:
        link.close()
    sys.exit(-1)


in crazyflie-clients-python / lib / cflib / crtp / __init__.py:

Code: Select all

def get_link_driver(uri, link_quality_callback=None, link_error_callback=None):
    """Return the link driver for the given URI. Returns None if no driver
    was found for the URI or the URI was not well formatted for the matching
    driver."""
    for instance in INSTANCES:
        print instance # output is: <cflib.crtp.radiodriver.RadioDriver instance at 0x{"random" number}>
        try:
            print "No. 1" # gets printed
            instance.connect(uri, link_quality_callback, link_error_callback)
            print "No. 2" # does not get printed
            return instance
        except WrongUriType:
            print "No. 3" # does not get printed
            continue
    print "No. 4" # does not get printed
    return None
So according to my "debug-outputs" the error occurs in instance.connect I think!? Do you know how I can fix this? Do I miss any packages? I've already installed python-usb for example.
Last edited by CrazyGuy on Wed Apr 20, 2016 12:44 pm, edited 1 time in total.
chad
Expert
Posts: 555
Joined: Sun Sep 28, 2014 12:54 am
Location: New York, USA
Contact:

Re: Cannot find a Crazyradio Dongle

Post by chad »

Are you sure you have the UDEV rules for Crazyradio set up on your new system? That could cause the dongle not to be accessible. Have you checked to see if the Crazyradio is available by using:

Code: Select all

lsusb
Crazyflier - my CF journal...
4x Crazyflie Nano (1.0) 10-DOF + NeoPixel Ring mod.
3x Crazyflie 2.0 + Qi Charger and LED Decks.
Raspberry Pi Ground Control.
Mac OS X Dev Environment.
Walkera Devo7e, ESky ET6I, PS3 and iOS Controllers.
CrazyGuy
Beginner
Posts: 27
Joined: Fri May 02, 2014 6:03 pm

Re: Cannot find a Crazyradio Dongle

Post by CrazyGuy »

yes and yes.

For the libcflie I need the udev rules too and it's working. The Crazyradio is available by using "lsusb"
marcus
Bitcraze
Posts: 659
Joined: Mon Jan 28, 2013 7:02 pm
Location: Sweden
Contact:

Re: Cannot find a Crazyradio Dongle

Post by marcus »

Hi!

Is all the code up to date, or do you have older changes that's mixed in with the new code? It could be an issue with libusb and we've made some changes there a while ago.
CrazyGuy
Beginner
Posts: 27
Joined: Fri May 02, 2014 6:03 pm

Re: Cannot find a Crazyradio Dongle

Post by CrazyGuy »

Well, it's not up to date. But I don't think that this is the problem. I use the same code on my old laptop and there it's working.

I don't know if that is a clue but if I try to flash the firmware with the radio NOT plugged in, then my two laptops don't show exactly the same information in the build log (I call the makefile via my Codeblocks-project)

On my old laptop (would work if I plug in the radio) the build log says:
------ Build: cload in crazyflie-firmware-mod (compiler: GNU GCC Compiler)-----
Running command: make -f Makefile cload
../crazyflie-clients-python/bin/cfloader flash cflie.bin
Error: Cannot find a Crazyradio Dongle
make: *** [cload] Fehler 255
Process terminated with status 2 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))
On my new laptop (doesn't matter if I plug in the radio or not) I get this message:
------ Build: cload in crazyflie-firmware-mod (compiler: GNU GCC Compiler)-----
Running command: make -f Makefile cload
../crazyflie-clients-python/bin/cfloader flash cflie.bin
Error: Cannot find a Crazyradio Dongle
make: *** [cload] Error 255
Makefile:176: recipe for target 'cload' failed
Process terminated with status 2 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))
So on my new laptop it also says that the recipe for target failed.

Line 176 of the makefile is: $(CLOAD_SCRIPT) flash cflie.bin

For the sake of completeness here the makefile I use (on both laptops). config.mk is empty on both systems:

Code: Select all

# CrazyFlie's Makefile
# Copyright (c) 2011,2012 Bitcraze AB
# This Makefile compiles all the objet file to ./bin/ and the resulting firmware
# image in ./cflie.elf and ./cflie.bin

#Put your personal build config in config.mk and DO NOT COMMIT IT!
-include config.mk

######### JTAG and environment configuration ##########
OPENOCD_INTERFACE ?= interface/jtagkey.cfg
OPENOCD_TARGET    ?= target/stm32f1x.cfg
CROSS_COMPILE     ?= arm-none-eabi-
PYTHON2           ?= python
CLOAD             ?= 1
DEBUG             ?= 0
CLOAD_SCRIPT      ?= ../crazyflie-clients-python/bin/cfloader

## Flag that can be added to config.mk
# CFLAGS += -DUSE_UART_CRTP        # Set CRTP link to UART
# CFLAGS += -DUSE_ESKYLINK         # Set CRTP link to E-SKY receiver
# CFLAGS += -DENABLE_UART          # To enable the uart
# CFLAGS += -DDEBUG_PRINT_ON_UART  # Redirect the console output to the UART
# CFLAGS += -DENABLE_FAST_CHARGE   # Will enable ~800mA USB current for wall adapters. Should only be used with batteries 
	  															 # that can handle ~740mA charge current or it will degrade the battery.

REV               ?= E

#OpenOCD conf
RTOS_DEBUG        ?= 0

############### Location configuration ################
FREERTOS = lib/FreeRTOS
PORT = $(FREERTOS)/portable/GCC/ARM_CM3
STLIB = lib/

################ Build configuration ##################
# St Lib
VPATH += $(STLIB)/CMSIS/Core/CM3/startup/gcc
CRT0=startup_stm32f10x_md.o

include scripts/st_obj.mk

# FreeRTOS
VPATH += $(PORT)
PORT_OBJ=port.o
VPATH +=  $(FREERTOS)/portable/MemMang
MEMMANG_OBJ = heap_4.o

VPATH += $(FREERTOS)
FREERTOS_OBJ = list.o tasks.o queue.o timers.o $(MEMMANG_OBJ)

# Crazyflie
VPATH += init hal/src modules/src utils/src drivers/src

############### Source files configuration ################

# Init
PROJ_OBJ = main.o

# Drivers
PROJ_OBJ += led.o uart.o adc.o nrf24l01.o  exti.o  nvic.o motors.o
PROJ_OBJ += mpu6050.o i2cdev.o i2croutines.o hmc5883l.o
PROJ_OBJ += ms5611.o

# Hal
PROJ_OBJ += crtp.o ledseq.o freeRTOSdebug.o imu.o pm.o radiolink.o eskylink.o
PROJ_OBJ += usec_time.o

# Modules
PROJ_OBJ += system.o comm.o console.o pid.o crtpservice.o param.o
PROJ_OBJ += commander.o controller.o sensfusion6.o stabilizer.o
PROJ_OBJ += log.o worker.o

# Utilities
PROJ_OBJ += filter.o cpuid.o cfassert.o configblock.o eprintf.o crc.o fp16.o debug.o abort.o
PROJ_OBJ += version.o


OBJ = $(CRT0) $(FREERTOS_OBJ) $(PORT_OBJ) $(ST_OBJ) $(PROJ_OBJ)

ifdef P
  C_PROFILE = -D P_$(P)
endif

############### Compilation configuration ################
AS = $(CROSS_COMPILE)as
CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)gcc
SIZE = $(CROSS_COMPILE)size
OBJCOPY = $(CROSS_COMPILE)objcopy

INCLUDES = -I$(FREERTOS)/include -I$(PORT) -I.
INCLUDES+= -I$(STLIB)/STM32F10x_StdPeriph_Driver/inc
INCLUDES+= -I$(STLIB)/CMSIS/Core/CM3
INCLUDES+= -Iconfig -Ihal/interface -Imodules/interface
INCLUDES+= -Iutils/interface -Idrivers/interface

PROCESSOR = -mcpu=cortex-m3 -mthumb

#Flags required by the ST library
STFLAGS = -DSTM32F10X_MD -include stm32f10x_conf.h

ifeq ($(DEBUG), 1)
  CFLAGS += -O0 -g3
else
  CFLAGS += -Os -g3
endif

ifeq ($(LTO), 1)
  CFLAGS += -flto -fuse-linker-plugin
endif

ifeq ($(USE_ESKYLINK), 1)
  CFLAGS += -DUSE_ESKYLINK
endif

CFLAGS += -DBOARD_REV_$(REV)

CFLAGS += $(PROCESSOR) $(INCLUDES) $(STFLAGS) -Wall -fno-strict-aliasing $(C_PROFILE)
# Compiler flags to generate dependency files:
CFLAGS += -MD -MP -MF $(BIN)/dep/$(@).d -MQ $(@)
#Permits to remove un-used functions and global variables from output file
CFLAGS += -ffunction-sections -fdata-sections

ASFLAGS = $(PROCESSOR) $(INCLUDES)
LDFLAGS = $(CFLAGS) -Wl,-Map=$(PROG).map,--cref,--gc-sections -nostdlib

ifeq ($(CLOAD), 1)
  LDFLAGS += -T scripts/STM32F103_32K_20K_FLASH_CLOAD.ld
else
  LDFLAGS += -T scripts/STM32F103_32K_20K_FLASH.ld
endif

#Program name
PROG = cflie
#Where to compile the .o
BIN = bin
VPATH += $(BIN)

#Dependency files to include
DEPS := $(foreach o,$(OBJ),$(BIN)/dep/$(o).d)

##################### Misc. ################################
ifeq ($(SHELL),/bin/sh)
  COL_RED=\033[1;31m
  COL_GREEN=\033[1;32m
  COL_RESET=\033[m
endif

#################### Targets ###############################

all: build
build: clean_version compile print_version size
compile: clean_version $(PROG).hex $(PROG).bin

clean_version:
ifeq ($(SHELL),/bin/sh)
	@echo "  CLEAN_VERSION"
	@rm -f version.c
endif

print_version: compile
ifeq ($(SHELL),/bin/sh)
	@./scripts/print_revision.sh
endif
ifeq ($(CLOAD), 1)
	@echo "CrazyLoader build!"
endif

size: compile
	@$(SIZE) -B $(PROG).elf

#Radio bootloader
cload:
ifeq ($(CLOAD), 1)
	$(CLOAD_SCRIPT) flash cflie.bin
else
	@echo "Only cload build can be bootloaded. Launch build and cload with CLOAD=1"
endif

#Flash the stm.
flash:
	openocd -d0 -f $(OPENOCD_INTERFACE) -f $(OPENOCD_TARGET) -c init -c targets -c "reset halt" \
                 -c "flash write_image erase cflie.elf" -c "verify_image cflie.elf" -c "reset run" -c shutdown

#STM utility targets
halt:
	openocd -d0 -f $(OPENOCD_INTERFACE) -f $(OPENOCD_TARGET) -c init -c targets -c "halt" -c shutdown

reset:
	openocd -d0 -f $(OPENOCD_INTERFACE) -f $(OPENOCD_TARGET) -c init -c targets -c "reset" -c shutdown

openocd:
	openocd -d0 -f $(OPENOCD_INTERFACE) -f $(OPENOCD_TARGET) -c init -c targets

#Print preprocessor #defines
prep:
	@$(CC) -dD

include scripts/targets.mk

#include dependencies
-include $(DEPS)

Python definitely detects the radio. After I've plugged in the radio dongle, I started python in a terminal and executed the following code which is part of the crazyradio.py file:

Code: Select all

import os
import usb

try:
    import usb.core
    pyusb_backend = None
    if os.name == "nt":
        import usb.backend.libusb0 as libusb0
        pyusb_backend = libusb0.get_backend()
    pyusb1 = True
except:
    pyusb1 = False

if pyusb1:
    dev = usb.core.find(idVendor=0x1915, idProduct=0x7777, find_all=1, backend=pyusb_backend)
    if dev is not None:
        ret = dev
        print "ok" # added by me right now
"ok" gets printed.

So does anyone have any ideas what's wrong? I'm pretty clueless right now :(
CrazyGuy
Beginner
Posts: 27
Joined: Fri May 02, 2014 6:03 pm

Re: Cannot find a Crazyradio Dongle

Post by CrazyGuy »

Just for your information: Yesterday I looked again at this situation and I figured out what the problem was. On my old system "import usb.core" failed. Therefore pyusb1 was set to False. On my new system pyusb1 was set to True since there is a usb.core module. My files are indeed not up to date. It seems like there are some bugs in these outdated files for the case that pyusb1 is set to true.

I haven't updated my files yet but used instead an ugly hack by setting pyusb1 always to False... Now it's working again :D
Post Reply