I've been able to develop a controller to fly my Crazyflie 2.0 getting the inputs from my HTML5 user interface: using the HTML5 gamepad API, the client gets the inputs from any controller, sends them to the server, where they are stored in a MongoDB database, and the python controller gets the inputs and sets roll, pitch, yaw and thrust using crazyflie.commander.send_setpoint(roll, pitch, yaw, thrust).
This works fine, it's very responsive and flying the drone is breeze.
However, I'm now trying to set the parameters of the LED Ring using the same python API and I'm running into problems. Here's the code:
Code: Select all
import sys
import time
sys.path.append("crazyflie/lib")
import cflib.crtp
from cflib.crazyflie import Crazyflie
from threading import Thread
import logging
crazyflie = Crazyflie()
logging.basicConfig(level=logging.ERROR)
cflib.crtp.init_drivers(enable_debug_driver=False)
def connected(link_uri):
print "Connected"
crazyflie.param.set_value("ring.headlightEnable", str(1))
time.sleep(5)
crazyflie.param.set_value("ring.headlightEnable", str(0))
time.sleep(5)
crazyflie.param.set_value("ring.headlightEnable", str(1))
def param_updated_callback(name, value):
print("Update Callback:"+str(name)+" "+str(value))
def connection_failed(link_uri, msg):
print "Connection failed"
def connection_lost(link_uri, msg):
print "Connection lost"
def disconnected(link_uri):
print "Disconnected"
print "Scanning interfaces for Crazyflies..."
available = cflib.crtp.scan_interfaces()
if len(available) >= 1:
print "Crazyflies found:"
print str(available)
link = available[0][0]
for i in xrange(1, len(available)):
if "80" in available[i][0]:
link = available[i][0]
print("Connecting to:" + link)
crazyflie.connected.add_callback(connected)
crazyflie.disconnected.add_callback(disconnected)
crazyflie.connection_failed.add_callback(connection_failed)
crazyflie.connection_lost.add_callback(connection_lost)
crazyflie.param.add_update_callback("ring", "headlightEnable", param_updated_callback)
crazyflie.open_link(link)
else:
print "No Crazyflies found"
Establishes a connection and once connected turns the headlight on, waits 5 seconds, turns it off and after another 5 seconds, turns it back on.
The problem is, it seems like it only registers the first param.set_value. The headlight turns on and never turns off. The param update callback outputs the following:
Code: Select all
Connected
Update Callback:ring.headlightEnable 1
Update Callback:ring.headlightEnable 1
Update Callback:ring.headlightEnable 1
Update Callback:ring.headlightEnable 1
I've tested the LED ring using cfclient, and it works fine, the headlights turn on and off without a hitch.
Does anyone have an idea of what I'm missing here? Any help is much appreciated. Thanks in advance.