Skip to content

Commit ab1cf5c

Browse files
committed
Minimal example code
1 parent bd70cb2 commit ab1cf5c

3 files changed

Lines changed: 98 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) 2022 OUXT Polaris
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
17+
#include "pkgname/visibility_control.h"
18+
19+
// Headers in ROS2
20+
#include <rclcpp/rclcpp.hpp>
21+
22+
// Headers needed in pub/sub, exposed types
23+
#include <memory> // shared_ptr in pub_
24+
#include <perception_msgs/msg/tracking2_d.hpp> // Tracking2D in pub_
25+
26+
namespace pkgname
27+
{
28+
class ExampleComponent : public rclcpp::Node
29+
{
30+
public:
31+
PKGNAME_PUBLIC
32+
explicit ExampleComponent(const rclcpp::NodeOptions & options);
33+
34+
private:
35+
std::shared_ptr<rclcpp::Publisher<perception_msgs::msg::Tracking2D>> pub_;
36+
};
37+
}

src/example_component.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) 2020 OUXT Polaris
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Headers in this package
16+
#include "pkgname/example_component.hpp"
17+
18+
// Components
19+
#include <rclcpp_components/register_node_macro.hpp>
20+
21+
// Headers needed in this component
22+
23+
namespace pkgname
24+
{
25+
ExampleComponent::ExampleComponent(const rclcpp::NodeOptions & options)
26+
: Node("example_node", options)
27+
{
28+
//TODO:
29+
}
30+
}
31+
32+
RCLCPP_COMPONENTS_REGISTER_NODE(pkgname::ExampleComponent)

src/example_node.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) 2022 OUXT Polaris
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Headers in this package
16+
#include <pkgname/example_component.hpp>
17+
18+
#include <memory>
19+
#include <rclcpp/rclcpp.hpp>
20+
21+
int main(int argc, char * argv[])
22+
{
23+
rclcpp::init(argc, argv);
24+
rclcpp::NodeOptions options;
25+
auto component = std::make_shared<pkgname::ExampleComponent>(options);
26+
rclcpp::spin(component);
27+
rclcpp::shutdown();
28+
return 0;
29+
}

0 commit comments

Comments
 (0)