Skip to content

Commit

Permalink
electrical_protocol: use ament_cmake_python instead of ament_python, …
Browse files Browse the repository at this point in the history
…move calculator example back to test
  • Loading branch information
cbrxyz committed Jan 2, 2025
1 parent 1bb065f commit 44f96e1
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 127 deletions.
52 changes: 52 additions & 0 deletions src/mil_common/electrical_protocol/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
cmake_minimum_required(VERSION 3.5)
project(electrical_protocol)

find_package(ament_cmake REQUIRED)
find_package(ament_cmake_python REQUIRED)
find_package(rclpy REQUIRED)

# Install the python module for this package
ament_python_install_package(${PROJECT_NAME})

# include_directories(include ${rclcpp_INCLUDE_DIRS})
# link_directories(${rclcpp_LIBRARY_DIRS})

# Add a c++ library
# add_library(${PROJECT_NAME} src/some_file.cpp)
# target_link_libraries(${PROJECT_NAME} ${rclcpp_LIBRARIES})
#
# # Install C++ headers
# install(
# DIRECTORY include/${PROJECT_NAME}/
# DESTINATION include/${PROJECT_NAME}
# FILES_MATCHING PATTERN "*.hpp")

# Install python scripts
# install(PROGRAMS test/calculator_device.py DESTINATION bin)
install(PROGRAMS
test/calculator_device.py
DESTINATION lib/${PROJECT_NAME} )

# Export package dependencies
ament_export_dependencies(ament_cmake)
ament_export_dependencies(ament_cmake_python)
ament_export_dependencies(rclpy)
# ament_export_include_directories(include ${rclcpp_INCLUDE_DIRS})
# ament_export_libraries(${PROJECT_NAME} ${rclcpp_LIBRARIES})

if(BUILD_TESTING)
find_package(ament_cmake_pytest REQUIRED)
set(_pytest_tests
test/test_simulated_basic.py
)
foreach(_test_path ${_pytest_tests})
get_filename_component(_test_name ${_test_path} NAME_WE)
ament_add_pytest_test(${_test_name} ${_test_path}
APPEND_ENV PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}
TIMEOUT 60
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
endforeach()
endif()

ament_package()

This file was deleted.

9 changes: 5 additions & 4 deletions src/mil_common/electrical_protocol/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
<maintainer email="[email protected]">Cameron Brown</maintainer>
<license>MIT</license>

<test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend>
<test_depend>ament_pep257</test_depend>
<buildtool_depend>ament</buildtool_depend>
<buildtool_depend>ament_cmake_python</buildtool_depend>
<test_depend>python3-pytest</test_depend>

<exec_depend>rclpy</exec_depend>

<export>
<build_type>ament_python</build_type>
<build_type>ament_cmake</build_type>
</export>
</package>
8 changes: 4 additions & 4 deletions src/mil_common/electrical_protocol/test/calculator_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,17 @@ def __init__(self):
def port_callback(self, msg: String):
self.connect(msg.data, 115200)

def trigger(self, _: Empty.Request, __: Empty.Response):
def trigger(self, _: Empty.Request, response: Empty.Response):
self.num_one, self.num_two = self.i, 1000 - self.i
self.i += 1
self.send_packet(
RequestAddPacket(number_one=self.num_one, number_two=self.num_two),
)
return Empty.Response()
return response

def trigger_two(self, _: Empty.Request, __: Empty.Response):
def trigger_two(self, _: Empty.Request, response: Empty.Response):
self.send_packet(CharacterPacket("a", "small"))
return Empty.Response()
return response

def on_packet_received(self, packet) -> None:
if isinstance(packet, AnswerPacket):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
def generate_test_description():
calculator_device = Node(
package="electrical_protocol",
executable="calculator",
executable="calculator_device.py",
name="calculator_device",
)

Expand Down

0 comments on commit 44f96e1

Please sign in to comment.