-
Notifications
You must be signed in to change notification settings - Fork 341
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
Demo nodes for raw publish and subscribe #185
Conversation
while (rclcpp::ok()) { | ||
sprintf(raw_msg.buffer, "%c%c%c%c%c%c%c%c%s %d", | ||
0x00, 0x01, 0x00, 0x00, 0x0f, 0x00, 0x00,0x00, "hello world", (++i)); | ||
std::cout << "Publishing: '" << raw_msg.buffer << "'" << std::endl; |
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.
Use printf.
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.
copied from the existing talker example
. It's outside of this PR, but I'll update the talker code accordingly.
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.
The other demo code will be updated to use logging pretty soon so I think it's fine to just use printf in the new code without modifying existing one
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.
@mikaelarguedas Just saw your comment. I'll rebase accordingly if necessary.
demo_nodes_cpp/src/topics/talker.cpp
Outdated
@@ -57,7 +57,7 @@ int main(int argc, char * argv[]) | |||
|
|||
while (rclcpp::ok()) { | |||
msg->data = "Hello World: " + std::to_string(i++); | |||
std::cout << "Publishing: '" << msg->data << "'" << std::endl; | |||
printf("Publishing: %s\n", msg->data.c_str()); |
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.
If we modify this in this PR, it needs to print the exacte same message as before (with single quotes around the data). Otherwise the tests will fail because they expect them:
demos/demo_nodes_cpp/test/talker.txt
Line 1 in 0c2fa6b
Publishing: 'Hello World: 1' |
5f84510
to
a778906
Compare
5f86772
to
4421d11
Compare
@@ -0,0 +1,95 @@ | |||
// Copyright 2014 Open Source Robotics Foundation, Inc. |
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.
This file is copyright 2014 but the talker is 2017, so is this one a copy of another and the talker is not or...?
[this]() -> void | ||
{ | ||
rcutils_snprintf(raw_msg_.buffer, raw_msg_.buffer_length, "%c%c%c%c%c%c%c%c%s %zu", | ||
0x00, 0x01, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, "Hello World:", (count_++)); |
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 think this deverse a comment explaining that this is basically manual serialization of a string to CDR, and/or a TODO to replace this with a call to the serialization API which is forthcoming (I assume).
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.
Also, the ()
around count++
are redundant.
: Node("raw_talker") | ||
{ | ||
raw_msg_.buffer_length = 24; | ||
raw_msg_.buffer = new char[raw_msg_.buffer_length]; |
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.
This needs to be deleted in the destructor of the class.
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.
While the delete
in the destructor is sufficient for the demo code to be "correct" I would suggest to use a smart pointer. Otherwise this might encourage people to copy-n-paste this code which is "incomplete" without a copy constructor and assignment operator.
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.
agreed, a smart pointer would be nice, but I don't think it's more user friendly. I would rather say it's even more error prone to make copy-paste mistakes as you can't simply instantiate a shared ptr with that c-struct. You have to pass a custom deleter function / callable object with the smart pointer to clean up correctly. Does this make sense?
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.
A std::unique_ptr
is specialized for arrays and should be fine to use (as of C++11) without a custom deleter afaik (see http://en.cppreference.com/w/cpp/memory/unique_ptr).
@Karsten1987 Should/can this be put into "in progress"? I have outstanding comments in ros2/rmw_fastrtps#186 and ros2/rmw_connext#259 (at least I think so) and this has stayed in review for several days. It would help me to put it in progress until issues are addressed so that I don't have to reevaluate its state each time I go through waffle to check for needed reviews. |
Rerun of Windows CI after ros2/rmw_connext@8eaeb9e: |
Rerun of Windows CI after ros2/rmw_connext@f778624: |
Rerun of Windows CI after ros2/rmw_connext@27cd763: |
So I merged this! |
I am making this the top level PR to gather all related PRs. This is WIP but as it affects basically all packages down the stack, I open this PR for early visibility.
This PR (and all others) aim to expose the raw CDR stream through the ROS2 API. This enables to send a raw data stream directly to the wire and in return take the data without going through the serialization process.
This ultimately serves as the base for a future upcoming ROSbag implementation.