-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Dev] Add ros2 bazel build example (#16)
- Loading branch information
Showing
10 changed files
with
186 additions
and
1 deletion.
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
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
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,37 @@ | ||
load("@com_github_mvukov_rules_ros2//ros2:cc_defs.bzl", "ros2_cpp_binary") | ||
load("@com_github_mvukov_rules_ros2//ros2:launch.bzl", "ros2_launch") | ||
|
||
load("//bazel/tools:cpplint.bzl", "cpplint") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
ros2_cpp_binary( | ||
name = "ros_talker", | ||
srcs = ["ros_talker.cc"], | ||
deps = [ | ||
"@ros2_common_interfaces//:cpp_std_msgs", | ||
"@ros2_rclcpp//:rclcpp", | ||
], | ||
) | ||
|
||
ros2_cpp_binary( | ||
name = "ros_listener", | ||
srcs = ["ros_listener.cc"], | ||
deps = [ | ||
"@ros2_common_interfaces//:cpp_std_msgs", | ||
"@ros2_rclcpp//:rclcpp", | ||
], | ||
) | ||
|
||
# Disabled ros2_launch temporarily, for following issue: | ||
# Error: file '@rules_python//python:pip.bzl' does not contain symbol 'whl_filegroup' | ||
#ros2_launch( | ||
# name = "ros_chatter", | ||
# launch_file = "ros_chatter.py", | ||
# nodes = [ | ||
# ":ros_listener", | ||
# ":ros_talker", | ||
# ], | ||
#) | ||
|
||
cpplint() |
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,6 @@ | ||
## ROS2 Example | ||
|
||
### References | ||
- https://github.com/mvukov/rules_ros2 | ||
- https://github.com/ApexAI/rules_ros/ | ||
- https://github.com/RobotLocomotion/drake-ros |
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,16 @@ | ||
"""Launch a talker and a listener.""" | ||
import launch | ||
import launch_ros.actions | ||
|
||
def generate_launch_description(): | ||
"""Launch a talker and a listener.""" | ||
return launch.LaunchDescription([ | ||
launch_ros.actions.Node( | ||
# Provide the rootpath for the node. | ||
executable='chatter/talker', | ||
output='screen', | ||
name='talker'), | ||
launch_ros.actions.Node(executable='chatter/listener', | ||
output='screen', | ||
name='listener'), | ||
]) |
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,26 @@ | ||
// Copyright 2023 AI-Playground | ||
#include <iostream> | ||
#include <memory> | ||
|
||
#include "rclcpp/rclcpp.hpp" | ||
#include "std_msgs/msg/string.hpp" | ||
|
||
class MinimalSubscriber : public rclcpp::Node { | ||
public: | ||
MinimalSubscriber() : Node("minimal_subscriber") { | ||
subscription_ = create_subscription<std_msgs::msg::String>( | ||
"topic", 10, [this](std_msgs::msg::String::UniquePtr msg) { | ||
RCLCPP_INFO(get_logger(), "I heard: '%s'", msg->data.c_str()); | ||
}); | ||
} | ||
|
||
private: | ||
rclcpp::Subscription<std_msgs::msg::String>::SharedPtr subscription_; | ||
}; | ||
|
||
int main(int argc, char* argv[]) { | ||
rclcpp::init(argc, argv); | ||
rclcpp::spin(std::make_shared<MinimalSubscriber>()); | ||
rclcpp::shutdown(); | ||
return 0; | ||
} |
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,40 @@ | ||
// Copyright 2023 AI-Playground | ||
#include <chrono> // NOLINT [build/c++11] | ||
#include <memory> | ||
|
||
#include "rclcpp/rclcpp.hpp" | ||
#include "std_msgs/msg/string.hpp" | ||
|
||
/* This example creates a subclass of Node and uses a fancy C++11 lambda | ||
* function to shorten the callback syntax, at the expense of making the | ||
* code somewhat more difficult to understand at first glance. */ | ||
|
||
class MinimalPublisher : public rclcpp::Node { | ||
public: | ||
MinimalPublisher() : Node("minimal_publisher"), count_(0) { | ||
declare_parameter("callback_period_ms", 500); | ||
auto callback_period_ms = get_parameter("callback_period_ms").as_int(); | ||
|
||
publisher_ = create_publisher<std_msgs::msg::String>("topic", 10); | ||
auto timer_callback = [this]() -> void { | ||
auto message = std_msgs::msg::String(); | ||
message.data = "Hello, world! " + std::to_string(count_++); | ||
RCLCPP_INFO(get_logger(), "Publishing: '%s'", message.data.c_str()); | ||
publisher_->publish(message); | ||
}; | ||
timer_ = create_wall_timer(std::chrono::milliseconds(callback_period_ms), | ||
timer_callback); | ||
} | ||
|
||
private: | ||
rclcpp::TimerBase::SharedPtr timer_; | ||
rclcpp::Publisher<std_msgs::msg::String>::SharedPtr publisher_; | ||
size_t count_; | ||
}; | ||
|
||
int main(int argc, char* argv[]) { | ||
rclcpp::init(argc, argv); | ||
rclcpp::spin(std::make_shared<MinimalPublisher>()); | ||
rclcpp::shutdown(); | ||
return 0; | ||
} |
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 @@ | ||
package(default_visibility = ["//visibility:public"]) |
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,6 @@ | ||
## rules_ros2 | ||
|
||
See: https://github.com/bazelbuild/rules_ros2 | ||
|
||
### references | ||
- https://github.com/bazelbuild/rules_ros2 |
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,12 @@ | ||
"""Loads the rules_python package""" | ||
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") | ||
|
||
def clean_dep(dep): | ||
return str(Label(dep)) | ||
|
||
def repo(): | ||
git_repository( | ||
name = "com_github_mvukov_rules_ros2", | ||
remote = "https://github.com/mvukov/rules_ros2.git", | ||
commit = "b599d6af09b90e0d548d3cb6e39fed8c3ef7be70", | ||
) |