Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MicroCART
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Distributed Autonomous Networked Control Lab
MicroCART
Commits
ae9599eb
Commit
ae9599eb
authored
1 year ago
by
488_MP-4
Browse files
Options
Downloads
Patches
Plain Diff
created LogfileHandler class
parent
14671622
No related branches found
No related tags found
5 merge requests
!106
Adding Pycrocart 2.1
,
!104
adding cflib to this branch
,
!103
Updating develop to current state of master branch
,
!98
Pycrocart 2.1 will
,
!94
Merge cflib adapter into main
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cflib_groundstation/LogfileHandler.py
+105
-0
105 additions, 0 deletions
cflib_groundstation/LogfileHandler.py
cflib_groundstation/crazyflie_connection.py
+0
-53
0 additions, 53 deletions
cflib_groundstation/crazyflie_connection.py
with
105 additions
and
53 deletions
cflib_groundstation/LogfileHandler.py
+
105
−
0
View file @
ae9599eb
from
datetime
import
datetime
from
email.utils
import
localtime
from
time
import
time
from
typing
import
List
import
time
import
struct
import
cflib.crtp
from
cflib.crazyflie
import
Crazyflie
from
cflib.crazyflie.syncCrazyflie
import
SyncCrazyflie
from
queue
import
Queue
#import groundstation_socket as gs
import
uCartCommander
from
groundstation_socket
import
MessageTypeID
from
SetpointHandler
import
SetpointHandler
,
FlightMode
from
cflib.crazyflie.log
import
LogConfig
import
numpy
as
np
class
LogfileHandler
:
"""
Handles all interactions with cflib.
"""
def
__init__
(
self
):
"""
Initialize the start time, the logging queue which is given to the
plotting window, and set the synchronous crazyflie connection by
default to None. This should be set to the crazyflie when connecting
to one.
"""
# Get the start time, so that the timestamp returned to the user will
# be in seconds since startup.
self
.
start_time
=
time
.
time
()
# self.logging_queue = Queue()
self
.
scf
=
None
self
.
is_connected
=
False
self
.
param_callback_count
=
0
self
.
logging_configs
=
[]
def
add_log_config
(
self
,
name
:
str
,
period
:
int
,
variables
:
List
[
str
]):
"""
Add a logging config. Used from logging tab when refreshing
logging variables. Add callback to route logged data to logging
queue.
"""
print
(
"
Name:
"
+
name
+
"
, period:
"
+
str
(
period
)
+
"
, variables:
"
+
str
(
variables
))
logging_group
=
LogConfig
(
name
=
name
,
period_in_ms
=
period
)
for
variable
in
variables
:
logging_group
.
add_variable
(
variable
,
'
float
'
)
self
.
logging_configs
.
append
(
logging_group
)
self
.
logging_configs
[
-
1
].
data_received_cb
.
add_callback
(
self
.
logging_callback
)
self
.
scf
.
cf
.
log
.
add_config
(
self
.
logging_configs
[
-
1
])
def
refresh_logging_configs
()
:
raise
Exception
def
load_logging_configs
()
:
raise
Exception
def
clear_logging_configs
(
self
):
"""
Stop logging and clear configuration. Used when refreshing
logging to stop anything that has configured to be logged from
logging.
"""
self
.
stop_logging
()
self
.
logging_configs
=
[]
# done refreshing toc is a callback function that is triggered when
# refresh toc is done executing.
self
.
scf
.
cf
.
log
.
refresh_toc
(
self
.
done_refreshing_toc
,
self
.
scf
.
cf
.
log
.
_toc_cache
)
# Blocks until toc is done refreshing.
while
self
.
param_callback_count
<
1
:
time
.
sleep
(
0.01
)
self
.
param_callback_count
=
0
# grabs new toc values
self
.
scf
.
wait_for_params
()
def
resume_logging_configs
():
raise
Exception
def
pause_logging_configs
():
raise
Exception
def
enable_logging
(
self
):
"""
Begins logging all configured logging blocks. This is used from
the controls tab when hitting begin logging.
"""
for
i
in
range
(
0
,
len
(
self
.
logging_configs
)):
self
.
logging_configs
[
i
].
start
()
def
disable_logging
(
self
):
"""
Stops logging all configured logging blocks. This is used from
the controls tab when hitting pause logging.
"""
for
i
in
range
(
0
,
len
(
self
.
logging_configs
)):
self
.
logging_configs
[
i
].
stop
()
This diff is collapsed.
Click to expand it.
cflib_groundstation/crazyflie_connection.py
+
0
−
53
View file @
ae9599eb
...
@@ -304,56 +304,3 @@ class CrazyflieConnection:
...
@@ -304,56 +304,3 @@ class CrazyflieConnection:
file
.
close
()
file
.
close
()
return
filename
return
filename
def
add_log_config
(
self
,
name
:
str
,
period
:
int
,
variables
:
List
[
str
]):
"""
Add a logging config. Used from logging tab when refreshing
logging variables. Add callback to route logged data to logging
queue.
"""
print
(
"
Name:
"
+
name
+
"
, period:
"
+
str
(
period
)
+
"
, variables:
"
+
str
(
variables
))
logging_group
=
LogConfig
(
name
=
name
,
period_in_ms
=
period
)
for
variable
in
variables
:
logging_group
.
add_variable
(
variable
,
'
float
'
)
self
.
logging_configs
.
append
(
logging_group
)
self
.
logging_configs
[
-
1
].
data_received_cb
.
add_callback
(
self
.
logging_callback
)
self
.
scf
.
cf
.
log
.
add_config
(
self
.
logging_configs
[
-
1
])
def
clear_logging_configs
(
self
):
"""
Stop logging and clear configuration. Used when refreshing
logging to stop anything that has configured to be logged from
logging.
"""
self
.
stop_logging
()
self
.
logging_configs
=
[]
# done refreshing toc is a callback function that is triggered when
# refresh toc is done executing.
self
.
scf
.
cf
.
log
.
refresh_toc
(
self
.
done_refreshing_toc
,
self
.
scf
.
cf
.
log
.
_toc_cache
)
# Blocks until toc is done refreshing.
while
self
.
param_callback_count
<
1
:
time
.
sleep
(
0.01
)
self
.
param_callback_count
=
0
# grabs new toc values
self
.
scf
.
wait_for_params
()
def
done_refreshing_toc
(
self
,
*
_args
):
"""
Callback for flow control, increments param callback count to
allow exit of while loop.
"""
self
.
param_callback_count
=
1
def
start_logging
(
self
):
"""
Begins logging all configured logging blocks. This is used from
the controls tab when hitting begin logging.
"""
for
i
in
range
(
0
,
len
(
self
.
logging_configs
)):
self
.
logging_configs
[
i
].
start
()
def
stop_logging
(
self
):
"""
Stops logging all configured logging blocks. This is used from
the controls tab when hitting pause logging.
"""
for
i
in
range
(
0
,
len
(
self
.
logging_configs
)):
self
.
logging_configs
[
i
].
stop
()
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