-
Notifications
You must be signed in to change notification settings - Fork 316
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
[rclpy_examples] QoS examples #132
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
627e98f
qos example
mikaelarguedas 1495841
add reliable/best_effort settings
mikaelarguedas ba88ec3
fix qos examples
mikaelarguedas 3dae26e
add argparse
mikaelarguedas 869562b
add qos examples to setup.py
mikaelarguedas 3c0e39c
clarify listener helper string
mikaelarguedas 86a119d
style
dirk-thomas 7d0787b
style
dirk-thomas 1ce6239
clarify reliability argument value
mikaelarguedas 6796177
boolean reliable parameter
mikaelarguedas ab24045
Fixup
dhood 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 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,58 @@ | ||
# Copyright 2016 Open Source Robotics Foundation, Inc. | ||
# | ||
# 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. | ||
|
||
import argparse | ||
import sys | ||
|
||
import rclpy | ||
from rclpy.qos import qos_profile_default, qos_profile_sensor_data | ||
|
||
from std_msgs.msg import String | ||
|
||
|
||
def chatter_callback(msg): | ||
print('I heard: [%s]' % msg.data) | ||
|
||
|
||
def main(argv=sys.argv[1:]): | ||
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) | ||
parser.add_argument( | ||
'-r', '--reliability', type=int, default=0, choices=[0, 1], | ||
help='1: reliable, 0: best effort') | ||
parser.add_argument( | ||
'-n', '--number_of_cycles', type=int, default=20, | ||
help='max number of spin_once iterations') | ||
args = parser.parse_args(argv) | ||
rclpy.init() | ||
|
||
if args.reliability == 1: | ||
custom_qos_profile = qos_profile_default | ||
print('reliable publisher') | ||
else: | ||
custom_qos_profile = qos_profile_sensor_data | ||
print('best effort publisher') | ||
|
||
node = rclpy.create_node('listener_qos') | ||
|
||
sub = node.create_subscription(String, 'chatter_qos', chatter_callback, custom_qos_profile) | ||
|
||
assert sub # prevent unused warning | ||
|
||
cycle_count = 0 | ||
while rclpy.ok() and cycle_count < args.number_of_cycles: | ||
rclpy.spin_once(node) | ||
cycle_count += 1 | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains 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 |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
name='rclpy_examples', | ||
version='0.0.0', | ||
packages=[], | ||
py_modules=['listener_py', 'talker_py'], | ||
py_modules=['listener_py', 'talker_py', 'listener_qos_py', 'talker_qos_py'], | ||
install_requires=['setuptools'], | ||
author='Esteve Fernandez', | ||
author_email='[email protected]', | ||
|
@@ -24,6 +24,8 @@ | |
'console_scripts': [ | ||
'listener_py = listener_py:main', | ||
'talker_py = talker_py:main', | ||
'listener_qos_py = listener_qos_py:main', | ||
'talker_qos_py = talker_qos_py:main', | ||
], | ||
}, | ||
) |
This file contains 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,58 @@ | ||
# Copyright 2016 Open Source Robotics Foundation, Inc. | ||
# | ||
# 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. | ||
|
||
import argparse | ||
import sys | ||
from time import sleep | ||
|
||
import rclpy | ||
from rclpy.qos import qos_profile_default, qos_profile_sensor_data | ||
|
||
from std_msgs.msg import String | ||
|
||
|
||
def main(argv=sys.argv[1:]): | ||
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) | ||
parser.add_argument( | ||
'-r', '--reliability', type=int, default=0, choices=[0, 1], | ||
help='1: reliable, 0: best effort') | ||
parser.add_argument( | ||
'-n', '--number_of_cycles', type=int, default=20, | ||
help='number of sending attempts') | ||
args = parser.parse_args(argv) | ||
rclpy.init() | ||
|
||
if args.reliability == 1: | ||
custom_qos_profile = qos_profile_default | ||
print('reliable publisher') | ||
else: | ||
custom_qos_profile = qos_profile_sensor_data | ||
print('best effort publisher') | ||
|
||
node = rclpy.create_node('talker_qos') | ||
|
||
chatter_pub = node.create_publisher(String, 'chatter_qos', custom_qos_profile) | ||
|
||
msg = String() | ||
|
||
cycle_count = 0 | ||
while rclpy.ok() and cycle_count < args.number_of_cycles: | ||
msg.data = 'Hello World: {0}'.format(cycle_count) | ||
print('Publishing: "{0}"'.format(msg.data)) | ||
chatter_pub.publish(msg) | ||
cycle_count += 1 | ||
sleep(1) | ||
|
||
if __name__ == '__main__': | ||
main() |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any other options planned? If not I would suggest using a boolean flag
--reliable
instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hesitated to add other profiles that's why I settled for a integer parameter. Given that this is supposed to be an example I think we can keep it simple and restrict ourselves to only 2 qos profiles.