Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
crazyflie-lib-python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lukas Wegmann
crazyflie-lib-python
Commits
27c2bad0
Commit
27c2bad0
authored
8 years ago
by
Arnaud Taffanel
Browse files
Options
Downloads
Patches
Plain Diff
Closes #40: Add support for rebooting LPS nodes
parent
2ed27b8c
No related branches found
No related tags found
Loading
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/lps_reboot_to_bootloader.py
+108
-0
108 additions, 0 deletions
examples/lps_reboot_to_bootloader.py
lpslib/lopoanchor.py
+8
-0
8 additions, 0 deletions
lpslib/lopoanchor.py
with
116 additions
and
0 deletions
examples/lps_reboot_to_bootloader.py
0 → 100644
+
108
−
0
View file @
27c2bad0
# -*- coding: utf-8 -*-
#
# || ____ _ __
# +------+ / __ )(_) /_______________ _____ ___
# | 0xBC | / __ / / __/ ___/ ___/ __ `/_ / / _ \
# +------+ / /_/ / / /_/ /__/ / / /_/ / / /_/ __/
# || || /_____/_/\__/\___/_/ \__,_/ /___/\___/
#
# Copyright (C) 2017 Bitcraze AB
#
# Crazyflie Nano Quadcopter Client
#
# 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.
"""
Simple example that connects to the first Crazyflie found, and then sends the
reboot signals to 6 anchors ID from 0 to 5. The reset signals is sent
10 times in a row to make sure all anchors are reset to bootloader.
"""
import
logging
import
time
from
threading
import
Thread
import
cflib
from
cflib.crazyflie
import
Crazyflie
from
lpslib.lopoanchor
import
LoPoAnchor
logging
.
basicConfig
(
level
=
logging
.
ERROR
)
class
LpsRebootToBootloader
:
"""
Example that connects to a Crazyflie and ramps the motors up/down and
the disconnects
"""
def
__init__
(
self
,
link_uri
):
"""
Initialize and run the example with the specified link_uri
"""
self
.
_cf
=
Crazyflie
()
self
.
_cf
.
connected
.
add_callback
(
self
.
_connected
)
self
.
_cf
.
disconnected
.
add_callback
(
self
.
_disconnected
)
self
.
_cf
.
connection_failed
.
add_callback
(
self
.
_connection_failed
)
self
.
_cf
.
connection_lost
.
add_callback
(
self
.
_connection_lost
)
self
.
_cf
.
open_link
(
link_uri
)
print
(
'
Connecting to %s
'
%
link_uri
)
def
_connected
(
self
,
link_uri
):
"""
This callback is called form the Crazyflie API when a Crazyflie
has been connected and the TOCs have been downloaded.
"""
# Start a separate thread to do the motor test.
# Do not hijack the calling thread!
Thread
(
target
=
self
.
_reboot_thread
).
start
()
def
_connection_failed
(
self
,
link_uri
,
msg
):
"""
Callback when connection initial connection fails (i.e no Crazyflie
at the specified address)
"""
print
(
'
Connection to %s failed: %s
'
%
(
link_uri
,
msg
))
def
_connection_lost
(
self
,
link_uri
,
msg
):
"""
Callback when disconnected after a connection has been made (i.e
Crazyflie moves out of range)
"""
print
(
'
Connection to %s lost: %s
'
%
(
link_uri
,
msg
))
def
_disconnected
(
self
,
link_uri
):
"""
Callback when the Crazyflie is disconnected (called in all cases)
"""
print
(
'
Disconnected from %s
'
%
link_uri
)
def
_reboot_thread
(
self
):
anchors
=
LoPoAnchor
(
self
.
_cf
)
print
(
'
Sending reboot signal to all anchors 10 times in a row ...
'
)
for
retry
in
range
(
10
):
for
anchor_id
in
range
(
6
):
anchors
.
reboot
(
anchor_id
,
anchors
.
REBOOT_TO_BOOTLOADER
)
time
.
sleep
(
0.1
)
self
.
_cf
.
close_link
()
if
__name__
==
'
__main__
'
:
# Initialize the low-level drivers (don't list the debug drivers)
cflib
.
crtp
.
init_drivers
(
enable_debug_driver
=
False
)
# Scan for Crazyflies and use the first one found
print
(
'
Scanning interfaces for Crazyflies...
'
)
available
=
cflib
.
crtp
.
scan_interfaces
()
print
(
'
Crazyflies found:
'
)
for
i
in
available
:
print
(
i
[
0
])
if
len
(
available
)
>
0
:
le
=
LpsRebootToBootloader
(
available
[
0
][
0
])
else
:
print
(
'
No Crazyflies found, cannot run example
'
)
This diff is collapsed.
Click to expand it.
lpslib/lopoanchor.py
+
8
−
0
View file @
27c2bad0
...
@@ -29,6 +29,10 @@ import struct
...
@@ -29,6 +29,10 @@ import struct
class
LoPoAnchor
():
class
LoPoAnchor
():
LPP_TYPE_POSITION
=
1
LPP_TYPE_POSITION
=
1
LPP_TYPE_REBOOT
=
2
REBOOT_TO_BOOTLOADER
=
0
REBOOT_TO_FIRMWARE
=
1
def
__init__
(
self
,
crazyflie
):
def
__init__
(
self
,
crazyflie
):
"""
"""
...
@@ -49,3 +53,7 @@ class LoPoAnchor():
...
@@ -49,3 +53,7 @@ class LoPoAnchor():
data
=
struct
.
pack
(
'
<Bfff
'
,
LoPoAnchor
.
LPP_TYPE_POSITION
,
x
,
y
,
z
)
data
=
struct
.
pack
(
'
<Bfff
'
,
LoPoAnchor
.
LPP_TYPE_POSITION
,
x
,
y
,
z
)
self
.
crazyflie
.
loc
.
send_short_lpp_packet
(
anchor_id
,
data
)
self
.
crazyflie
.
loc
.
send_short_lpp_packet
(
anchor_id
,
data
)
def
reboot
(
self
,
anchor_id
,
mode
):
data
=
struct
.
pack
(
'
<BB
'
,
LoPoAnchor
.
LPP_TYPE_REBOOT
,
mode
)
self
.
crazyflie
.
loc
.
send_short_lpp_packet
(
anchor_id
,
data
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment