-
Notifications
You must be signed in to change notification settings - Fork 35
Feature/configuration #13
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b62b33c
Add configuration examples.
BorjaOuterelo 5f65712
Added configuration examples
pablogs9 b7f764b
Client key API
pablogs9 811b154
Fix
pablogs9 086be09
Examples cleanup ad error code check
pablogs9 c5af16d
Added error check macros
pablogs9 a10cbbf
Indentation fix
pablogs9 44f38cd
Indentation fix
pablogs9 8cb6f85
Indentation fix
pablogs9 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
rcl/configuration_example/configured_publisher/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| cmake_minimum_required(VERSION 3.5) | ||
| set(CMAKE_C_CLANG_TIDY clang-tidy -checks=*) | ||
|
|
||
| project(configured_publisher) | ||
|
|
||
| find_package(ament_cmake REQUIRED) | ||
| find_package(geometry_msgs REQUIRED) | ||
| find_package(rmw_microxrcedds REQUIRED) | ||
| find_package(rcl REQUIRED) | ||
|
|
||
| add_executable(${PROJECT_NAME} main.c) | ||
| ament_target_dependencies(${PROJECT_NAME} | ||
| geometry_msgs | ||
| rmw_microxrcedds | ||
| rcl | ||
| ) | ||
|
|
||
| install(TARGETS ${PROJECT_NAME} | ||
| DESTINATION ${PROJECT_NAME} | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
|
|
||
| #include <stdio.h> | ||
| #include <unistd.h> | ||
|
|
||
| #include <rcl/rcl.h> | ||
| #include <geometry_msgs/msg/vector3.h> | ||
| #include <rmw_uros/options.h> | ||
|
|
||
| #define RCCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){printf("Failed status on line %d: %d. Aborting.\n",__LINE__,(int)temp_rc); return 1;}} | ||
| #define RCSOFTCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){printf("Failed status on line %d: %d. Continuing.\n",__LINE__,(int)temp_rc);}} | ||
|
|
||
| int main(int argc, char * const argv[]) | ||
| { | ||
| //Init RCL context | ||
| rcl_context_t context; | ||
| rcl_init_options_t init_options; | ||
|
|
||
| init_options = rcl_get_zero_initialized_init_options(); | ||
| RCCHECK(rcl_init_options_init(&init_options, rcl_get_default_allocator())) | ||
|
|
||
| printf("Connecting to agent %s:%d\n",argv[1],atoi(argv[2])); | ||
| rmw_init_options_t* rmw_options = rcl_init_options_get_rmw_init_options(&init_options); | ||
| RCCHECK(rmw_uros_options_set_udp_address(argv[1], argv[2], rmw_options)) | ||
| RCCHECK(rmw_uros_options_set_client_key(0xBA5EBA11, rmw_options)) | ||
|
|
||
| context = rcl_get_zero_initialized_context(); | ||
|
|
||
| RCCHECK(rcl_init(0, NULL, &init_options, &context)) | ||
|
|
||
| //Init Node | ||
| rcl_node_t node = rcl_get_zero_initialized_node(); | ||
| rcl_node_options_t node_ops = rcl_node_get_default_options(); | ||
|
|
||
| RCCHECK(rcl_node_init(&node, "vector3_publisher", "", &context, &node_ops)) | ||
|
|
||
| //Init Publisher | ||
| const char* topic_name = "sample_vector3"; | ||
|
|
||
| rcl_publisher_t publisher_vector3 = rcl_get_zero_initialized_publisher(); | ||
| const rosidl_message_type_support_t * pub_type_support = ROSIDL_GET_MSG_TYPE_SUPPORT(geometry_msgs, msg, Vector3); | ||
| rcl_publisher_options_t pub_opt = rcl_publisher_get_default_options(); | ||
|
|
||
| RCCHECK(rcl_publisher_init(&publisher_vector3, &node, pub_type_support, topic_name, &pub_opt)) | ||
|
|
||
| geometry_msgs__msg__Vector3 topic_data; | ||
| geometry_msgs__msg__Vector3__init(&topic_data); | ||
|
|
||
| // Spin | ||
| rcl_wait_set_t wait_set = rcl_get_zero_initialized_wait_set(); | ||
| RCCHECK(rcl_wait_set_init(&wait_set, 1, 0, 0, 0, 0, 0, &context, rcl_get_default_allocator())) | ||
|
|
||
| float values[3]; | ||
| values[0] = 0.0; | ||
| values[1] = 1.0; | ||
| values[2] = 2.0; | ||
|
|
||
| topic_data.x = values[0]; | ||
| topic_data.y = values[1]; | ||
| topic_data.z = values[2]; | ||
|
|
||
| while (rcl_context_is_valid(&context)) { | ||
| RCSOFTCHECK(rcl_publish( &publisher_vector3, (const void *) &topic_data, NULL)) | ||
|
|
||
| for(uint8_t i = 0; i < 3; i++) { | ||
| values[i]++; | ||
| } | ||
|
|
||
| topic_data.x = values[0]; | ||
| topic_data.y = values[1]; | ||
| topic_data.z = values[2]; | ||
|
|
||
| printf("Publish: %f, %f, %f\n",topic_data.x,topic_data.y,topic_data.z); | ||
| sleep(1); | ||
| } | ||
|
|
||
| RCCHECK(rcl_node_fini(&node)) | ||
| } |
20 changes: 20 additions & 0 deletions
20
rcl/configuration_example/configured_subscriber/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| cmake_minimum_required(VERSION 3.5) | ||
| set(CMAKE_C_CLANG_TIDY clang-tidy -checks=*) | ||
|
|
||
| project(configured_subscriber) | ||
|
|
||
| find_package(ament_cmake REQUIRED) | ||
| find_package(geometry_msgs REQUIRED) | ||
| find_package(rmw_microxrcedds REQUIRED) | ||
| find_package(rcl REQUIRED) | ||
|
|
||
| add_executable(${PROJECT_NAME} main.c) | ||
| ament_target_dependencies(${PROJECT_NAME} | ||
| geometry_msgs | ||
| rmw_microxrcedds | ||
| rcl | ||
| ) | ||
|
|
||
| install(TARGETS ${PROJECT_NAME} | ||
| DESTINATION ${PROJECT_NAME} | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
|
|
||
| #include <stdio.h> | ||
| #include <unistd.h> | ||
|
|
||
| #include <rcl/rcl.h> | ||
| #include <geometry_msgs/msg/vector3.h> | ||
| #include <rmw_uros/options.h> | ||
|
|
||
| #define RCCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){printf("Failed status on line %d: %d. Aborting.\n",__LINE__,(int)temp_rc); return 1;}} | ||
| #define RCSOFTCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){printf("Failed status on line %d: %d. Continuing.\n",__LINE__,(int)temp_rc);}} | ||
|
|
||
| int main(int argc, char * argv[]) | ||
| { | ||
| //Init RCL context | ||
| rcl_context_t context; | ||
| rcl_init_options_t init_options; | ||
|
|
||
| init_options = rcl_get_zero_initialized_init_options(); | ||
| RCCHECK(rcl_init_options_init(&init_options, rcl_get_default_allocator())) | ||
|
|
||
| printf("Connecting to agent %s:%d\n",argv[1],atoi(argv[2])); | ||
| rmw_init_options_t* rmw_options = rcl_init_options_get_rmw_init_options(&init_options); | ||
| RCCHECK(rmw_uros_options_set_udp_address(argv[1], argv[2], rmw_options)) | ||
| RCCHECK(rmw_uros_options_set_client_key(0xCAFEBABE, rmw_options)) | ||
|
|
||
| context = rcl_get_zero_initialized_context(); | ||
|
|
||
| RCCHECK(rcl_init(0, NULL, &init_options, &context)) | ||
|
|
||
| //Init Node | ||
| rcl_node_t node = rcl_get_zero_initialized_node(); | ||
| rcl_node_options_t node_ops = rcl_node_get_default_options(); | ||
|
|
||
| RCCHECK(rcl_node_init(&node, "vector3_subscriber", "", &context, &node_ops)) | ||
|
|
||
| //Init Subscriber | ||
| const char* topic_name = "sample_vector3"; | ||
| rcl_subscription_t subscriber_vector3 = rcl_get_zero_initialized_subscription(); | ||
| rcl_subscription_options_t subs_ops = rcl_subscription_get_default_options(); | ||
|
|
||
| const rosidl_message_type_support_t * sub_type_support = ROSIDL_GET_MSG_TYPE_SUPPORT(geometry_msgs, msg, Vector3); | ||
|
|
||
| RCCHECK(rcl_subscription_init(&subscriber_vector3, &node, sub_type_support, topic_name, &subs_ops)) | ||
|
|
||
| geometry_msgs__msg__Vector3 topic_data; | ||
| geometry_msgs__msg__Vector3__init(&topic_data); | ||
|
|
||
| // Spin | ||
| rcl_wait_set_t wait_set = rcl_get_zero_initialized_wait_set(); | ||
| RCCHECK(rcl_wait_set_init(&wait_set, 1, 0, 0, 0, 0, 0, &context, rcl_get_default_allocator())) | ||
|
|
||
| uint32_t timeout_ms = 500; | ||
|
|
||
| while (rcl_context_is_valid(&context)) | ||
| { | ||
| // get empty wait set | ||
| rcl_wait_set_t wait_set = rcl_get_zero_initialized_wait_set(); | ||
| RCSOFTCHECK(rcl_wait_set_init(&wait_set, 1, 0, 0, 0, 0, 0, &context, rcl_get_default_allocator())) | ||
|
|
||
| // set rmw fields to NULL | ||
| RCSOFTCHECK(rcl_wait_set_clear(&wait_set)) | ||
|
|
||
| size_t index = 0; | ||
| RCSOFTCHECK(rcl_wait_set_add_subscription(&wait_set, &subscriber_vector3, &index)) | ||
|
|
||
| rcl_ret_t rc = rcl_wait(&wait_set, RCL_MS_TO_NS(timeout_ms)); | ||
|
|
||
| if (rc == RCL_RET_OK && wait_set.subscriptions[0]) { | ||
| rmw_message_info_t messageInfo; | ||
| RCSOFTCHECK(rcl_take(wait_set.subscriptions[0], &topic_data, &messageInfo, NULL)) | ||
| printf("Received: %f, %f, %f\n",topic_data.x,topic_data.y,topic_data.z); | ||
| } | ||
|
|
||
| RCSOFTCHECK(rcl_wait_set_fini(&wait_set)) | ||
| } | ||
|
|
||
| RCCHECK(rcl_node_fini(&node)) | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.