SMACC2
Loading...
Searching...
No Matches
cl_nav2z::CpWaypointsVisualizer Class Reference

#include <cp_waypoints_visualizer.hpp>

Inheritance diagram for cl_nav2z::CpWaypointsVisualizer:
Inheritance graph
Collaboration diagram for cl_nav2z::CpWaypointsVisualizer:
Collaboration graph

Public Member Functions

 CpWaypointsVisualizer (rclcpp::Duration duration)
 
void onInitialize () override
 
- Public Member Functions inherited from smacc2::ISmaccComponent
 ISmaccComponent ()
 
virtual ~ISmaccComponent ()
 
 ISmaccComponent (const ISmaccComponent &)=delete
 
ISmaccComponent & operator= (const ISmaccComponent &)=delete
 
 ISmaccComponent (ISmaccComponent &&)=delete
 
ISmaccComponent & operator= (ISmaccComponent &&)=delete
 
virtual std::string getName () const
 
- Public Member Functions inherited from smacc2::ISmaccUpdatable
 ISmaccUpdatable ()
 
 ISmaccUpdatable (rclcpp::Duration duration)
 
virtual ~ISmaccUpdatable ()=default
 
 ISmaccUpdatable (const ISmaccUpdatable &)=delete
 
ISmaccUpdatable & operator= (const ISmaccUpdatable &)=delete
 
 ISmaccUpdatable (ISmaccUpdatable &&)=delete
 
ISmaccUpdatable & operator= (ISmaccUpdatable &&)=delete
 
void executeUpdate (rclcpp::Node::SharedPtr node)
 
void setUpdatePeriod (rclcpp::Duration duration)
 

Public Attributes

cl_nav2z::CpWaypointNavigator * waypointsNavigator_ = nullptr
 

Protected Member Functions

void update () override
 
- Protected Member Functions inherited from smacc2::ISmaccComponent
template<typename TOrthogonal , typename TClient >
void onComponentInitialization ()
 
template<typename EventType >
void postEvent (const EventType &ev)
 
template<typename EventType >
void postEvent ()
 
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
template<typename TComponent >
void requiresComponent (TComponent *&requiredComponentStorage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
template<typename TComponent >
void requiresComponent (const std::string &name, TComponent *&requiredComponentStorage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
template<typename TClient >
void requiresClient (TClient *&requiredClientStorage)
 
template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs>
SmaccComponentType * createSiblingComponent (const TArgs &... targs)
 
template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs>
SmaccComponentType * createSiblingNamedComponent (const std::string &name, const TArgs &... targs)
 
rclcpp::Node::SharedPtr getNode ()
 
rclcpp::Logger getLogger () const
 
ISmaccStateMachine * getStateMachine ()
 
- Protected Member Functions inherited from smacc2::ISmaccUpdatable

Private Member Functions

void createMarker (const geometry_msgs::msg::Pose &waypoint, visualization_msgs::msg::Marker &m)
 
void createMarkerLabel (const geometry_msgs::msg::Pose &waypoint, std::string label, visualization_msgs::msg::Marker &m)
 

Private Attributes

std::mutex m_mutex_
 
rclcpp::Publisher< visualization_msgs::msg::MarkerArray >::SharedPtr markersPub_
 
visualization_msgs::msg::MarkerArray markers_
 
visualization_msgs::msg::MarkerArray markerLabels_
 

Additional Inherited Members

- Protected Attributes inherited from smacc2::ISmaccComponent
ISmaccStateMachine * stateMachine_ = nullptr
 
ISmaccClient * owner_ = nullptr
 

Detailed Description

Definition at line 34 of file cp_waypoints_visualizer.hpp.

Constructor & Destructor Documentation

◆ CpWaypointsVisualizer()

cl_nav2z::CpWaypointsVisualizer::CpWaypointsVisualizer ( rclcpp::Duration duration)

Definition at line 27 of file cp_waypoints_visualizer.cpp.

27 : ISmaccUpdatable(duration)
28{
29}

Member Function Documentation

◆ createMarker()

void cl_nav2z::CpWaypointsVisualizer::createMarker ( const geometry_msgs::msg::Pose & waypoint,
visualization_msgs::msg::Marker & m )
private

Definition at line 83 of file cp_waypoints_visualizer.cpp.

85{
86 marker.header.frame_id = frameid;
87 marker.header.stamp = getNode()->now();
88 marker.ns = "waypoints";
89
90 marker.id = static_cast<int>(markers_.markers.size());
91 marker.type = visualization_msgs::msg::Marker::SPHERE;
92 marker.action = visualization_msgs::msg::Marker::ADD;
93 marker.scale.x = 0.1;
94 marker.scale.y = 0.1;
95 marker.scale.z = 0.1;
96
97 marker.color.a = 1.0;
98 marker.pose = waypoint;
99}
visualization_msgs::msg::MarkerArray markers_
rclcpp::Node::SharedPtr getNode()
const std::string frameid

References cl_nav2z::frameid, smacc2::ISmaccComponent::getNode(), and markers_.

Referenced by onInitialize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createMarkerLabel()

void cl_nav2z::CpWaypointsVisualizer::createMarkerLabel ( const geometry_msgs::msg::Pose & waypoint,
std::string label,
visualization_msgs::msg::Marker & m )
private

Definition at line 62 of file cp_waypoints_visualizer.cpp.

65{
66 marker.header.frame_id = frameid;
67 marker.header.stamp = getNode()->now();
68 marker.ns = "waypoints_labels";
69
70 marker.id = static_cast<int>(markers_.markers.size());
71 marker.type = visualization_msgs::msg::Marker::TEXT_VIEW_FACING;
72 marker.action = visualization_msgs::msg::Marker::ADD;
73 marker.scale.x = 0.3;
74 marker.scale.y = 0.3;
75 marker.scale.z = 0.3;
76 marker.text = label;
77
78 marker.color.a = 1.0;
79 marker.pose = waypoint;
80 marker.pose.position.z += 0.3;
81}

References cl_nav2z::frameid, smacc2::ISmaccComponent::getNode(), and markers_.

Referenced by onInitialize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onInitialize()

void cl_nav2z::CpWaypointsVisualizer::onInitialize ( )
overridevirtual

Reimplemented from smacc2::ISmaccComponent.

Definition at line 31 of file cp_waypoints_visualizer.cpp.

32{
33 markersPub_ = getNode()->create_publisher<visualization_msgs::msg::MarkerArray>(
34 "cp_waypoints_visualizer/visualization_markers", rclcpp::QoS(rclcpp::KeepLast(1)));
35
36 this->requiresComponent(waypointsNavigator_, ComponentRequirement::HARD);
37 auto & waypoints = waypointsNavigator_->getWaypoints();
38 auto & waypointsNames = waypointsNavigator_->getWaypointNames();
39
40 int i = 0;
41 for (auto & waypoint : waypoints)
42 {
43 // an unnamed waypoint has an empty name
44 std::string name = waypointsNames[i];
45 if (name.empty())
46 {
47 name = "waypoint_" + std::to_string(i);
48 }
49
50 visualization_msgs::msg::Marker marker;
51 createMarker(waypoint, marker);
52 markers_.markers.push_back(marker);
53
54 visualization_msgs::msg::Marker markerlabel;
55 createMarkerLabel(waypoint, name, markerlabel);
56 markerLabels_.markers.push_back(markerlabel);
57
58 i++;
59 }
60}
const std::vector< geometry_msgs::msg::Pose > & getWaypoints() const
const std::vector< std::string > & getWaypointNames() const
visualization_msgs::msg::MarkerArray markerLabels_
cl_nav2z::CpWaypointNavigator * waypointsNavigator_
rclcpp::Publisher< visualization_msgs::msg::MarkerArray >::SharedPtr markersPub_
void createMarker(const geometry_msgs::msg::Pose &waypoint, visualization_msgs::msg::Marker &m)
void createMarkerLabel(const geometry_msgs::msg::Pose &waypoint, std::string label, visualization_msgs::msg::Marker &m)
void requiresComponent(TComponent *&requiredComponentStorage, ComponentRequirement requirementType=ComponentRequirement::SOFT)

References createMarker(), createMarkerLabel(), smacc2::ISmaccComponent::getNode(), cl_nav2z::CpWaypointNavigatorBase::getWaypointNames(), cl_nav2z::CpWaypointNavigatorBase::getWaypoints(), markerLabels_, markers_, markersPub_, smacc2::ISmaccComponent::requiresComponent(), and waypointsNavigator_.

Here is the call graph for this function:

◆ update()

void cl_nav2z::CpWaypointsVisualizer::update ( )
overrideprotectedvirtual

Implements smacc2::ISmaccUpdatable.

Definition at line 101 of file cp_waypoints_visualizer.cpp.

102{
103 std::lock_guard<std::mutex> guard(m_mutex_);
104
106
107 int i = 0;
108
109 for (auto & marker : markers_.markers)
110 {
111 marker.header.stamp = getNode()->now();
112
113 if (i >= index)
114 {
115 marker.color.r = 1.0;
116 marker.color.g = 0;
117 marker.color.b = 0;
118 }
119 else
120 {
121 marker.color.r = 0.0;
122 marker.color.g = 1.0;
123 marker.color.b = 0;
124 }
125 i++;
126 }
127
128 i = 0;
129 for (auto & marker : markerLabels_.markers)
130 {
131 marker.header.stamp = getNode()->now();
132
133 if (i >= index)
134 {
135 marker.color.r = 1.0;
136 marker.color.g = 0;
137 marker.color.b = 0;
138 }
139 else
140 {
141 marker.color.r = 0.0;
142 marker.color.g = 1.0;
143 marker.color.b = 0;
144 }
145 i++;
146 }
147
148 markersPub_->publish(markers_);
149 markersPub_->publish(markerLabels_);
150}

References cl_nav2z::CpWaypointNavigatorBase::getCurrentWaypointIndex(), smacc2::ISmaccComponent::getNode(), m_mutex_, markerLabels_, markers_, markersPub_, and waypointsNavigator_.

Here is the call graph for this function:

Member Data Documentation

◆ m_mutex_

std::mutex cl_nav2z::CpWaypointsVisualizer::m_mutex_
private

Definition at line 47 of file cp_waypoints_visualizer.hpp.

Referenced by update().

◆ markerLabels_

visualization_msgs::msg::MarkerArray cl_nav2z::CpWaypointsVisualizer::markerLabels_
private

Definition at line 51 of file cp_waypoints_visualizer.hpp.

Referenced by onInitialize(), and update().

◆ markers_

visualization_msgs::msg::MarkerArray cl_nav2z::CpWaypointsVisualizer::markers_
private

Definition at line 50 of file cp_waypoints_visualizer.hpp.

Referenced by createMarker(), createMarkerLabel(), onInitialize(), and update().

◆ markersPub_

rclcpp::Publisher<visualization_msgs::msg::MarkerArray>::SharedPtr cl_nav2z::CpWaypointsVisualizer::markersPub_
private

Definition at line 49 of file cp_waypoints_visualizer.hpp.

Referenced by onInitialize(), and update().

◆ waypointsNavigator_

cl_nav2z::CpWaypointNavigator* cl_nav2z::CpWaypointsVisualizer::waypointsNavigator_ = nullptr

Definition at line 37 of file cp_waypoints_visualizer.hpp.

Referenced by onInitialize(), and update().


The documentation for this class was generated from the following files: