[Solved] Simple Hover program
Posted: Mon May 19, 2014 11:11 pm
Hi all,
I made a very simple python program that simply turns on thrust to get the crazyflie in the air, and then uses the hover functionality to enable hover mode. I looked extensively at the way hover was implemented in cfclient source code, and attempted to mimic this functionality. The hover is set as such:
However, the hover mode appears to be set for about half a second, then turns off. Below is the entire source for setting hover mode:
In a different program, I printed out data from the altHold target, and observed the values. It appears that upon first setting hover mode, it works for the first half second or so, but soon it turns off, as seen in the logging debugging printout below.
Any ideas on why the hover mode is not working?
Thank you!
I made a very simple python program that simply turns on thrust to get the crazyflie in the air, and then uses the hover functionality to enable hover mode. I looked extensively at the way hover was implemented in cfclient source code, and attempted to mimic this functionality. The hover is set as such:
Code: Select all
cf.param.set_value("flightmode.althold", "True")
Code: Select all
import sys
sys.path.append("../lib")
import cflib.crtp
import time
from cflib.crazyflie import Crazyflie
# Initialize the low-level drivers (don't list the debug drivers)
cflib.crtp.init_drivers(enable_debug_driver=False)
print "Scanning interfaces for Crazyflies..."
available = cflib.crtp.scan_interfaces()
print "Crazyflies found:"
for i in available:
print i[0]
if len(available) > 0:
# Create a Crazyflie object without specifying any cache dirs
cf = Crazyflie()
def handle_connected(link_uri):
print "Connected to %s" % link_uri
print "Sending thrust 45000"
cf.commander.send_setpoint(0, 0, 0, 45000)
time.sleep(0.75)
print "Stopping thrust; hovering"
cf.commander.send_setpoint(0, 0, 0, 0)
cf.param.set_value("flightmode.althold", "True")
def close_link():
print 'Closing'
cf.commander.send_setpoint(0, 0, 0, 0)
time.sleep(0.1)
cf.close_link()
# Connect some callbacks from the Crazyflie API
cf.connected.add_callback(handle_connected)
link_uri = available[0][0]
print "Connecting to %s" % link_uri
# Try to connect to the Crazyflie
cf.open_link(link_uri)
# Variable used to keep main loop occupied until disconnect
is_connected = True
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
close_link()
else:
print "No Crazyflies found, cannot run example"
Code: Select all
[957179][Stabilizer]: {'altHold.target': 33.872318267822266, 'altHold.err': 0.1075897216796875}
[957279][Stabilizer]: {'altHold.target': 33.82230758666992, 'altHold.err': 0.11747360229492188}
[957379][Stabilizer]: {'altHold.target': 33.77229690551758, 'altHold.err': 0.11321258544921875}
[957579][Stabilizer]: {'altHold.target': 33.67227554321289, 'altHold.err': 0.3401451110839844}
[957679][Stabilizer]: {'altHold.target': 33.62226486206055, 'altHold.err': 0.3916740417480469}
[957779][Stabilizer]: {'altHold.target': 33.5722541809082, 'altHold.err': 0.3349266052246094}
[957879][Stabilizer]: {'altHold.target': 33.52224349975586, 'altHold.err': 0.3975334167480469}
[957979][Stabilizer]: {'altHold.target': 33.472232818603516, 'altHold.err': 0.43831634521484375}
[958179][Stabilizer]: {'altHold.target': 33.37221145629883, 'altHold.err': 0.5722694396972656}
[958279][Stabilizer]: {'altHold.target': 33.322200775146484, 'altHold.err': 0.6295738220214844}
[958379][Stabilizer]: {'altHold.target': 33.27219009399414, 'altHold.err': 0.6853408813476562}
[958479][Stabilizer]: {'altHold.target': 33.2221794128418, 'altHold.err': 0.699859619140625}
[958579][Stabilizer]: {'altHold.target': 33.17216873168945, 'altHold.err': 0.7846832275390625}
[958679][Stabilizer]: {'altHold.target': 33.12215805053711, 'altHold.err': 0.7600898742675781}
[958779][Stabilizer]: {'altHold.target': 33.072147369384766, 'altHold.err': 0.7624588012695312}
[958879][Stabilizer]: {'altHold.target': 33.02213668823242, 'altHold.err': 0.7686080932617188}
[958979][Stabilizer]: {'altHold.target': 32.97212600708008, 'altHold.err': 0.8769187927246094}
[959079][Stabilizer]: {'altHold.target': 32.922115325927734, 'altHold.err': 0.9493331909179688}
[959179][Stabilizer]: {'altHold.target': 0.0, 'altHold.err': 0.0}
[959279][Stabilizer]: {'altHold.target': 0.0, 'altHold.err': 0.0}
... etc.
Thank you!