Skip to content

Commit

Permalink
added CLI arguement for enabling mock data node
Browse files Browse the repository at this point in the history
  • Loading branch information
alberto-escobar committed Nov 3, 2024
1 parent 5724251 commit 4fe4d90
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/boat_simulator/boat_simulator/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ class BoatProperties:
# CLI argument name for data collection option
DATA_COLLECTION_CLI_ARG_NAME = "--enable-data-collection"

# CLI argument name for data collection option
MOCK_DATA_CLI_ARG_NAME = "--enable-mock-data"

# Enumerated orientation indices since indexing pitch, roll, and yaw could be arbitrary
ORIENTATION_INDICES = Enum("ORIENTATION_INDICES", ["PITCH", "ROLL", "YAW"], start=0) # x, y, x

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import random
import sys

import rclpy
from custom_interfaces.msg import DesiredHeading, HelperHeading, SailCmd
Expand Down Expand Up @@ -70,7 +71,20 @@ def publish_mock_sail_trim_tab_angle(self):
def main(args=None):
rclpy.init(args=args)
node = MockDataNode()
rclpy.spin(node)
if is_mock_data_enabled():
try:
rclpy.spin(node)
finally:
rclpy.shutdown()


def is_mock_data_enabled() -> bool:
try:
is_mock_data_enabled_index = sys.argv.index(Constants.MOCK_DATA_CLI_ARG_NAME) + 1
is_mock_data_enabled = sys.argv[is_mock_data_enabled_index] == "true"
except ValueError:
is_mock_data_enabled = False
return is_mock_data_enabled


if __name__ == "__main__":
Expand Down
10 changes: 8 additions & 2 deletions src/boat_simulator/launch/main_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
choices=["true", "false"],
description="Enable data collection in the boat simulator",
),
DeclareLaunchArgument(
name="enable-mock-data",
default_value="false",
choices=["true", "false"],
description="Enable generation of mock data from pathfinding",
),
]


Expand Down Expand Up @@ -200,8 +206,8 @@ def get_mock_data_description(context: LaunchContext) -> Node:
]
# may not need local arguments.
local_arguments: List[SomeSubstitutionsType] = [
Constants.MULTITHREADING_CLI_ARG_NAME,
[LaunchConfiguration("enable_sim_multithreading")],
Constants.MOCK_DATA_CLI_ARG_NAME,
[LaunchConfiguration("enable-mock-data")],
]

node = Node(
Expand Down

0 comments on commit 4fe4d90

Please sign in to comment.