glowColorMode.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #ifndef GLOWCOLORMODE_H
19 #define GLOWCOLORMODE_H
20 
21 #include <mode.h>
22 
23 class GlowColorMode : public Mode
24 {
25 public:
26  GlowColorMode(color::rgba color, int priority = 0, double freq = 0.25, int pulses = 0, double timeout = 0)
27  :Mode(priority, freq, pulses, timeout), _timer_inc(0.0)
28  {
29  _color = color;
30  h = 0.0;
31  _inc = (1. / UPDATE_RATE_HZ) * _freq;
32  h_inc=0;
33  color::Color::rgb2hsv(color.r, color.g, color.b, h, s, v);
34  }
35 
36  void execute()
37  {
38  static int sign = 1;
39  float r = 0;
40  float g = 0;
41  float b = 0;
42 
43  if(_timer_inc >= 1.0)
44  {
45  double tmp = h;
46 
47  h_inc += 0.001 * sign;
48  if(h_inc >= 0.01 || h_inc <= -0.01)
49  {
50  sign *= -1;
51  _pulsed++;
52  }
53  h += h_inc;
54  if( h < 0)
55  h = 1 + h;
56 
57  //double fV = (exp(sin(_timer_inc))-1.0/M_E)*(1.000/(M_E-1.0/M_E));
58  double fV = (exp(sin( (M_PI/2)+h_inc*60 ))-0.36787944)*0.42545906411;
59 
60  color::Color::hsv2rgb(h, s, v, r, g, b);
61 
62  color::rgba col;
63  col.r = r;
64  col.g = g;
65  col.b = b;
66  col.a = fV;
67 
68  _timer_inc = 0.0;
69  m_sigColorReady(col);
70  h = tmp;
71  }
72  else
73  _timer_inc += _inc;
74  }
75 
76  std::string getName(){ return std::string("GlowColorMode"); }
77 
78 private:
79  double _timer_inc;
80  double _inc;
81  float h, s, v;
82  double h_inc;
83 };
84 
85 #endif
color::rgba _color
Definition: mode.h:121
static void rgb2hsv(float r, float g, float b, float &h, float &s, float &v)
Definition: colorUtils.h:54
double _timer_inc
Definition: glowColorMode.h:79
Definition: mode.h:26
int _pulsed
Definition: mode.h:119
static void hsv2rgb(float h, float s, float v, float &r, float &g, float &b)
Definition: colorUtils.h:81
static const unsigned int UPDATE_RATE_HZ
Definition: mode.h:126
double _freq
Definition: mode.h:114
std::string getName()
Definition: glowColorMode.h:76
boost::signals2::signal< void(color::rgba color)> m_sigColorReady
Definition: mode.h:128
GlowColorMode(color::rgba color, int priority=0, double freq=0.25, int pulses=0, double timeout=0)
Definition: glowColorMode.h:26


cob_light
Author(s): Benjamin Maidel
autogenerated on Wed Apr 7 2021 02:11:39