autonomous Sequence

Discussions about all things Bitcraze
Post Reply
florenzan21
Beginner
Posts: 1
Joined: Sat Jun 10, 2017 6:01 am

autonomous Sequence

Post by florenzan21 »

Hi guys,
I' making my first step in the "world of Bitcraze" and i need your help. I have a crazyflie 2.0, the crazyradio pa and the loco system position. I would like to use "crazyflie-lib-python" to fly crazyflie. Now i can execute some examples that i found in "crazyflie-lib-python" like basiclog, rump, ect.. but i can't use "autonomousSequence.py" in particolar i recive a error in the log config Kalman variance, the script can't found a variable toc Kalman. The code is exactly the same of "crazyflie-lib-python". I am using a linux system, and i don't know if the crazyflie it's new or an other student change the firmware. there is a method to reinitialize? thank you

the code the i would execute in python is:

Code: Select all

import time

import cflib.crtp
from cflib.crazyflie.log import LogConfig
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
from cflib.crazyflie.syncLogger import SyncLogger

# URI to the Crazyflie to connect to
uri = 'radio://0/80/2M'  #i change it, i utilize the uri of my Cf

# Change the sequence according to your setup
#             x    y    z  YAW
sequence = [
    (2.5, 2.5, 1.2, 0), 
    (2.5, 2.5, 1.2, 0),
    (2.5, 2.5, 1.2, 0),
    (2.5, 2.5, 1.2, 0), 
    (2.5, 2.5, 1.2, 0),
    (2.5, 2.5, 1.2, 0),
    (2.5, 2.5, 1.2, 0),
]


def wait_for_position_estimator(scf):
    print('Waiting for estimator to find position...')

    log_config = LogConfig(name='Kalman Variance', period_in_ms=500)
    log_config.add_variable('kalman.varPX', 'float')
    log_config.add_variable('kalman.varPY', 'float')
    log_config.add_variable('kalman.varPZ', 'float')

    var_y_history = [1000] * 10
    var_x_history = [1000] * 10
    var_z_history = [1000] * 10

    threshold = 0.001

    with SyncLogger(scf, log_config) as logger:
        for log_entry in logger:
            data = log_entry[1]

            var_x_history.append(data['kalman.varPX'])
            var_x_history.pop(0)
            var_y_history.append(data['kalman.varPY'])
            var_y_history.pop(0)
            var_z_history.append(data['kalman.varPZ'])
            var_z_history.pop(0)

            min_x = min(var_x_history)
            max_x = max(var_x_history)
            min_y = min(var_y_history)
            max_y = max(var_y_history)
            min_z = min(var_z_history)
            max_z = max(var_z_history)

            # print("{} {} {}".
            #       format(max_x - min_x, max_y - min_y, max_z - min_z))

            if (max_x - min_x) < threshold and (
                    max_y - min_y) < threshold and (
                    max_z - min_z) < threshold:
                break


def reset_estimator(scf):
    cf = scf.cf
    cf.param.set_value('kalman.resetEstimation', '1')
    time.sleep(0.1)
    cf.param.set_value('kalman.resetEstimation', '0')

    wait_for_position_estimator(cf)


def position_callback(timestamp, data, logconf):
    x = data['kalman.stateX']
    y = data['kalman.stateY']
    z = data['kalman.stateZ']
    print('pos: ({}, {}, {})'.format(x, y, z))


def start_position_printing(scf):
    log_conf = LogConfig(name='Position', period_in_ms=500)
    log_conf.add_variable('kalman.stateX', 'float')
    log_conf.add_variable('kalman.stateY', 'float')
    log_conf.add_variable('kalman.stateZ', 'float')

    scf.cf.log.add_config(log_conf)
    log_conf.data_received_cb.add_callback(position_callback)
    log_conf.start()


def run_sequence(scf, sequence):
    cf = scf.cf

    cf.param.set_value('flightmode.posSet', '1')

    for position in sequence:
        print('Setting position {}'.format(position))
        for i in range(50):
            cf.commander.send_setpoint(position[1], position[0],
                                       position[3],
                                       int(position[2] * 1000))
            time.sleep(0.1)

    cf.commander.send_setpoint(0, 0, 0, 0)
    # Make sure that the last packet leaves before the link is closed
    # since the message queue is not flushed before closing
    time.sleep(0.1)


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

    with SyncCrazyflie(uri) as scf:
        reset_estimator(scf)
        # start_position_printing(scf)
        run_sequence(scf, sequence)
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: autonomous Sequence

Post by arnaud »

Hi,
To fly in the LPS you need a version of the Crazyflie that has the kalman filter enabled. You can do that by compiling the Crazyfie by yourself with "SENSOR=kalman" in the file tools/make/config.mk or you can download the pre-compiled released firmware: https://github.com/bitcraze/crazyflie-r ... ag/2017.05
NickCong
Beginner
Posts: 29
Joined: Sun Oct 15, 2017 12:24 pm

Re: autonomous Sequence

Post by NickCong »

arnaud wrote: Tue Jun 13, 2017 12:11 pm Hi,
To fly in the LPS you need a version of the Crazyflie that has the kalman filter enabled. You can do that by compiling the Crazyfie by yourself with "SENSOR=kalman" in the file tools/make/config.mk or you can download the pre-compiled released firmware: https://github.com/bitcraze/crazyflie-r ... ag/2017.05
Hi
where is the the file tools/make/config.mk? i also have seen the same in this https://github.com/bitcraze/crazyflie-f ... d#configmk ,but i don't understand what is the root folder?does the root folder means crazyflie-firmware/tools/make/ or crazyflie-firmware/ or others?
Jens_Lee
Member
Posts: 40
Joined: Sun Nov 19, 2017 8:14 pm

Re: autonomous Sequence

Post by Jens_Lee »

The root folder for the firmware would be

Code: Select all

 crazyflie-firmware/
The config file is here

Code: Select all

crazyflie-firmware/tools/make/
NickCong
Beginner
Posts: 29
Joined: Sun Oct 15, 2017 12:24 pm

Re: autonomous Sequence

Post by NickCong »

Jens_Lee wrote: Tue Nov 28, 2017 12:57 pm The root folder for the firmware would be

Code: Select all

 crazyflie-firmware/
The config file is here

Code: Select all

crazyflie-firmware/tools/make/
Hi
thank you,does it mean i just copy the

Code: Select all

PLATFORM=CF2
DEBUG=1
CLOAD=0
SENSOR=kalman
to the crazyflie-firmware/tools/make/config.mk is ok?
Jens_Lee
Member
Posts: 40
Joined: Sun Nov 19, 2017 8:14 pm

Re: autonomous Sequence

Post by Jens_Lee »

You will need to build a new firmware and flash it. The easiest way is with the Bitcraze VM, that has everything installed already.

OR download the firmware that Arnaud referenced, and flash it through the cfclient.
Post Reply