For some reason, it seems like each action (liftOff, hover, setDown, etc) happens twice on each device. This is not the behavior I expect.
One consequence of this is that when it goes to setDown, it ramps down the propellers until they stop (as expected), then it starts the setDown action again which brings the propellers back to hovering thrust and ramps them back down again while on the floor - causing them to crash.
Can someone take a look at this code and let me know why this is happening? And perhaps how else I should approach this?
Code: Select all
import math
import time
import cflib.crtp
from cflib.crazyflie.swarm import CachedCfFactory
from cflib.crazyflie.swarm import Swarm
# Change uris according to your setup
URI1 = 'radio://0/80/2M/E7E7E7E7E5'
URI2 = 'radio://0/83/2M/E7E7E7E7E7'
uris = {
URI1,
URI2
}
#MOVEMENTS
def liftOff(cf):
print("\n+++Lift off+++" )
for y in range(10):
cf.commander.send_hover_setpoint(0, 0, 0, (1-(1.1**(-y)))/2.5)
time.sleep(0.1)
def setDown(cf):
print("\n---Set down---")
for y in range(10):
#cf.commander.send_hover_setpoint(0, 0, 0, (10 - y) / 25)
cf.commander.send_hover_setpoint(0, 0, 0, (1.1**(-y))/2.5)
time.sleep(0.1)
def hover(cf):
print("\n===Hovering===")
for _ in range(20):
cf.commander.send_hover_setpoint(0, 0, 0, 0.4)
time.sleep(0.1)
def moveForward(cf):
print("\n^^^forward^^^")
for _ in range(20):
cf.commander.send_hover_setpoint(0.5, 0, 0, 0.4)
time.sleep(0.1)
def moveBackwards(cf):
print("\n\/\/\/Backwards\/\/\/")
for _ in range(20):
cf.commander.send_hover_setpoint(-0.5, 0, 0, 0.4)
time.sleep(0.1)
def stop(cf):
print("\nXXX_Stop_XXX")
cf.commander.send_stop_setpoint()
time.sleep(0.5)
#END MOVEMENTS
def reset_estimator(scf):
print("reseting state estimation")
cf = scf.cf
cf.param.set_value('kalman.resetEstimation', '1')
time.sleep(0.1)
cf.param.set_value('kalman.resetEstimation', '0')
time.sleep(2)
def sequence(scf):
cf = scf.cf
liftOff(cf)
hover(cf)
moveForward(cf)
hover(cf)
setDown(cf)
stop(cf)
liftOff(cf)
hover(cf)
moveBackwards(cf)
hover(cf)
setDown(cf)
stop(cf)
if __name__ == '__main__':
cflib.crtp.init_drivers()
factory = CachedCfFactory(rw_cache='./cache')
with Swarm(uris, factory=factory) as swarm:
swarm.parallel_safe(reset_estimator)
print("\n############flying############")
swarm.parallel_safe(sequence)