Skip to content

Commit

Permalink
Add basic numpy conversions (#18)
Browse files Browse the repository at this point in the history
* Add basic numpy conversions

* Add unittests | Fix bugs

* Add .gitignore

* Fix feedforward in unittests

* Fix docstrings
  • Loading branch information
Kotochleb authored Nov 26, 2024
1 parent a98c7ee commit aa6ce78
Show file tree
Hide file tree
Showing 6 changed files with 630 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Byte-compiled / optimized / DLL files
**/__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Linter cache
*.ruff_cache

# Colcon custom files
COLCON_IGNORE
AMENT_IGNORE

# VS Code
.vscode
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,28 @@ if(BUILD_TESTING)
ament_add_gtest(test_eigen_conversions tests/test_eigen_conversions.cpp
tests/gtest_main.cpp)
target_link_libraries(test_eigen_conversions ${PROJECT_NAME}_conversion)

find_package(ament_cmake_pytest REQUIRED)
set(_pytest_tests
tests/test_numpy_conversions.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()

#
# Install
#

# Install Python modules
ament_python_install_package(${PROJECT_NAME}_py)

install(
TARGETS ${PROJECT_NAME}_conversion
EXPORT export_${PROJECT_NAME}
Expand Down
Empty file.
54 changes: 54 additions & 0 deletions linear_feedback_controller_msgs_py/lfc_py_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from typing import Annotated, List, Literal
from dataclasses import dataclass
import numpy as np
import numpy.typing as npt

np_array6 = Annotated[npt.NDArray[np.float64], Literal[6]]
np_array7 = Annotated[npt.NDArray[np.float64], Literal[7]]


@dataclass
class JointState:
"""Structure containing JointState information similarly to ROS message
sensor_msgs.msg.JointState.
"""

name: List[str]
position: npt.NDArray[np.float64]
velocity: npt.NDArray[np.float64]
effort: npt.NDArray[np.float64]


@dataclass
class Contact:
"""Structure containing Contact information similarly to ROS message
linear_feedback_controller_msgs.msg.Contact.
"""

active: bool
name: str
wrench: np_array6
pose: np_array7


@dataclass
class Sensor:
"""Structure containing Sensor information similarly to ROS message
linear_feedback_controller_msgs.msg.Sensor.
"""

base_pose: np_array7
base_twist: np_array6
joint_state: JointState
contacts: List[Contact]


@dataclass
class Control:
"""Structure containing Control information similarly to ROS message
linear_feedback_controller_msgs.msg.Control.
"""

feedback_gain: npt.NDArray[np.float64]
feedforward: npt.NDArray[np.float64]
initial_state: Sensor
Loading

0 comments on commit aa6ce78

Please sign in to comment.