Skip to content

Commit

Permalink
added windows symbol cmake command
Browse files Browse the repository at this point in the history
  • Loading branch information
skucheria committed Jul 15, 2019
1 parent ddcb5a7 commit 5146e1f
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 89 deletions.
22 changes: 18 additions & 4 deletions demo_nodes_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

find_package(ament_cmake REQUIRED)
find_package(example_interfaces REQUIRED)
find_package(rclcpp REQUIRED)
Expand Down Expand Up @@ -54,27 +56,39 @@ custom_executable(services add_two_ints_client_async)
custom_executable(services add_two_ints_server)

# Tutorials of Parameters with Asynchronous and Synchronous
custom_executable(parameters list_parameters)
#custom_executable(parameters list_parameters)
custom_executable(parameters list_parameters_async)
custom_executable(parameters parameter_blackboard)
#custom_executable(parameters parameter_blackboard)
custom_executable(parameters parameter_events)
custom_executable(parameters parameter_events_async)
custom_executable(parameters even_parameters_node)
custom_executable(parameters set_and_get_parameters)
custom_executable(parameters set_and_get_parameters_async)

# Tutorials of Timers
custom_executable(timers one_off_timer)
custom_executable(timers reuse_timer)
#custom_executable(timers one_off_timer)
#custom_executable(timers reuse_timer)

use_composition(listparameterslib parameters list_parameters)
rclcpp_components_register_node(listparameterslib PLUGIN "demo_nodes_cpp::ListParameters" EXECUTABLE list_parameters)
use_composition(parameterblackboardlib parameters parameter_blackboard)
rclcpp_components_register_node(parameterblackboardlib PLUGIN "demo_nodes_cpp::ParameterBlackboard" EXECUTABLE parameter_blackboard)
use_composition(talkerlib topics talker)
rclcpp_components_register_node(talkerlib PLUGIN "demo_nodes_cpp::Talker" EXECUTABLE talker)
use_composition(talkerserializedlib topics talker_serialized_message)
rclcpp_components_register_node(talkerserializedlib PLUGIN "demo_nodes_cpp::SerializedMessageTalker" EXECUTABLE talker_serialized_message)
use_composition(oneofftimerlib timers one_off_timer)
rclcpp_components_register_node(oneofftimerlib PLUGIN "demo_nodes_cpp::OneOffTimerNode" EXECUTABLE one_off_timer)
use_composition(resusetimerlib timers reuse_timer)
rclcpp_components_register_node(resusetimerlib PLUGIN "demo_nodes_cpp::ReuseTimerNode" EXECUTABLE reuse_timer)

install(TARGETS
talkerlib
talkerserializedlib
oneofftimerlib
resusetimerlib
parameterblackboardlib
listparameterslib
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
Expand Down
94 changes: 48 additions & 46 deletions demo_nodes_cpp/src/parameters/list_parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,62 +16,64 @@
#include <sstream>

#include "rclcpp/rclcpp.hpp"
#include "rclcpp_components/register_node_macro.hpp"

using namespace std::chrono_literals;

int main(int argc, char ** argv)
namespace demo_nodes_cpp
{
// Force flush of the stdout buffer.
setvbuf(stdout, NULL, _IONBF, BUFSIZ);

rclcpp::init(argc, argv);

auto node = rclcpp::Node::make_shared("list_parameters");

// Declare parameters that may be set on this node
node->declare_parameter("foo");
node->declare_parameter("bar");
node->declare_parameter("baz");
node->declare_parameter("foo.first");
node->declare_parameter("foo.second");
node->declare_parameter("foobar");
class ListParameters : public rclcpp::Node
{
public:
explicit ListParameters(const rclcpp::NodeOptions & options)
: Node("list_paramters", options)
{
this->declare_parameter("foo");
this->declare_parameter("bar");
this->declare_parameter("baz");
this->declare_parameter("foo.first");
this->declare_parameter("foo.second");
this->declare_parameter("foobar");

auto parameters_client = std::make_shared<rclcpp::SyncParametersClient>(node);
while (!parameters_client->wait_for_service(1s)) {
if (!rclcpp::ok()) {
RCLCPP_ERROR(node->get_logger(), "Interrupted while waiting for the service. Exiting.");
return 0;
auto parameters_client = std::make_shared<rclcpp::SyncParametersClient>(this);
while (!parameters_client->wait_for_service(1s)) {
if (!rclcpp::ok()) {
RCLCPP_ERROR(this->get_logger(), "Interrupted while waiting for the service. Exiting.");
rclcpp::shutdown();
}
RCLCPP_INFO(this->get_logger(), "service not available, waiting again...");
}
RCLCPP_INFO(node->get_logger(), "service not available, waiting again...");
}

RCLCPP_INFO(node->get_logger(), "Setting parameters...");
// Set several different types of parameters.
auto set_parameters_results = parameters_client->set_parameters({
rclcpp::Parameter("foo", 2),
rclcpp::Parameter("bar", "hello"),
rclcpp::Parameter("baz", 1.45),
rclcpp::Parameter("foo.first", 8),
rclcpp::Parameter("foo.second", 42),
rclcpp::Parameter("foobar", true),
});
RCLCPP_INFO(this->get_logger(), "Setting parameters...");
// Set several different types of parameters.
auto set_parameters_results = parameters_client->set_parameters({
rclcpp::Parameter("foo", 2),
rclcpp::Parameter("bar", "hello"),
rclcpp::Parameter("baz", 1.45),
rclcpp::Parameter("foo.first", 8),
rclcpp::Parameter("foo.second", 42),
rclcpp::Parameter("foobar", true),
});

RCLCPP_INFO(node->get_logger(), "Listing parameters...");
// List the details of a few parameters up to a namespace depth of 10.
auto parameters_and_prefixes = parameters_client->list_parameters({"foo", "bar"}, 10);
RCLCPP_INFO(this->get_logger(), "Listing parameters...");
// List the details of a few parameters up to a namespace depth of 10.
auto parameters_and_prefixes = parameters_client->list_parameters({"foo", "bar"}, 10);

std::stringstream ss;
ss << "\nParameter names:";
for (auto & name : parameters_and_prefixes.names) {
ss << "\n " << name;
}
ss << "\nParameter prefixes:";
for (auto & prefix : parameters_and_prefixes.prefixes) {
ss << "\n " << prefix;
std::stringstream ss;
ss << "\nParameter names:";
for (auto & name : parameters_and_prefixes.names) {
ss << "\n " << name;
}
ss << "\nParameter prefixes:";
for (auto & prefix : parameters_and_prefixes.prefixes) {
ss << "\n " << prefix;
}
RCLCPP_INFO(this->get_logger(), ss.str().c_str());
rclcpp::shutdown();
}
RCLCPP_INFO(node->get_logger(), ss.str().c_str());
};

rclcpp::shutdown();
} // namespace demo_nodes_cpp

return 0;
}
RCLCPP_COMPONENTS_REGISTER_NODE(demo_nodes_cpp::ListParameters)
19 changes: 9 additions & 10 deletions demo_nodes_cpp/src/parameters/parameter_blackboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@

#include "rcl_interfaces/srv/list_parameters.hpp"
#include "rclcpp/rclcpp.hpp"
#include "rclcpp_components/register_node_macro.hpp"

namespace demo_nodes_cpp
{

class ParameterBlackboard : public rclcpp::Node
{
public:
ParameterBlackboard(
const std::string & name = "parameter_blackboard",
const std::string & namespace_ = "",
explicit ParameterBlackboard(
const rclcpp::NodeOptions & options = (
rclcpp::NodeOptions()
.allow_undeclared_parameters(true)
.automatically_declare_parameters_from_overrides(true)
))
: rclcpp::Node(name, namespace_, options)
: Node("parameter_blackboard", options)
{
RCLCPP_INFO(this->get_logger(),
"Parameter blackboard node named '%s' ready, and serving '%zu' parameters already!",
Expand All @@ -38,9 +40,6 @@ class ParameterBlackboard : public rclcpp::Node
}
};

int main(int argc, char const * argv[])
{
rclcpp::init(argc, argv);
rclcpp::spin(std::make_shared<ParameterBlackboard>());
return 0;
}
} // namespace demo_nodes_cpp

RCLCPP_COMPONENTS_REGISTER_NODE(demo_nodes_cpp::ParameterBlackboard)
22 changes: 8 additions & 14 deletions demo_nodes_cpp/src/timers/one_off_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@
#include <memory>

#include "rclcpp/rclcpp.hpp"
#include "rclcpp_components/register_node_macro.hpp"

using namespace std::chrono_literals;

namespace demo_nodes_cpp
{

class OneOffTimerNode : public rclcpp::Node
{
public:
OneOffTimerNode()
: Node("one_off_timer"), count(0)
explicit OneOffTimerNode(const rclcpp::NodeOptions & options)
: Node("one_off_timer", options), count(0)
{
periodic_timer = this->create_wall_timer(
2s,
Expand All @@ -47,16 +51,6 @@ class OneOffTimerNode : public rclcpp::Node
size_t count;
};

int main(int argc, char * argv[])
{
// Force flush of the stdout buffer.
setvbuf(stdout, NULL, _IONBF, BUFSIZ);

rclcpp::init(argc, argv);

auto node = std::make_shared<OneOffTimerNode>();

rclcpp::spin(node);
} // namespace demo_nodes_cpp

return 0;
}
RCLCPP_COMPONENTS_REGISTER_NODE(demo_nodes_cpp::OneOffTimerNode)
23 changes: 8 additions & 15 deletions demo_nodes_cpp/src/timers/reuse_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@
#include <memory>

#include "rclcpp/rclcpp.hpp"

#include "rclcpp_components/register_node_macro.hpp"
using namespace std::chrono_literals;

namespace demo_nodes_cpp
{

class ReuseTimerNode : public rclcpp::Node
{
public:
ReuseTimerNode()
: Node("reuse_timer"), count(0)
explicit ReuseTimerNode(const rclcpp::NodeOptions & options)
: Node("reuse_timer", options), count(0)
{
one_off_timer = this->create_wall_timer(
1s,
Expand Down Expand Up @@ -53,16 +56,6 @@ class ReuseTimerNode : public rclcpp::Node
size_t count;
};

int main(int argc, char * argv[])
{
// Force flush of the stdout buffer.
setvbuf(stdout, NULL, _IONBF, BUFSIZ);

rclcpp::init(argc, argv);

auto node = std::make_shared<ReuseTimerNode>();

rclcpp::spin(node);
} // namespace demo_nodes_cpp

return 0;
}
RCLCPP_COMPONENTS_REGISTER_NODE(demo_nodes_cpp::ReuseTimerNode)

0 comments on commit 5146e1f

Please sign in to comment.