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

Discussions about all things Bitcraze
Post Reply
aqqz
Beginner
Posts: 16
Joined: Wed Nov 18, 2020 1:40 am

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

Post 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)
        
Last edited by aqqz on Wed Dec 02, 2020 2:37 am, edited 1 time in total.
kimberly
Bitcraze
Posts: 1050
Joined: Fri Jul 06, 2018 11:13 am

Re: How to use python to restart the crazyflie?

Post by kimberly »

Hi!

Have you looked at the reboot script in the crazyflie-firmware repo? That is doing exactly what you need.
aqqz
Beginner
Posts: 16
Joined: Wed Nov 18, 2020 1:40 am

Re: How to use python to restart the crazyflie?

Post 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'
kimberly
Bitcraze
Posts: 1050
Joined: Fri Jul 06, 2018 11:13 am

Re: How to use python to restart the crazyflie?

Post 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?
aqqz
Beginner
Posts: 16
Joined: Wed Nov 18, 2020 1:40 am

Re: How to use python to restart the crazyflie?

Post 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
kimberly
Bitcraze
Posts: 1050
Joined: Fri Jul 06, 2018 11:13 am

Re: How to use python to restart the crazyflie?

Post 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.
aqqz
Beginner
Posts: 16
Joined: Wed Nov 18, 2020 1:40 am

Re: How to use python to restart the crazyflie?

Post 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.
aqqz
Beginner
Posts: 16
Joined: Wed Nov 18, 2020 1:40 am

Re: How to use python to restart the crazyflie?

Post by aqqz »

I install the cflib on the Windows,now it works well,thank you i will close the topic.
Post Reply