Skip to content
This repository has been archived by the owner on Aug 6, 2024. It is now read-only.

chore: debug #3

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true
},
{
"name": "main (Workspace must be sourced before execution)",
"type": "python",
"request": "launch",
"program": "autoware_msg_bag_converter/main.py",
"console": "integratedTerminal",
"args": ["$HOME/data/sample-rosbag", "$HOME/data/converted-rosbag"]
}
]
}
20 changes: 3 additions & 17 deletions autoware_msg_bag_converter/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@
# https://github.com/ros2/rosbag2/blob/rolling/rosbag2_py/test/test_sequential_writer.py
# https://github.com/ros2/rosbag2/blob/rolling/rosbag2_py/test/test_reindexer.py

from typing import Any

from rosbag2_py import Reindexer
from rosbag2_py import TopicMetadata

from autoware_msg_bag_converter.bag import create_reader
from autoware_msg_bag_converter.bag import create_writer
from autoware_msg_bag_converter.bag import get_default_storage_options
from autoware_msg_bag_converter.msg import * # noqa


def change_topic_type(old_type: TopicMetadata) -> TopicMetadata:
Expand All @@ -36,16 +33,6 @@ def change_topic_type(old_type: TopicMetadata) -> TopicMetadata:
)


def convert_msg(old_msg: Any) -> Any:
old_representation = repr(old_msg)
# If the type of old_msg is not of type autoware_auto, old_msg is returned as is
# Because if the message type is not sourced when executing eval, a runtime error will occur.
if "autoware_auto_" not in old_representation:
return old_msg
new_representation = old_representation.replace("autoware_auto_", "autoware_")
return eval(new_representation) # noqa


def convert_bag(input_bag_path: str, output_bag_path: str) -> None:
# open reader
reader = create_reader(input_bag_path)
Expand All @@ -61,11 +48,10 @@ def convert_bag(input_bag_path: str, output_bag_path: str) -> None:
)
writer.create_topic(new_topic_type)

# convert msg type and write to output bag
# copy data from input bag to output bag
while reader.has_next():
topic_name, old_msg, stamp = reader.read_next()
new_msg = convert_msg(old_msg)
writer.write(topic_name, new_msg, stamp)
topic_name, msg, stamp = reader.read_next()
writer.write(topic_name, msg, stamp)

# reindex to update metadata.yaml
del writer
Expand Down
26 changes: 0 additions & 26 deletions autoware_msg_bag_converter/msg.py

This file was deleted.

23 changes: 0 additions & 23 deletions test/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import autoware_auto_vehicle_msgs.msg as auto_vehicle
import autoware_vehicle_msgs.msg as aw_vehicle
from builtin_interfaces.msg import Time
from rclpy.clock import Clock
from rosbag2_py import TopicMetadata

from autoware_msg_bag_converter.converter import change_topic_type
from autoware_msg_bag_converter.converter import convert_msg


def get_time_now() -> Time:
stamp = Clock().now()
return stamp.to_msg()


def test_change_topic_type() -> None:
Expand All @@ -37,16 +27,3 @@ def test_change_topic_type() -> None:
assert new_type.name == "/vehicle/status/control_mode"
assert new_type.type == "autoware_vehicle_msgs/msg/ControlModeReport"
assert new_type.serialization_format == "cdr"


def test_convert_msg() -> None:
now = get_time_now()
auto_control_report = auto_vehicle.ControlModeReport(
stamp=now,
mode=auto_vehicle.ControlModeReport.AUTONOMOUS,
)
aw_control_report = convert_msg(auto_control_report)
assert aw_control_report == aw_vehicle.ControlModeReport(
stamp=now,
mode=aw_vehicle.ControlModeReport.AUTONOMOUS,
)
Loading