Skip to content

Commit

Permalink
Tools: ros2: Disable ament_flake, use black, enable networking
Browse files Browse the repository at this point in the history
* Everything else passes and we want DDS in CI running
* We're going to switch to black because autoformat
* Enforce formatting with black instead of flake8

Signed-off-by: Ryan Friedman <[email protected]>
  • Loading branch information
Ryanf55 committed Nov 21, 2023
1 parent adc0ebf commit 7c7abce
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ def __init__(self):
def cb(self, msg):
"""Process a Time message."""
if msg.sec:
self.get_logger().info(
"From AP : True [sec:{}, nsec: {}]".format(msg.sec, msg.nanosec)
)
self.get_logger().info("From AP : True [sec:{}, nsec: {}]".format(msg.sec, msg.nanosec))
else:
self.get_logger().info("From AP : False")

Expand Down
3 changes: 2 additions & 1 deletion Tools/ros2/ardupilot_dds_tests/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
<exec_depend>rclpy</exec_depend>
<exec_depend>socat</exec_depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_cmake_black</test_depend>
<test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend>
<test_depend>ament_pep257</test_depend>
<test_depend>ardupilot_sitl</test_depend>
<test_depend>launch</test_depend>
Expand Down
12 changes: 4 additions & 8 deletions Tools/ros2/ardupilot_dds_tests/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@
version='0.0.0',
packages=[package_name],
data_files=[
('share/ament_index/resource_index/packages',
['resource/' + package_name]),
('share/ament_index/resource_index/packages', ['resource/' + package_name]),
('share/' + package_name, ['package.xml']),
(os.path.join("share", package_name, "launch"),
glob("launch/*.launch.py")),
(os.path.join("share", package_name, "config"),
glob("config/*.parm")),
(os.path.join("share", package_name, "config"),
glob("config/*.yaml")),
(os.path.join("share", package_name, "launch"), glob("launch/*.launch.py")),
(os.path.join("share", package_name, "config"), glob("config/*.parm")),
(os.path.join("share", package_name, "config"), glob("config/*.yaml")),
],
install_requires=['setuptools'],
zip_safe=True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,18 @@ def start_subscriber(self):
depth=1,
)

self.subscription = self.create_subscription(
NavSatFix, self.topic, self.subscriber_callback, qos_profile
)
self.subscription = self.create_subscription(NavSatFix, self.topic, self.subscriber_callback, qos_profile)

# Add a spin thread.
self.ros_spin_thread = threading.Thread(
target=lambda node: rclpy.spin(node), args=(self,)
)
self.ros_spin_thread = threading.Thread(target=lambda node: rclpy.spin(node), args=(self,))
self.ros_spin_thread.start()

def subscriber_callback(self, msg):
"""Process a NavSatFix message."""
self.msg_event_object.set()

if msg.latitude:
self.get_logger().info(
"From AP : True [lat:{}, lon: {}]".format(msg.latitude, msg.longitude)
)
self.get_logger().info("From AP : True [lat:{}, lon: {}]".format(msg.latitude, msg.longitude))
else:
self.get_logger().info("From AP : False")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,18 @@ def __init__(self):

def start_subscriber(self):
"""Start the subscriber."""
self.subscription = self.create_subscription(
Time, self.topic, self.subscriber_callback, 1
)
self.subscription = self.create_subscription(Time, self.topic, self.subscriber_callback, 1)

# Add a spin thread.
self.ros_spin_thread = threading.Thread(
target=lambda node: rclpy.spin(node), args=(self,)
)
self.ros_spin_thread = threading.Thread(target=lambda node: rclpy.spin(node), args=(self,))
self.ros_spin_thread.start()

def subscriber_callback(self, msg):
"""Process a Time message."""
self.msg_event_object.set()

if msg.sec:
self.get_logger().info(
"From AP : True [sec:{}, nsec: {}]".format(msg.sec, msg.nanosec)
)
self.get_logger().info("From AP : True [sec:{}, nsec: {}]".format(msg.sec, msg.nanosec))
else:
self.get_logger().info("From AP : False")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,5 @@ def test_virtual_ports(launch_context, launch_description):
def validate_output(output):
assert "N starting data transfer loop" in output, "Test process had no output."

process_tools.assert_stderr_sync(
launch_context, virtual_ports, validate_output, timeout=5
)
process_tools.assert_stderr_sync(launch_context, virtual_ports, validate_output, timeout=5)
yield
27 changes: 0 additions & 27 deletions Tools/ros2/ardupilot_dds_tests/test/test_flake8.py

This file was deleted.

8 changes: 6 additions & 2 deletions Tools/ros2/ardupilot_sitl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ message(STATUS "WAF_COMMAND: ${WAF_COMMAND}")
set(WAF_CONFIG $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:"--debug">)

add_custom_target(ardupilot_configure ALL
${WAF_COMMAND} configure --board sitl --enable-dds ${WAF_CONFIG}
${WAF_COMMAND} configure --board sitl --enable-dds --enable-networking ${WAF_CONFIG}
WORKING_DIRECTORY ${ARDUPILOT_ROOT}
)

add_custom_target(ardupilot_build ALL
${WAF_COMMAND} build --enable-dds ${WAF_CONFIG}
${WAF_COMMAND} build --enable-dds --enable-networking ${WAF_CONFIG}
WORKING_DIRECTORY ${ARDUPILOT_ROOT}
)
add_dependencies(ardupilot_build ardupilot_configure)
Expand Down Expand Up @@ -95,6 +95,10 @@ if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()

# ament_black isn't supported in ament_lint_auto yet, so use pre-commit instead
# find_package(ament_cmake_black REQUIRED)
# ament_black()

# Add python tests.
find_package(ament_cmake_pytest REQUIRED)
set(_pytest_tests
Expand Down
14 changes: 3 additions & 11 deletions Tools/ros2/ardupilot_sitl/src/ardupilot_sitl/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,8 @@ def __init__(
"""Create an ExecuteFunction action."""
super().__init__(**left_over_kwargs)
if not callable(function):
raise TypeError(
"ExecuteFunction expected a callable for 'function', got '{}'".format(
type(function)
)
)
ensure_argument_type(
args, (collections.abc.Iterable, type(None)), "args", "ExecuteFunction"
)
raise TypeError("ExecuteFunction expected a callable for 'function', got '{}'".format(type(function)))
ensure_argument_type(args, (collections.abc.Iterable, type(None)), "args", "ExecuteFunction")
ensure_argument_type(kwargs, (dict, type(None)), "kwargs", "ExecuteFunction")
self.__function = function
self.__args = [] # type: Iterable
Expand All @@ -98,9 +92,7 @@ def action(self) -> Action:
"""Return the Action obtained by executing the function."""
return self.__action

def execute(
self, context: LaunchContext
) -> Optional[List[LaunchDescriptionEntity]]:
def execute(self, context: LaunchContext) -> Optional[List[LaunchDescriptionEntity]]:
"""Execute the function."""
action = self.__function(context, *self.__args, **self.__kwargs)
self.__action = action
Expand Down
22 changes: 6 additions & 16 deletions Tools/ros2/ardupilot_sitl/src/ardupilot_sitl/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ def generate_action(context: LaunchContext, *args, **kwargs) -> ExecuteProcess:
return action

@staticmethod
def generate_launch_description_with_actions() -> (
Tuple[LaunchDescription, Dict[Text, ExecuteFunction]]
):
def generate_launch_description_with_actions() -> Tuple[LaunchDescription, Dict[Text, ExecuteFunction]]:
"""Generate a launch description with actions."""
launch_arguments = VirtualPortsLaunch.generate_launch_arguments()

Expand Down Expand Up @@ -186,9 +184,7 @@ def generate_action(context: LaunchContext, *args, **kwargs) -> ExecuteProcess:
return node

@staticmethod
def generate_launch_description_with_actions() -> (
Tuple[LaunchDescription, Dict[Text, ExecuteFunction]]
):
def generate_launch_description_with_actions() -> Tuple[LaunchDescription, Dict[Text, ExecuteFunction]]:
"""Generate a launch description with actions."""
launch_arguments = MicroRosAgentLaunch.generate_launch_arguments()

Expand Down Expand Up @@ -315,9 +311,7 @@ def generate_action(context: LaunchContext, *args, **kwargs) -> ExecuteProcess:
return mavproxy_process

@staticmethod
def generate_launch_description_with_actions() -> (
Tuple[LaunchDescription, Dict[Text, ExecuteFunction]]
):
def generate_launch_description_with_actions() -> Tuple[LaunchDescription, Dict[Text, ExecuteFunction]]:
"""Generate a launch description for MAVProxy."""
launch_arguments = MAVProxyLaunch.generate_launch_arguments()

Expand Down Expand Up @@ -486,9 +480,7 @@ def generate_action(context: LaunchContext, *args, **kwargs) -> ExecuteProcess:
return sitl_process

@staticmethod
def generate_launch_description_with_actions() -> (
Tuple[LaunchDescription, Dict[Text, ExecuteFunction]]
):
def generate_launch_description_with_actions() -> Tuple[LaunchDescription, Dict[Text, ExecuteFunction]]:
"""Generate a launch description for SITL."""
launch_arguments = SITLLaunch.generate_launch_arguments()

Expand Down Expand Up @@ -553,8 +545,7 @@ def generate_launch_arguments() -> List[DeclareLaunchArgument]:
DeclareLaunchArgument(
"instance",
default_value="0",
description="Set instance of SITL "
"(adds 10*instance to all port numbers).",
description="Set instance of SITL " "(adds 10*instance to all port numbers).",
),
DeclareLaunchArgument(
"defaults",
Expand Down Expand Up @@ -599,8 +590,7 @@ def generate_launch_arguments() -> List[DeclareLaunchArgument]:
DeclareLaunchArgument(
"base_port",
default_value="",
description="Set port num for base port(default 5670) "
"must be before -I option.",
description="Set port num for base port(default 5670) " "must be before -I option.",
),
DeclareLaunchArgument(
"rc_in_port",
Expand Down
4 changes: 1 addition & 3 deletions Tools/ros2/ardupilot_sitl/src/ardupilot_sitl/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ def listify(fn) -> List[LaunchDescriptionEntity]:
"""Wrap a functions's return value in a list."""

@wraps(fn)
def listify_helper(
context: LaunchContext, *args, **kwargs
) -> List[LaunchDescriptionEntity]:
def listify_helper(context: LaunchContext, *args, **kwargs) -> List[LaunchDescriptionEntity]:
return [fn(context, args, kwargs)]

return listify_helper

0 comments on commit 7c7abce

Please sign in to comment.