Skip to content

Commit

Permalink
Adding demos side of changes
Browse files Browse the repository at this point in the history
Signed-off-by: CursedRock17 <[email protected]>
  • Loading branch information
CursedRock17 committed May 1, 2024
1 parent 41458c1 commit 09025c1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ endif()
# Besides the package specific dependencies we also need the `pluginlib` and `webots_ros2_driver`
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(example_interfaces REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(pluginlib REQUIRED)
find_package(webots_ros2_driver REQUIRED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ endif()
# Besides the package specific dependencies we also need the `pluginlib` and `webots_ros2_driver`
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(example_interfaces REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(pluginlib REQUIRED)
find_package(webots_ros2_driver REQUIRED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ Remove a Webots imported node

Once a node has been imported with the ``/Ros2Supervisor/spawn_node_from_string`` service, it can also be removed.

This can be achieved by sending the name of the node to the topic named ``/Ros2Supervisor/remove_node`` of type ``std_msgs/msg/String``.
This can be achieved by sending the name of the node to the topic named ``/Ros2Supervisor/remove_node`` of type ``example_interfaces/msg/String``.

If the node is indeed in the imported list, it is removed with the ``remove()`` `API method <https://cyberbotics.com/doc/reference/supervisor?tab-language=python#wb_supervisor_node_remove>`_.

Here is an example on how to remove the ``imported_robot`` Robot:

.. code-block:: bash
ros2 topic pub --once /Ros2Supervisor/remove_node std_msgs/msg/String "{data: imported_robot}"
ros2 topic pub --once /Ros2Supervisor/remove_node example_interfaces/msg/String "{data: imported_robot}"
Record animations
-----------------
Expand Down
18 changes: 9 additions & 9 deletions source/Tutorials/Demos/Content-Filtering-Subscription.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ https://github.com/ros2/demos/blob/{REPOS_FILE_BRANCH}/demo_nodes_cpp/src/topics
#include "rclcpp/rclcpp.hpp"
#include "rclcpp_components/register_node_macro.hpp"

#include "std_msgs/msg/float32.hpp"
#include "example_interfaces/msg/float32.hpp"

#include "demo_nodes_cpp/visibility_control.h"

Expand All @@ -96,7 +96,7 @@ https://github.com/ros2/demos/blob/{REPOS_FILE_BRANCH}/demo_nodes_cpp/src/topics
auto publish_message =
[this]() -> void
{
msg_ = std::make_unique<std_msgs::msg::Float32>();
msg_ = std::make_unique<example_interfaces::msg::Float32>();
msg_->data = temperature_;
temperature_ += TEMPERATURE_SETTING[2];
if (temperature_ > TEMPERATURE_SETTING[1]) {
Expand All @@ -112,16 +112,16 @@ https://github.com/ros2/demos/blob/{REPOS_FILE_BRANCH}/demo_nodes_cpp/src/topics
// rclcpp::KeepAll{} if the user wishes.
// (rclcpp::KeepLast(7) -> rclcpp::KeepAll() fails to compile)
rclcpp::QoS qos(rclcpp::KeepLast{7});
pub_ = this->create_publisher<std_msgs::msg::Float32>("temperature", qos);
pub_ = this->create_publisher<example_interfaces::msg::Float32>("temperature", qos);

// Use a timer to schedule periodic message publishing.
timer_ = this->create_wall_timer(1s, publish_message);
}

private:
float temperature_ = TEMPERATURE_SETTING[0];
std::unique_ptr<std_msgs::msg::Float32> msg_;
rclcpp::Publisher<std_msgs::msg::Float32>::SharedPtr pub_;
std::unique_ptr<example_interfaces::msg::Float32> msg_;
rclcpp::Publisher<example_interfaces::msg::Float32>::SharedPtr pub_;
rclcpp::TimerBase::SharedPtr timer_;
};

Expand Down Expand Up @@ -176,7 +176,7 @@ https://github.com/ros2/demos/blob/{REPOS_FILE_BRANCH}/demo_nodes_cpp/src/topics
#include "rclcpp_components/register_node_macro.hpp"
#include "rcpputils/join.hpp"

#include "std_msgs/msg/float32.hpp"
#include "example_interfaces/msg/float32.hpp"

#include "demo_nodes_cpp/visibility_control.h"

Expand All @@ -197,7 +197,7 @@ https://github.com/ros2/demos/blob/{REPOS_FILE_BRANCH}/demo_nodes_cpp/src/topics
setvbuf(stdout, NULL, _IONBF, BUFSIZ);
// Create a callback function for when messages are received.
auto callback =
[this](const std_msgs::msg::Float32 & msg) -> void
[this](const example_interfaces::msg::Float32 & msg) -> void
{
if (msg.data < EMERGENCY_TEMPERATURE[0] || msg.data > EMERGENCY_TEMPERATURE[1]) {
RCLCPP_INFO(
Expand All @@ -217,7 +217,7 @@ https://github.com/ros2/demos/blob/{REPOS_FILE_BRANCH}/demo_nodes_cpp/src/topics
std::to_string(EMERGENCY_TEMPERATURE[1])
};

sub_ = create_subscription<std_msgs::msg::Float32>("temperature", 10, callback, sub_options);
sub_ = create_subscription<example_interfaces::msg::Float32>("temperature", 10, callback, sub_options);

if (!sub_->is_cft_enabled()) {
RCLCPP_WARN(
Expand All @@ -233,7 +233,7 @@ https://github.com/ros2/demos/blob/{REPOS_FILE_BRANCH}/demo_nodes_cpp/src/topics
}

private:
rclcpp::Subscription<std_msgs::msg::Float32>::SharedPtr sub_;
rclcpp::Subscription<example_interfaces::msg::Float32>::SharedPtr sub_;
};

} // namespace demo_nodes_cpp
Expand Down
28 changes: 14 additions & 14 deletions source/Tutorials/Demos/Intra-Process-Communication.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ https://github.com/ros2/demos/blob/{REPOS_FILE_BRANCH}/intra_process_demo/src/tw
#include <utility>

#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/int32.hpp"
#include "example_interfaces/msg/int32.hpp"

using namespace std::chrono_literals;

Expand All @@ -63,7 +63,7 @@ https://github.com/ros2/demos/blob/{REPOS_FILE_BRANCH}/intra_process_demo/src/tw
: Node(name, rclcpp::NodeOptions().use_intra_process_comms(true))
{
// Create a publisher on the output topic.
pub_ = this->create_publisher<std_msgs::msg::Int32>(output, 10);
pub_ = this->create_publisher<example_interfaces::msg::Int32>(output, 10);
std::weak_ptr<std::remove_pointer<decltype(pub_.get())>::type> captured_pub = pub_;
// Create a timer which publishes on the output topic at ~1Hz.
auto callback = [captured_pub]() -> void {
Expand All @@ -72,7 +72,7 @@ https://github.com/ros2/demos/blob/{REPOS_FILE_BRANCH}/intra_process_demo/src/tw
return;
}
static int32_t count = 0;
std_msgs::msg::Int32::UniquePtr msg(new std_msgs::msg::Int32());
example_interfaces::msg::Int32::UniquePtr msg(new example_interfaces::msg::Int32());
msg->data = count++;
printf(
"Published message with value: %d, and address: 0x%" PRIXPTR "\n", msg->data,
Expand All @@ -82,7 +82,7 @@ https://github.com/ros2/demos/blob/{REPOS_FILE_BRANCH}/intra_process_demo/src/tw
timer_ = this->create_wall_timer(1s, callback);
}

rclcpp::Publisher<std_msgs::msg::Int32>::SharedPtr pub_;
rclcpp::Publisher<example_interfaces::msg::Int32>::SharedPtr pub_;
rclcpp::TimerBase::SharedPtr timer_;
};

Expand All @@ -93,17 +93,17 @@ https://github.com/ros2/demos/blob/{REPOS_FILE_BRANCH}/intra_process_demo/src/tw
: Node(name, rclcpp::NodeOptions().use_intra_process_comms(true))
{
// Create a subscription on the input topic which prints on receipt of new messages.
sub_ = this->create_subscription<std_msgs::msg::Int32>(
sub_ = this->create_subscription<example_interfaces::msg::Int32>(
input,
10,
[](std_msgs::msg::Int32::UniquePtr msg) {
[](example_interfaces::msg::Int32::UniquePtr msg) {
printf(
" Received message with value: %d, and address: 0x%" PRIXPTR "\n", msg->data,
reinterpret_cast<std::uintptr_t>(msg.get()));
});
}

rclcpp::Subscription<std_msgs::msg::Int32>::SharedPtr sub_;
rclcpp::Subscription<example_interfaces::msg::Int32>::SharedPtr sub_;
};

int main(int argc, char * argv[])
Expand Down Expand Up @@ -183,7 +183,7 @@ https://github.com/ros2/demos/blob/{REPOS_FILE_BRANCH}/intra_process_demo/src/cy
#include <utility>

#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/int32.hpp"
#include "example_interfaces/msg/int32.hpp"

using namespace std::chrono_literals;

Expand All @@ -194,13 +194,13 @@ https://github.com/ros2/demos/blob/{REPOS_FILE_BRANCH}/intra_process_demo/src/cy
: Node(name, rclcpp::NodeOptions().use_intra_process_comms(true))
{
// Create a publisher on the output topic.
pub = this->create_publisher<std_msgs::msg::Int32>(out, 10);
pub = this->create_publisher<example_interfaces::msg::Int32>(out, 10);
std::weak_ptr<std::remove_pointer<decltype(pub.get())>::type> captured_pub = pub;
// Create a subscription on the input topic.
sub = this->create_subscription<std_msgs::msg::Int32>(
sub = this->create_subscription<example_interfaces::msg::Int32>(
in,
10,
[captured_pub](std_msgs::msg::Int32::UniquePtr msg) {
[captured_pub](example_interfaces::msg::Int32::UniquePtr msg) {
auto pub_ptr = captured_pub.lock();
if (!pub_ptr) {
return;
Expand All @@ -221,8 +221,8 @@ https://github.com/ros2/demos/blob/{REPOS_FILE_BRANCH}/intra_process_demo/src/cy
});
}

rclcpp::Publisher<std_msgs::msg::Int32>::SharedPtr pub;
rclcpp::Subscription<std_msgs::msg::Int32>::SharedPtr sub;
rclcpp::Publisher<example_interfaces::msg::Int32>::SharedPtr pub;
rclcpp::Subscription<example_interfaces::msg::Int32>::SharedPtr sub;
};

int main(int argc, char * argv[])
Expand All @@ -237,7 +237,7 @@ https://github.com/ros2/demos/blob/{REPOS_FILE_BRANCH}/intra_process_demo/src/cy
auto pipe2 = std::make_shared<IncrementerPipe>("pipe2", "topic2", "topic1");
rclcpp::sleep_for(1s); // Wait for subscriptions to be established to avoid race conditions.
// Publish the first message (kicking off the cycle).
std::unique_ptr<std_msgs::msg::Int32> msg(new std_msgs::msg::Int32());
std::unique_ptr<example_interfaces::msg::Int32> msg(new example_interfaces::msg::Int32());
msg->data = 42;
printf(
"Published first message with value: %d, and address: 0x%" PRIXPTR "\n", msg->data,
Expand Down

0 comments on commit 09025c1

Please sign in to comment.