Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
ros_parse_data
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
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Houssaini Ziyad
ros_parse_data
Commits
99f1b35c
Commit
99f1b35c
authored
1 year ago
by
Houssaini Ziyad
Browse files
Options
Downloads
Patches
Plain Diff
Add new directory containing python parser ros
parent
fa7392cf
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
python_parser_ros/display_topics.py
+44
-0
44 additions, 0 deletions
python_parser_ros/display_topics.py
python_parser_ros/save_topics_format.py
+68
-0
68 additions, 0 deletions
python_parser_ros/save_topics_format.py
with
112 additions
and
0 deletions
python_parser_ros/display_topics.py
0 → 100644
+
44
−
0
View file @
99f1b35c
import
os
import
argparse
#La bibliothèque permettant de lire les fichiers rosbag (ROS1 Noetic)
from
bagpy
import
bagreader
import
pandas
as
pd
import
shutil
def
save_rosbags_topics
(
file_name
:
str
,
directory
:
str
):
"""
This function export all the informations from the ROSBAG into a csv file
which contains the topics, the variable types, the number of samples and the frequency
samples. The most interesting part it is the topic name inorder to extract all the data
saved in this topic
"""
if
(
directory
not
in
os
.
listdir
()):
os
.
mkdir
(
directory
)
else
:
shutil
.
rmtree
(
directory
)
os
.
mkdir
(
directory
)
for
content
in
file_name
:
content_split
=
content
.
split
(
"
/
"
)[
-
1
]
#Case when you specify the directory containing the rosbags files or read directory the file
b
=
bagreader
(
content
)
df_topics
=
b
.
topic_table
df_topics
.
to_csv
(
os
.
path
.
join
(
directory
,
content_split
[:
-
5
]
+
'
.csv
'
))
print
(
"
Save the topics in csv format : {} and the name is {}
"
.
format
(
directory
,
content_split
[:
-
5
]
+
'
.csv
'
))
if
__name__
==
"
__main__
"
:
parser
=
argparse
.
ArgumentParser
(
description
=
"
Export all topics into a csv format
"
)
parser
.
add_argument
(
'
filenames
'
,
type
=
str
,
nargs
=
'
+
'
,
help
=
'
Can support read one or multplies bagfile
'
)
parser
.
add_argument
(
'
-d
'
,
'
--output_directory
'
,
help
=
'
Folder Name to export all csv topics files
'
)
args
=
parser
.
parse_args
()
save_rosbags_topics
(
args
.
filenames
,
args
.
output_directory
)
This diff is collapsed.
Click to expand it.
python_parser_ros/save_topics_format.py
0 → 100644
+
68
−
0
View file @
99f1b35c
from
scipy.io
import
savemat
from
bagpy
import
bagreader
import
bagpy
import
pandas
as
pd
import
os
import
argparse
import
shutil
def
convert_topics_to_file
(
files
,
topics
,
directory
):
if
(
directory
not
in
os
.
listdir
()):
os
.
mkdir
(
directory
)
else
:
shutil
.
rmtree
(
directory
)
os
.
mkdir
(
directory
)
for
file
in
files
:
b
=
bagreader
(
file
)
for
topic
in
topics
:
try
:
data_frame_string
=
b
.
message_by_topic
(
topic
)
data_frame
=
pd
.
read_csv
(
data_frame_string
)
file_split
=
file
.
split
(
'
/
'
)[
-
1
][:
-
4
]
if
(
file_split
not
in
os
.
listdir
(
directory
)):
os
.
mkdir
(
os
.
path
.
join
(
directory
,
file_split
))
else
:
shutil
.
rmtree
(
os
.
path
.
join
(
directory
,
file_split
))
os
.
mkdir
(
os
.
path
.
join
(
directory
,
file_split
))
data_frame
.
to_csv
(
os
.
path
.
join
(
directory
,
file_split
,
file_split
+
'
.csv
'
))
print
(
"
Convert the topic {} to a csv format in the directory {}
"
.
format
(
topic
,
os
.
path
.
join
(
directory
,
file_split
)))
data_mat
=
data_frame
.
to_dict
(
'
list
'
)
topic_name
=
topic
.
replace
(
'
/
'
,
'
_
'
)
savemat
(
os
.
path
.
join
(
directory
,
file_split
,
file_split
+
'
.mat
'
)
,
data_mat
)
print
(
"
Convert the topic {} to a matlab format in the directory {}
"
.
format
(
topic
,
os
.
path
.
join
(
directory
,
file_split
+
'
.mat
'
)))
except
Exception
as
e
:
print
(
'
Unable to read the topic or other probles ... {}
'
.
format
(
e
))
if
__name__
==
"
__main__
"
:
parser
=
argparse
.
ArgumentParser
(
description
=
"
Export all topics into a csv format or matlab format
"
)
parser
.
add_argument
(
'
files
'
,
nargs
=
'
+
'
,
type
=
str
,
help
=
"
Read the rosbag files
"
)
parser
.
add_argument
(
'
-t
'
,
'
--topics
'
,
nargs
=
'
+
'
,
help
=
"
Read different topics save to the rosbags
"
)
parser
.
add_argument
(
'
-d
'
,
'
--directory_output
'
,
help
=
"
Save the output data
"
)
args
=
parser
.
parse_args
()
print
(
args
.
files
,
args
.
topics
,
args
.
directory_output
)
convert_topics_to_file
(
args
.
files
,
args
.
topics
,
args
.
directory_output
)
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