Skip to content

Commit b16d7ca

Browse files
committed
Created skeleton for landmarkserver
1 parent 6be0d53 commit b16d7ca

File tree

5 files changed

+152
-40
lines changed

5 files changed

+152
-40
lines changed

mission/Landmark_server/test.cpp

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
cmake_minimum_required(VERSION 3.8)
2+
project(landmark_server)
3+
4+
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
5+
add_compile_options(-Wall -Wextra -Wpedantic)
6+
endif()
7+
8+
# find dependencies
9+
find_package(ament_cmake REQUIRED)
10+
find_package(rclcpp REQUIRED)
11+
find_package(std_msgs REQUIRED)
12+
# uncomment the following section in order to fill in
13+
# further dependencies manually.
14+
# find_package(<dependency> REQUIRED)
15+
16+
add_executable(landmark_server_Node src/landmark_server.cpp)
17+
add_executable(landmark_server_Node_sub src/landmark_server_sub.cpp)
18+
ament_target_dependencies(landmark_server_Node rclcpp std_msgs)
19+
ament_target_dependencies(landmark_server_Node_sub rclcpp std_msgs)
20+
21+
install(TARGETS
22+
landmark_server_Node
23+
landmark_server_Node_sub
24+
DESTINATION lib/${PROJECT_NAME})
25+
26+
if(BUILD_TESTING)
27+
find_package(ament_lint_auto REQUIRED)
28+
# the following line skips the linter which checks for copyrights
29+
# comment the line when a copyright and license is added to all source files
30+
set(ament_cmake_copyright_FOUND TRUE)
31+
# the following line skips cpplint (only works in a git repo)
32+
# comment the line when this package is in a git repo and when
33+
# a copyright and license is added to all source files
34+
set(ament_cmake_cpplint_FOUND TRUE)
35+
ament_lint_auto_find_test_dependencies()
36+
endif()
37+
38+
ament_package()
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0"?>
2+
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="3">
4+
<name>landmark_server</name>
5+
<version>0.0.0</version>
6+
<description>TODO: Package description</description>
7+
<maintainer email="[email protected]">philliab</maintainer>
8+
<license>TODO: License declaration</license>
9+
10+
<buildtool_depend>ament_cmake</buildtool_depend>
11+
12+
<depend>rclcpp</depend>
13+
<depend>std_msgs</depend>
14+
15+
<test_depend>ament_lint_auto</test_depend>
16+
<test_depend>ament_lint_common</test_depend>
17+
18+
<export>
19+
<build_type>ament_cmake</build_type>
20+
</export>
21+
</package>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <chrono>
2+
#include <functional>
3+
#include <memory>
4+
#include <string>
5+
6+
#include "rclcpp/rclcpp.hpp"
7+
#include "std_msgs/msg/string.hpp"
8+
9+
using namespace std::chrono_literals;
10+
11+
/* This example creates a subclass of Node and uses std::bind() to register a
12+
* member function as a callback from the timer. */
13+
14+
class MinimalPublisher : public rclcpp::Node
15+
{
16+
public:
17+
MinimalPublisher()
18+
: Node("minimal_publisher"), count_(0)
19+
{
20+
publisher_ = this->create_publisher<std_msgs::msg::String>("topic", 10);
21+
timer_ = this->create_wall_timer(
22+
500ms, std::bind(&MinimalPublisher::timer_callback, this));
23+
}
24+
25+
private:
26+
void timer_callback()
27+
{
28+
auto message = std_msgs::msg::String();
29+
message.data = "Hello, world! " + std::to_string(count_++);
30+
RCLCPP_INFO(this->get_logger(), "Publishing: '%s'", message.data.c_str());
31+
publisher_->publish(message);
32+
}
33+
rclcpp::TimerBase::SharedPtr timer_;
34+
rclcpp::Publisher<std_msgs::msg::String>::SharedPtr publisher_;
35+
size_t count_;
36+
};
37+
38+
int main(int argc, char * argv[])
39+
{
40+
rclcpp::init(argc, argv);
41+
rclcpp::spin(std::make_shared<MinimalPublisher>());
42+
rclcpp::shutdown();
43+
return 0;
44+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include <memory>
2+
3+
#include "rclcpp/rclcpp.hpp"
4+
#include "std_msgs/msg/string.hpp"
5+
#include <vortex_msgs/msg/landmark_array.hpp>
6+
using std::placeholders::_1;
7+
8+
using vortex_msgs::msg::LandmarkArray;
9+
using vortex_msgs::msg::Landmark;
10+
11+
class LandmarkArraySubscriber : public rclcpp::Node
12+
{
13+
public:
14+
LandmarkArraySubscriber()
15+
: rclcpp::Node("landmark_array_subscriber")
16+
{
17+
storedLandmarks_=std::make_shared<LandmarkArray>();
18+
19+
20+
sub_ = this->create_subscription<LandmarkArray>(
21+
"/landmarks", rclcpp::QoS(10), std::bind(&LandmarkArraySubscriber::callback, this, _1));
22+
}
23+
24+
private:
25+
void callback(const LandmarkArray::SharedPtr msg) {
26+
RCLCPP_INFO(get_logger(), "frame='%s' count=%zu",
27+
msg->header.frame_id.c_str(), msg->landmarks.size());
28+
29+
if (!msg->landmarks.empty()) {
30+
// NOTE: adjust this depending on your actual Landmark.msg:
31+
// If Landmark has .odom.pose.pose.position:
32+
const auto &p = msg->landmarks.front().odom.pose.pose.position;
33+
// If Landmark has .pose.pose.position instead, use that line instead.
34+
35+
RCLCPP_INFO(get_logger(), "first landmark pos = (%.2f, %.2f, %.2f)",
36+
p.x, p.y, p.z);
37+
}
38+
}
39+
40+
rclcpp::Subscription<LandmarkArray>::SharedPtr sub_;
41+
};
42+
43+
int main(int argc, char * argv[])
44+
{
45+
rclcpp::init(argc, argv);
46+
rclcpp::spin(std::make_shared<LandMarkArraySubscriber>());
47+
rclcpp::shutdown();
48+
return 0;
49+
}

0 commit comments

Comments
 (0)