Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: aimrt_py support ros2 protocol interface #95

Merged
merged 55 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
5a79b74
feat: add checks for ROS 2 message type support
zhangyi1357 Nov 7, 2024
11ac735
build: update file globbing to include configure dependencies
zhangyi1357 Nov 7, 2024
455a2fc
feat: add ROS2 message support and enhance publishing functionality
Nov 8, 2024
67e98c8
feat: add HTTP and ROS2 example configurations and applications
Nov 8, 2024
cdb8924
chore: disable unimplemented copy and move functions
Nov 8, 2024
0650f44
feat: enhance message publishing with iteration and logging
Nov 8, 2024
f7691c8
refactor: reorganize and encapsulate ROS2 message handling functionality
Nov 8, 2024
6aa08bb
refactor: streamline protobuf and ROS2 message publishing
Nov 11, 2024
3751ed1
refactor: streamline messaging functions
Nov 11, 2024
079306b
refactor: simplify message subscription handling and reduce publish f…
Nov 11, 2024
219a300
fix: remove unnecessary error message for ROS 1 type detection
Nov 11, 2024
ab6521e
docs: update README and add ros2 channel examples
Nov 11, 2024
605cf09
feat: support ros2 message types in aimrt_py channel
Nov 11, 2024
78a4425
fix: improve error handling during ROS2 message serialization and des…
Nov 11, 2024
f53d338
fix: correct argument validation and formatting
Nov 11, 2024
ccc44ba
refactor: streamline message conversion logic
Nov 11, 2024
39aa0ab
feat: add ROS2 support to Python runtime
Nov 12, 2024
b9a0016
feat: enhance message type handling for publishers and subscribers
Nov 12, 2024
ae64f1c
feat: update message types to use RosTestMsg for better compatibility
Nov 12, 2024
780864c
chore: consolidate pybind11 includes
Nov 12, 2024
8a67e4b
docs: add ROS2 message support details and example links
Nov 12, 2024
c794cf4
chore: update copyright information to reflect new authorship
Nov 12, 2024
60011e4
feat: add ROS2 RPC client and server examples with configurations
zhangyi1357 Nov 14, 2024
e75460d
feat: update RPC request and response handling
zhangyi1357 Nov 14, 2024
95ad436
refactor: simplify RPC response handling
zhangyi1357 Nov 14, 2024
95d26b8
refactor: streamline publisher and subscriber method names
zhangyi1357 Nov 14, 2024
475b6af
chore: update configuration file paths for gRPC client and server exa…
zhangyi1357 Nov 14, 2024
31cb039
refactor: rename internal methods for clarity
zhangyi1357 Nov 14, 2024
7076dd3
feat: add service type validation and improve bash scripts
zhangyi1357 Nov 15, 2024
4585e11
feat: extend RPC response data structure and improve logging
zhangyi1357 Nov 15, 2024
14274d9
feat: add support for static and dynamic arrays in RPC service
zhangyi1357 Nov 18, 2024
aa85968
feat: add support for new ROS message types
zhangyi1357 Nov 18, 2024
6ad0e57
refactor: improve type mapping and message copy functions
zhangyi1357 Nov 18, 2024
f97f3c0
refactor: improve message copying and moving functions
zhangyi1357 Nov 19, 2024
068716e
refactor: simplify message type support functions
zhangyi1357 Nov 19, 2024
b76018f
refactor: streamline ROS message handling and improve introspection s…
zhangyi1357 Nov 19, 2024
5e6ae7f
fix: ensure pointers for ROS message creation and destruction are valid
zhangyi1357 Nov 19, 2024
b8fd122
feat: enhance RosTestRpc method signature for better type safety
zhangyi1357 Nov 19, 2024
97e362e
refactor: simplify parameter naming in RPC proxy function
zhangyi1357 Nov 19, 2024
5542a83
fix: restrict static array sizes in RosTestRpc service
zhangyi1357 Nov 19, 2024
079c0c1
feat: enhance python runtime generation for ROS2 services
zhangyi1357 Nov 19, 2024
bb37ded
refactor: update RPC service and client implementations to use ROS2 n…
zhangyi1357 Nov 19, 2024
a5372b6
chore: update .gitignore to exclude generated files
zhangyi1357 Nov 19, 2024
f250378
refactor: streamline response structure for RosTestRpc
zhangyi1357 Nov 19, 2024
42811d0
chore: update log level to INFO for consistency
zhangyi1357 Nov 19, 2024
bcfa9c0
docs: add README for ros2 rpc examples
zhangyi1357 Nov 19, 2024
b5625ec
feat: enhance aimrt_py channel with rpc support for ros2 message types
zhangyi1357 Nov 19, 2024
059d5e7
docs: add ros2_rpc example to Python interface section
zhangyi1357 Nov 19, 2024
116dc13
chore: add spacing for improved readability in service proxy class
zhangyi1357 Nov 19, 2024
d107f4f
chore: standardize argument names for RPC generator
zhangyi1357 Nov 19, 2024
3cb5d3f
docs: update RPC documentation to include ROS2 Srv support
zhangyi1357 Nov 19, 2024
f341fc0
style: standardize whitespace in RosTestRpc.srv
zhangyi1357 Nov 19, 2024
a5cea2c
build: exclude ROS2 specific files from the build if not using ROS2
zhangyi1357 Nov 19, 2024
1fd6b4c
style: add missing newline at end of file for consistency
zhangyi1357 Nov 19, 2024
9bf6eb8
refactor: rename copy function to improve clarity
zhangyi1357 Nov 19, 2024
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
Prev Previous commit
Next Next commit
fix: improve error handling during ROS2 message serialization and des…
…erialization

Enhance robustness by adding exception handling to ensure the process correctly handles serialization and deserialization failures, improving overall stability in handling ROS2 messages.
  • Loading branch information
zhangyi committed Nov 11, 2024
commit 78a442593427c525cab33d2dc7033bc699412f8c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const aimrt_type_support_base_t* GetRos2MessageTypeSupport() {
if (aimrt::util::ToStdStringView(serialization_type) == "ros2") {
if (buffer_array_view.len == 1) {
rcl_serialized_message_t serialized_msg = rmw_get_zero_initialized_serialized_message();
serialized_msg.buffer = const_cast<uint8_t*>(static_cast<const uint8_t*>(buffer_array_view.data[0].data)),
serialized_msg.buffer = const_cast<uint8_t*>(static_cast<const uint8_t*>(buffer_array_view.data[0].data));
serialized_msg.buffer_length = buffer_array_view.data[0].len;
serialized_msg.buffer_capacity = buffer_array_view.data[0].len;
rcl_ret_t ret = rmw_deserialize(&serialized_msg, ts_ptr, msg);
Expand All @@ -120,7 +120,7 @@ const aimrt_type_support_base_t* GetRos2MessageTypeSupport() {
}

rcl_serialized_message_t serialized_msg = rmw_get_zero_initialized_serialized_message();
serialized_msg.buffer = buffer,
serialized_msg.buffer = buffer;
serialized_msg.buffer_length = total_size;
serialized_msg.buffer_capacity = total_size;
rcl_ret_t ret = rmw_deserialize(&serialized_msg, ts_ptr, msg);
Expand Down
79 changes: 43 additions & 36 deletions src/runtime/python_runtime/export_ros2_type_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,54 +56,61 @@ class PyRos2TypeSupport {
const void* msg,
const aimrt_buffer_array_allocator_t* allocator,
aimrt_buffer_array_t* buffer_array) const {
if (aimrt::util::ToStdStringView(serialization_type) == "ros2") {
aimrt_buffer_array_with_allocator_t bawa{.buffer_array = buffer_array, .allocator = allocator};
Ros2RclSerializedMessageAdapter serialized_msg_adapter(&bawa);
rcl_ret_t ret = rmw_serialize(msg, msg_type_support_, serialized_msg_adapter.GetRclSerializedMessage());
return (ret == RMW_RET_OK);
try {
if (aimrt::util::ToStdStringView(serialization_type) == "ros2") {
aimrt_buffer_array_with_allocator_t bawa{.buffer_array = buffer_array, .allocator = allocator};
Ros2RclSerializedMessageAdapter serialized_msg_adapter(&bawa);
rcl_ret_t ret = rmw_serialize(msg, msg_type_support_, serialized_msg_adapter.GetRclSerializedMessage());
return (ret == RMW_RET_OK);
}
return false;
} catch (const std::exception& e) {
return false;
}
return false;
}

bool Deserialize(
aimrt_string_view_t serialization_type,
aimrt_buffer_array_view_t buffer_array_view,
void* msg) const {
if (aimrt::util::ToStdStringView(serialization_type) == "ros2") {
if (buffer_array_view.len == 1) {
rcl_serialized_message_t serialized_msg = rmw_get_zero_initialized_serialized_message();
serialized_msg.buffer = const_cast<uint8_t*>(static_cast<const uint8_t*>(buffer_array_view.data[0].data)),
serialized_msg.buffer_length = buffer_array_view.data[0].len;
serialized_msg.buffer_capacity = buffer_array_view.data[0].len;
rcl_ret_t ret = rmw_deserialize(&serialized_msg, msg_type_support_, msg);
return (ret == RMW_RET_OK);
}

if (buffer_array_view.len > 1) {
size_t total_size = 0;
for (size_t ii = 0; ii < buffer_array_view.len; ++ii) {
total_size += buffer_array_view.data[ii].len;
}
std::vector<uint8_t> buffer_vec(total_size);
uint8_t* buffer = buffer_vec.data();
size_t cur_size = 0;
for (size_t ii = 0; ii < buffer_array_view.len; ++ii) {
memcpy(buffer + cur_size,
buffer_array_view.data[ii].data,
buffer_array_view.data[ii].len);
cur_size += buffer_array_view.data[ii].len;
try {
if (aimrt::util::ToStdStringView(serialization_type) == "ros2") {
if (buffer_array_view.len == 1) {
rcl_serialized_message_t serialized_msg = rmw_get_zero_initialized_serialized_message();
serialized_msg.buffer = const_cast<uint8_t*>(static_cast<const uint8_t*>(buffer_array_view.data[0].data));
serialized_msg.buffer_length = buffer_array_view.data[0].len;
serialized_msg.buffer_capacity = buffer_array_view.data[0].len;
rcl_ret_t ret = rmw_deserialize(&serialized_msg, msg_type_support_, msg);
return (ret == RMW_RET_OK);
}

rcl_serialized_message_t serialized_msg = rmw_get_zero_initialized_serialized_message();
serialized_msg.buffer = buffer,
serialized_msg.buffer_length = total_size;
serialized_msg.buffer_capacity = total_size;
rcl_ret_t ret = rmw_deserialize(&serialized_msg, msg_type_support_, msg);
return (ret == RMW_RET_OK);
if (buffer_array_view.len > 1) {
size_t total_size = 0;
for (size_t ii = 0; ii < buffer_array_view.len; ++ii) {
total_size += buffer_array_view.data[ii].len;
}
std::vector<uint8_t> buffer_vec(total_size);
uint8_t* buffer = buffer_vec.data();
size_t cur_size = 0;
for (size_t ii = 0; ii < buffer_array_view.len; ++ii) {
memcpy(buffer + cur_size,
buffer_array_view.data[ii].data,
buffer_array_view.data[ii].len);
cur_size += buffer_array_view.data[ii].len;
}

rcl_serialized_message_t serialized_msg = rmw_get_zero_initialized_serialized_message();
serialized_msg.buffer = buffer;
serialized_msg.buffer_length = total_size;
serialized_msg.buffer_capacity = total_size;
rcl_ret_t ret = rmw_deserialize(&serialized_msg, msg_type_support_, msg);
return (ret == RMW_RET_OK);
}
}
return false;
} catch (const std::exception& e) {
return false;
}
return false;
}

aimrt_type_support_base_t GenBase(PyRos2TypeSupport* impl, py::object pymsg_type) {
Expand Down