-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathposition_commander_demo.py
84 lines (69 loc) · 2.79 KB
/
position_commander_demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# -*- coding: utf-8 -*-
#
# || ____ _ __
# +------+ / __ )(_) /_______________ _____ ___
# | 0xBC | / __ / / __/ ___/ ___/ __ `/_ / / _ \
# +------+ / /_/ / / /_/ /__/ / / /_/ / / /_/ __/
# || || /_____/_/\__/\___/_/ \__,_/ /___/\___/
#
# Copyright (C) 2018 Bitcraze AB
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
"""
This script shows the basic use of the PositionHlCommander class.
Simple example that connects to the crazyflie at `URI` and runs a
sequence. This script requires some kind of location system.
The PositionHlCommander uses position setpoints.
Change the URI variable to your Crazyflie configuration.
"""
import cflib.crtp
import time
from cflib.crazyflie import Crazyflie
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
from cflib.positioning.position_hl_commander import PositionHlCommander
# URI to the Crazyflie to connect to
uri = 'radio://0/10/2M/E7E7E7E7E7'
def slightly_more_complex_usage():
with SyncCrazyflie(uri, cf=Crazyflie(rw_cache='./cache')) as scf:
with PositionHlCommander(
scf,
x=1.0, y=1.0, z=0.0,
default_velocity=0.3,
default_height=0.5,
controller=PositionHlCommander.CONTROLLER_MELLINGER) as pc:
# Go to a coordinate
pc.go_to(2.0, 2.0, 1)
time.sleep(2)
# Move relative to the current position
# pc.go_to(1.0, 4.0)
# Go to a coordinate and use default height
# pc.go_to(2.0, 4.0)
# Go slowly to a coordinate
# pc.go_to(2.0, 2.0)
# Set new default velocity and height
#pc.set_default_velocity(0.3)
#pc.set_default_height(1.0)
#pc.go_to(0.0, 0.0)
def simple_sequence():
with SyncCrazyflie(uri, cf=Crazyflie(rw_cache='./cache')) as scf:
with PositionHlCommander(scf) as pc:
pc.forward(1.0)
pc.left(1.0)
pc.back(1.0)
pc.go_to(1.0, 2.0, 1.0)
if __name__ == '__main__':
cflib.crtp.init_drivers(enable_debug_driver=False)
# simple_sequence()
slightly_more_complex_usage()