glowColorMode.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *   http://www.apache.org/licenses/LICENSE-2.0
00009 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 
00018 #ifndef GLOWCOLORMODE_H
00019 #define GLOWCOLORMODE_H
00020 
00021 #include <mode.h>
00022 
00023 class GlowColorMode : public Mode
00024 {
00025 public:
00026     GlowColorMode(color::rgba color, int priority = 0, double freq = 0.25, int pulses = 0, double timeout = 0)
00027         :Mode(priority, freq, pulses, timeout), _timer_inc(0.0)
00028     {
00029         _color = color;
00030         h = 0.0;
00031         _inc = (1. / UPDATE_RATE_HZ) * _freq;
00032         h_inc=0;
00033         color::Color::rgb2hsv(color.r, color.g, color.b, h, s, v);
00034     }
00035 
00036     void execute()
00037     {
00038         static int sign = 1;
00039         float r = 0;
00040         float g = 0;
00041         float b = 0;
00042 
00043         if(_timer_inc >= 1.0)
00044         {
00045             double tmp = h;
00046 
00047             h_inc += 0.001 * sign;
00048             if(h_inc >= 0.01 || h_inc <= -0.01)
00049             {
00050                 sign *= -1;
00051                 _pulsed++;
00052             }
00053             h += h_inc;
00054             if( h < 0)
00055                 h = 1 + h;
00056             
00057             //double fV = (exp(sin(_timer_inc))-1.0/M_E)*(1.000/(M_E-1.0/M_E));
00058             double fV = (exp(sin( (M_PI/2)+h_inc*60 ))-0.36787944)*0.42545906411;
00059 
00060             color::Color::hsv2rgb(h, s, v, r, g, b);
00061 
00062             color::rgba col;
00063             col.r = r;
00064             col.g = g;
00065             col.b = b;
00066             col.a = fV;
00067 
00068             _timer_inc = 0.0;
00069             m_sigColorReady(col);
00070             h = tmp;
00071         }
00072         else
00073             _timer_inc += _inc;
00074     }
00075 
00076     std::string getName(){ return std::string("GlowColorMode"); }
00077 
00078 private:
00079     double _timer_inc;
00080     double _inc;
00081     float h, s, v;
00082     double h_inc;
00083 };
00084 
00085 #endif


cob_light
Author(s): Benjamin Maidel
autogenerated on Sat Jun 8 2019 21:02:07