1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Displayプラグインの雛形

Last updated at Posted at 2021-03-11

rviz2プラグインの作り方 トップページへ

トピックなし

AxesやGridのようにトピックの購読なしで動作するプラグイン

display_template.hpp
#ifndef SAMPLE_RVIZ_PLUGINS_DISPLAY_TEMPLATE_HPP
#define SAMPLE_RVIZ_PLUGINS_DISPLAY_TEMPLATE_HPP

#include <rviz_common/display.hpp>

namespace sample_rviz_plugins
{

class DisplayTemplate : public rviz_common::Display
{
    Q_OBJECT
public:
    DisplayTemplate();

    ~DisplayTemplate() override;

    void onInitialize() override;
    void update(float dt, float ros_dt) override;

protected:
    void onEnable() override;
    void onDisable() override;

private Q_SLOTS:
    // void updateShape();

private:
};

}

#endif // SAMPLE_RVIZ_PLUGINS_DISPLAY_TEMPLATE_HPP
display_template.cpp
#include "display_template.hpp"

#include <rviz_common/display_context.hpp>

namespace rviz_default_plugins
{

DisplayTemplate::DisplayTemplate()
    : Display()
{
}

DisplayTemplate::~DisplayTemplate() = default;

void DisplayTemplate::onInitialize()
{
}

void DisplayTemplate::onEnable()
{
}

void DisplayTemplate::onDisable()
{
}

void DisplayTemplate::update(float dt, float ros_dt)
{
    (void)dt;
    (void)ros_dt;
    
}

}

#include <pluginlib/class_list_macros.hpp>
PLUGINLIB_EXPORT_CLASS(sample_rviz_plugins::DisplayTemplate, rviz_common::Display)

トピックあり

Odometry,Pose,Pathのようにトピックを購読して動作するプラグイン

topic_display_template.hpp
#ifndef SAMPLE_RVIZ_PLUGINS_TOPIC_DISPLAY_TEMPLATE_HPP
#define SAMPLE_RVIZ_PLUGINS_TOPIC_DISPLAY_TEMPLATE_HPP

#include <std_msgs/msg/float32.hpp>
#include <rviz_common/ros_topic_display.hpp>
#include <mutex>

namespace sample_rviz_plugins
{

class TopicDisplayTemplate
    : public rviz_common::RosTopicDisplay<std_msgs::msg::Float32>
{
    Q_OBJECT
public:
    TopicDisplayTemplate();
    ~TopicDisplayTemplate() override;

protected:
    void onEnable() override;
    void onDisable() override;
    void onInitialize() override;
    void processMessage(std_msgs::msg::Float32::ConstSharedPtr msg) override;
    void update(float wall_dt, float ros_dt) override;
    void reset() override;

    std::mutex mutex_;
private:
};

}

#endif // SAMPLE_RVIZ_PLUGINS_TOPIC_DISPLAY_TEMPLATE_HPP
topic_display_template.cpp
#include "topic_display_template.hpp"

#include <rviz_common/display_context.hpp>

namespace sample_rviz_plugins
{

TopicDisplayTemplate::TopicDisplayTemplate()
{
}

TopicDisplayTemplate::~TopicDisplayTemplate()
{
}

void TopicDisplayTemplate::onInitialize()
{
    RTDClass::onInitialize();
}

void TopicDisplayTemplate::update(float wall_dt, float ros_dt)
{
    (void)dt;
    (void)ros_dt;
    
}

void TopicDisplayTemplate::processMessage(std_msgs::msg::Float32::ConstSharedPtr msg)
{
    std::lock_guard<std::mutex> lock(mutex_);
    
}

void TopicDisplayTemplate::reset()
{
    RTDClass::reset();
}

void TopicDisplayTemplate::onEnable()
{
    subscribe();
}

void TopicDisplayTemplate::onDisable()
{
    unsubscribe();
}

}

#include <pluginlib/class_list_macros.hpp>
PLUGINLIB_EXPORT_CLASS( sample_rviz_plugins::TopicDisplayTemplate, rviz_common::Display )
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?