@@ -112,84 +112,88 @@ double getArrayDirection(const lanelet::ConstPoint3d & p)
112
112
}
113
113
}
114
114
115
- void lightAsMarker (
116
- const rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr & node_logging,
117
- lanelet::ConstPoint3d p, visualization_msgs::msg::Marker * marker, const std::string & ns,
118
- const rclcpp::Time & current_time, const double & yaw)
115
+ void addColor (visualization_msgs::msg::Marker & marker, const uint8_t & p_color)
119
116
{
120
- if (marker == nullptr ) {
121
- RCLCPP_ERROR_STREAM (node_logging->get_logger (), __FUNCTION__ << " : marker is null pointer!" );
122
- return ;
117
+ if (p_color == TrafficLightElement::RED) {
118
+ marker.color .r = 1 .0f ;
119
+ marker.color .g = 0 .0f ;
120
+ marker.color .b = 0 .0f ;
121
+ } else if (p_color == TrafficLightElement::GREEN) {
122
+ marker.color .r = 0 .0f ;
123
+ marker.color .g = 1 .0f ;
124
+ marker.color .b = 0 .0f ;
125
+ } else if (p_color == TrafficLightElement::AMBER) {
126
+ marker.color .r = 1 .0f ;
127
+ marker.color .g = 1 .0f ;
128
+ marker.color .b = 0 .0f ;
129
+ } else if (p_color == TrafficLightElement::UNKNOWN) {
130
+ marker.color .r = 1 .0f ;
131
+ marker.color .g = 1 .0f ;
132
+ marker.color .b = 1 .0f ;
133
+ } else if (p_color == TrafficLightElement::WHITE) {
134
+ marker.color .r = 1 .0f ;
135
+ marker.color .g = 1 .0f ;
136
+ marker.color .b = 1 .0f ;
137
+ } else {
138
+ marker.color .r = 1 .0f ;
139
+ marker.color .g = 1 .0f ;
140
+ marker.color .b = 1 .0f ;
123
141
}
142
+ }
124
143
125
- marker->header .frame_id = " map" ;
126
- marker->header .stamp = current_time;
127
- marker->frame_locked = true ;
128
- marker->ns = ns;
129
- marker->id = p.id ();
130
- marker->lifetime = rclcpp::Duration::from_seconds (0.2 );
144
+ void lightAsMarker (
145
+ lanelet::ConstPoint3d p, visualization_msgs::msg::Marker & marker, const std::string & ns,
146
+ const rclcpp::Time & current_time, const double & yaw)
147
+ {
148
+ marker.header .frame_id = " map" ;
149
+ marker.header .stamp = current_time;
150
+ marker.frame_locked = true ;
151
+ marker.ns = ns;
152
+ marker.id = p.id ();
153
+ marker.lifetime = rclcpp::Duration::from_seconds (0.2 );
131
154
132
155
if (!p.hasAttribute (" arrow" )) {
133
- marker-> type = visualization_msgs::msg::Marker::SPHERE;
134
- marker-> pose .position .x = p.x ();
135
- marker-> pose .position .y = p.y ();
136
- marker-> pose .position .z = p.z ();
137
- marker-> pose .orientation .x = 0.0 ;
138
- marker-> pose .orientation .y = 0.0 ;
139
- marker-> pose .orientation .z = 0.0 ;
140
- marker-> pose .orientation .w = 1.0 ;
156
+ marker. type = visualization_msgs::msg::Marker::SPHERE;
157
+ marker. pose .position .x = p.x ();
158
+ marker. pose .position .y = p.y ();
159
+ marker. pose .position .z = p.z ();
160
+ marker. pose .orientation .x = 0.0 ;
161
+ marker. pose .orientation .y = 0.0 ;
162
+ marker. pose .orientation .z = 0.0 ;
163
+ marker. pose .orientation .w = 1.0 ;
141
164
142
165
float s = 0.3 ;
143
166
144
- marker-> scale .x = s;
145
- marker-> scale .y = s;
146
- marker-> scale .z = s;
167
+ marker. scale .x = s;
168
+ marker. scale .y = s;
169
+ marker. scale .z = s;
147
170
} else {
148
- marker-> type = visualization_msgs::msg::Marker::ARROW;
171
+ marker. type = visualization_msgs::msg::Marker::ARROW;
149
172
150
173
float length = 0.3 ;
151
174
152
175
const double pitch = getArrayDirection (p);
153
176
tf2::Quaternion q;
154
177
q.setRPY (0.0 , pitch, yaw);
155
178
156
- marker-> pose .position .x = p.x () - (length / 2.0 ) * std::cos (pitch) * std::cos (yaw);
157
- marker-> pose .position .y = p.y () - (length / 2.0 ) * std::cos (pitch) * std::sin (yaw);
158
- marker-> pose .position .z = p.z () + (length / 2.0 ) * std::sin (pitch);
179
+ marker. pose .position .x = p.x () - (length / 2.0 ) * std::cos (pitch) * std::cos (yaw);
180
+ marker. pose .position .y = p.y () - (length / 2.0 ) * std::cos (pitch) * std::sin (yaw);
181
+ marker. pose .position .z = p.z () + (length / 2.0 ) * std::sin (pitch);
159
182
160
- marker-> pose .orientation .x = q.x ();
161
- marker-> pose .orientation .y = q.y ();
162
- marker-> pose .orientation .z = q.z ();
163
- marker-> pose .orientation .w = q.w ();
183
+ marker. pose .orientation .x = q.x ();
184
+ marker. pose .orientation .y = q.y ();
185
+ marker. pose .orientation .z = q.z ();
186
+ marker. pose .orientation .w = q.w ();
164
187
165
- marker-> scale .x = length;
166
- marker-> scale .y = 0.1 ;
167
- marker-> scale .z = 0.1 ;
188
+ marker. scale .x = length;
189
+ marker. scale .y = 0.1 ;
190
+ marker. scale .z = 0.1 ;
168
191
}
169
192
170
- marker-> color .a = 0 .999f ;
193
+ marker. color .a = 0 .999f ;
171
194
172
195
uint8_t p_color = convertMapcolor2Msg (p);
173
- if (p_color == TrafficLightElement::RED) {
174
- marker->color .r = 1 .0f ;
175
- marker->color .g = 0 .0f ;
176
- marker->color .b = 0 .0f ;
177
- } else if (p_color == TrafficLightElement::GREEN) {
178
- marker->color .r = 0 .0f ;
179
- marker->color .g = 1 .0f ;
180
- marker->color .b = 0 .0f ;
181
- } else if (p_color == TrafficLightElement::AMBER) {
182
- marker->color .r = 1 .0f ;
183
- marker->color .g = 1 .0f ;
184
- marker->color .b = 0 .0f ;
185
- } else {
186
- RCLCPP_WARN (
187
- node_logging->get_logger (),
188
- " color does not match 'red', 'green' or 'amber'. so represented by white." );
189
- marker->color .r = 1 .0f ;
190
- marker->color .g = 1 .0f ;
191
- marker->color .b = 1 .0f ;
192
- }
196
+ addColor (marker, p_color);
193
197
}
194
198
} // namespace utils
195
199
@@ -256,8 +260,7 @@ void TrafficLightMapVisualizerNode::trafficSignalsCallback(
256
260
for (const auto & elem : input_traffic_signal.elements ) {
257
261
visualization_msgs::msg::Marker marker;
258
262
if (utils::isCompareColorAndShape (pt, elem)) {
259
- utils::lightAsMarker (
260
- get_node_logging_interface (), pt, &marker, " traffic_light" , current_time, yaw);
263
+ utils::lightAsMarker (pt, marker, " traffic_light" , current_time, yaw);
261
264
}
262
265
output_msg.markers .push_back (marker);
263
266
}
0 commit comments