Page 1 of 1

[SOLVED] How to use python to restart the crazyflie?

Posted: Sun Nov 29, 2020 7:55 am
by aqqz
Hi,i want to now how to use python to restart the crazyflie? i find cflib/utils/power_switch.py,but i don`t know how to use it. it always run error with crazyradio or crtp.
The following is my code:

Code: Select all

import time

import cflib.crtp
from cflib.drivers.crazyradio import Crazyradio

from cflib.crazyflie import Crazyflie
from cflib.crazyflie.log import LogConfig
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
from cflib.crazyflie.syncLogger import SyncLogger
from cflib.utils.power_switch import PowerSwitch


uri = 'radio://0/10/2M/E7E7E7E712'


if __name__ == '__main__':
    cflib.crtp.init_drivers(enable_debug_driver=False)

    with SyncCrazyflie(uri,cf=Crazyflie(rw_cache='./cache')) as scf:
        cf = scf.cf

        ps = PowerSwitch(uri)
        ps.stm_power_down()
        time.sleep(3)
        ps.stm_power_up()
        time.sleep(3)
        

Re: How to use python to restart the crazyflie?

Posted: Mon Nov 30, 2020 7:52 am
by kimberly
Hi!

Have you looked at the reboot script in the crazyflie-firmware repo? That is doing exactly what you need.

Re: How to use python to restart the crazyflie?

Posted: Mon Nov 30, 2020 12:56 pm
by aqqz
I try to run as prompted,the following is my console output:

Code: Select all

tz@ubuntu:~/crazyflie/crazyflie-firmware$ python3 tools/utils/reboot.py 
Error: uri is missing
Usage: tools/utils/reboot.py uri

Code: Select all

tz@ubuntu:~/crazyflie/crazyflie-firmware$ python3 tools/utils/reboot.py radio://0/10/2M/E7E7E7E710
Traceback (most recent call last):
  File "tools/utils/reboot.py", line 33, in <module>
    PowerSwitch(sys.argv[1]).stm_power_cycle()
  File "/home/tz/crazyflie/crazyflie-lib-python/cflib/utils/power_switch.py", line 63, in stm_power_cycle
    self.stm_power_down()
  File "/home/tz/crazyflie/crazyflie-lib-python/cflib/utils/power_switch.py", line 54, in stm_power_down
    self._send(self.BOOTLOADER_CMD_SYSOFF)
  File "/home/tz/crazyflie/crazyflie-lib-python/cflib/utils/power_switch.py", line 79, in _send
    if res.ack:
AttributeError: 'NoneType' object has no attribute 'ack'

Re: How to use python to restart the crazyflie?

Posted: Tue Dec 01, 2020 7:49 am
by kimberly
Probably you have installed an older version of the cflib. Could you check that with:

Code: Select all

pip freeze | grep cflib
And show the output here.

Also, which firmware version are you using on your crazyflie?

Re: How to use python to restart the crazyflie?

Posted: Tue Dec 01, 2020 1:49 pm
by aqqz
This is my console output, my firmware version is 2020.09

Code: Select all

-e git+https://github.com/bitcraze/crazyflie-lib-python.git@0c70f88e407129cbe91281867cde9e165ab20e3c#egg=cflib

Re: How to use python to restart the crazyflie?

Posted: Tue Dec 01, 2020 3:23 pm
by kimberly
your cflib seems to be after this reboot functionality has been implemented....

So I tried it with firmware 2019.01 and cflib version 0.1.11 (which is the last version feature will work on). It works fine for me.

Could you reinstall the cflib to the latest release?:

Code: Select all

pip3 install cflib==0.1.12.1
and then please try again. Also make sure that radio://0/10/2M/E7E7E7E710 is indeedd the right address for your crazyflie.

Re: How to use python to restart the crazyflie?

Posted: Wed Dec 02, 2020 2:16 am
by aqqz
I reinstall my cflib and it prompt I have installed,the function can close crazyflie by not restart it and output error as I gived,i think the PA don`t receive the ack from crazyflie.my test environment is ubuntu 18.04.

Re: How to use python to restart the crazyflie?

Posted: Wed Dec 02, 2020 2:36 am
by aqqz
I install the cflib on the Windows,now it works well,thank you i will close the topic.