Creating a custom input interface

Firmware/software/electronics/mechanics
Post Reply
schmiddes
Beginner
Posts: 2
Joined: Wed Aug 15, 2018 2:21 pm

Creating a custom input interface

Post by schmiddes »

Hello,

First of all a huge thanks to the cf developers for giving us an open source quadcopter, this is an awesome project! I am an computer science student and currently working on using gesture recognition to control my crazyflie 2.0. I am using a BLE device for gesture recognition but I am struggling with creating a custom input interface.
My goal is to read data sent from the BLE device, convert it into control input for the cfclient and then send it to the crazyflie. I already achieved reading data from the input device in a python script, however I am struggling to create a custom input interface which is being recognized by the cfclient. I tried copying some of the example code (leapmotion and wiimote) but never succeeded to get the BLE device being recognized as an input device.
Did anyone else try to create a custom input interface and ran into similar problems? What requirements does the input interface have to meet in order to be recognized by the cfclient? Would be great if somebody could point me in the right direction as I am pretty much stuck right now :D

cheers,
schmiddes

This is the code that reads data from the BLE device:

Code: Select all

import binascii
import bluepy
from bluepy import btle


#DELEGATE CLASS FOR NOTIFICATION
class MyDelegate(btle.DefaultDelegate):
    def __init__(self):
        btle.DefaultDelegate.__init__(self)
        
        
#BLE DEVICE SETTINGS
ble_uuid = btle.UUID("7ac71000-503d-4920-b000-acc000000001")
service_uuid = btle.UUID("bea5760d-503d-4920-b000-101e7306b000")  
p = btle.Peripheral("BE:A5:7F:31:69:56")
p.setDelegate(MyDelegate())

#CHARACTERISTICS LIST
bleService = p.getServiceByUUID(service_uuid)
for ch in bleService.getCharacteristics():
        print str(ch)

#OBTAIN DATA FROM CHARACTERISTIC
bleSensorValue = bleService.getCharacteristics(ble_uuid)[0]
val = bleSensorValue.read()
print "Characteristic value: ", binascii.b2a_hex(val)

#WAIT FOR NOTIFICATIONS
try:
    while True:
        #if p.waitForNotifications(1.0):
        print "Characteristic value: ", binascii.b2a_hex(bleSensorValue.read())
        continue
except:
    print("Terminated")
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Creating a custom input interface

Post by arnaud »

Hi,

the easiest to get started would be to use the existing ZMQ interface, you can easily push input controls to the Crazyflie client using ZMQ from a python script. The documentation on how to enable ZMQ input is on the wiki: https://wiki.bitcraze.io/doc:crazyflie: ... put_device, and there is an example on how to generate the required messages in github: https://github.com/bitcraze/crazyflie-c ... ntinput.py.

Now, to answer more directly your question :-), if you want to implement an input driver in the Crazyflie client directly the simplest might actually be to start from the ZMQ input driver: https://github.com/bitcraze/crazyflie-c ... zmqpull.py, you can copy-paste the code and change all the names to match your driver's name. The ZMQ driver already setup a thread that will be useful to implement your reading loop. To appear in the client, you need to add you new driver to the list in the __init__.py file of the same folder: https://github.com/bitcraze/crazyflie-c ... py#L43-L53. Then your driver should appear in the list of input devices.
schmiddes
Beginner
Posts: 2
Joined: Wed Aug 15, 2018 2:21 pm

Re: Creating a custom input interface

Post by schmiddes »

Hi,

first of all thank you for your reply. After fighting with my python skills and some time setting everything up I finally got the client to recognize my input device and sending some basic control commands to the crazyflie. I took the ZMQ interface and tweaked the parameters just as you suggested, thank you :)

Kind regards
schmiddes
Post Reply