Skip to content

Commit

Permalink
Merge pull request #7 from OUXT-Polaris/feature/foxy
Browse files Browse the repository at this point in the history
enable pass colcon test
  • Loading branch information
hakuturu583 committed Jan 10, 2021
2 parents 024e762 + 9304349 commit e03d284
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ THE SOFTWARE.
* @brief Preset Color names
*/

#ifndef INCLUDE_COLOR_NAMES_COLOR_NAMES_H
#define INCLUDE_COLOR_NAMES_COLOR_NAMES_H
#ifndef COLOR_NAMES__COLOR_NAMES_HPP_
#define COLOR_NAMES__COLOR_NAMES_HPP_

#include <std_msgs/msg/color_rgba.hpp>

#include <cassert>
#include <string>
#include <map>
#include <std_msgs/msg/color_rgba.hpp>

namespace color_names
{
Expand All @@ -40,9 +42,8 @@ std_msgs::msg::ColorRGBA makeColorMsg(std::string preset_name, double alpha = 1.
*/
std_msgs::msg::ColorRGBA fromHsv(double h, double s, double v, double alpha = 1.0);

///@todo Read data from text data?
const std::map<std::string, std::array<float, 3>> COLOR_NAME_DICT{
//{"COLOR_NAME", {R, G, B}} //template
const std::map<std::string, std::array<float, 3>> COLOR_NAME_DICT {
// {"COLOR_NAME", {R, G, B}} //template
{"aliceblue", {0.941176, 0.972549, 1}},
{"antiquewhite", {0.980392, 0.921569, 0.843137}},
{"aqua", {0, 1, 1}},
Expand Down Expand Up @@ -183,8 +184,9 @@ const std::map<std::string, std::array<float, 3>> COLOR_NAME_DICT{
{"whitesmoke", {0.960784, 0.960784, 0.960784}},
{"yellow", {1, 1, 0}},
{"yellowgreen", {0.603922, 0.803922, 0.196078}},
{"ERROR", {0, 0, 0}}};
{"ERROR", {0, 0, 0}}
};

} // namespace color_names

#endif
#endif // COLOR_NAMES__COLOR_NAMES_HPP_
44 changes: 34 additions & 10 deletions src/color_names.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,40 @@
#include <color_names/color_names.h>
/*
Copyright (c) 2019 shuhei yoshida
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/


#include <color_names/color_names.hpp>
#include <string>

#include <iostream>

namespace color_names
{
/**
* @brief generate std_msgs::msg::ColorRGBA message from hsv values
* @param h hue
* @param s saturation
* @param h hue
* @param s saturation
* @param v value
* @param alpha alpha value of the color
* @return std_msgs::msg::ColorRGBA
* @return std_msgs::msg::ColorRGBA
*/
std_msgs::msg::ColorRGBA fromHsv(double h, double s, double v, double alpha)
{
Expand All @@ -21,8 +45,8 @@ std_msgs::msg::ColorRGBA fromHsv(double h, double s, double v, double alpha)
float b = v;
if (s > 0.0f) {
h *= 6.0f;
int i = (int)h;
float f = h - (float)i;
int i = static_cast<int>(h);
float f = h - static_cast<float>(i);
switch (i) {
default:
case 0:
Expand Down Expand Up @@ -61,14 +85,14 @@ std_msgs::msg::ColorRGBA fromHsv(double h, double s, double v, double alpha)
* @brief generate std_msgs::msg::ColorRGBA message from color name
* @param preset_name the name of the color
* @param alpha alpha value of the color
* @return std_msgs::msg::ColorRGBA
* @return std_msgs::msg::ColorRGBA
*/
std_msgs::msg::ColorRGBA makeColorMsg(std::string preset_name, double alpha)
{
std_msgs::msg::ColorRGBA c_msg;
c_msg.a = alpha;
if (c_msg.a < 0.) c_msg.a = 0.;
if (c_msg.a > 1.) c_msg.a = 1.;
if (c_msg.a < 0.) {c_msg.a = 0.;}
if (c_msg.a > 1.) {c_msg.a = 1.;}

auto found_itr = COLOR_NAME_DICT.find(preset_name);
if (found_itr != COLOR_NAME_DICT.end()) {
Expand All @@ -82,4 +106,4 @@ std_msgs::msg::ColorRGBA makeColorMsg(std::string preset_name, double alpha)
}
return c_msg;
}
} // namespace color_names
} // namespace color_names
39 changes: 30 additions & 9 deletions src/view_all.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
/*
Copyright (c) 2019 shuhei yoshida
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/


/**
* @file color_names_node.cpp
*/
Expand All @@ -9,12 +32,11 @@
* @date 2020-07-17
*/

#include <color_names/color_names.h>
#include <chrono>
#include <color_names/color_names.hpp>
#include <rclcpp/rclcpp.hpp>
#include <visualization_msgs/msg/marker_array.hpp>
using namespace color_names;
using namespace std::chrono_literals;

#include <chrono>

int main(int argc, char ** argv)
{
Expand All @@ -29,9 +51,8 @@ int main(int argc, char ** argv)
color_mrk.id = 0;
int id = 1;
int count = 0;
for (auto && data : COLOR_NAME_DICT) {
for (auto && data : color_names::COLOR_NAME_DICT) {
geometry_msgs::msg::Point p;
///@todo set points in good way, May be need to sort color data by names
p.x = 0.10 * (count % 10);
p.y = 0.10 * (count / 10);
count++;
Expand All @@ -49,19 +70,19 @@ int main(int argc, char ** argv)
m_txt.pose.orientation.w = 1;
mrks_msg.markers.push_back(m_txt);

color_mrk.colors.push_back(makeColorMsg(data.first, 1.0));
color_mrk.colors.push_back(color_names::makeColorMsg(data.first, 1.0));
color_mrk.points.push_back(p);
}
mrks_msg.markers.push_back(color_mrk);

auto mrks_pub =
node->create_publisher<visualization_msgs::msg::MarkerArray>("color_sample_marker", 1);
rclcpp::WallRate loop_rate(500ms);
rclcpp::WallRate loop_rate(std::chrono::milliseconds{500});
while (rclcpp::ok()) {
mrks_pub->publish(mrks_msg);
rclcpp::spin_some(node);
loop_rate.sleep();
}
rclcpp::spin(node);
return 0;
}
}

0 comments on commit e03d284

Please sign in to comment.