turnIndicatorMode.h
Go to the documentation of this file.
1 /*
2  * Copyright 2021 Mojin Robotics GmbH https://www.mojin-robotics.de
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 
19 #ifndef TURNINDICATORMODE_H
20 #define TURNINDICATORMODE_H
21 
22 #include <mode.h>
23 
24 class TurnIndicatorMode : public Mode
25 {
26 public:
27  TurnIndicatorMode(color::rgba color, size_t num_leds, int dir, int priority = 0, double freq = 0.25, int pulses = 0, double timeout = 0)
28  :Mode(priority, freq, pulses, timeout), _num_leds(num_leds)
29  {
30  _inc = (1. / UPDATE_RATE_HZ) * _freq;
31 
32  _color = color;
33  _colors.assign(_num_leds, color::rgba());
34  _colors[0] = color;
35  _pos = 0;
36  _dir = dir;
37  if(_num_leds%2 == 0)
38  {
39  _center_pos = _num_leds/2 - 1;
40  if(_dir < 0)
41  _center_pos--;
42  }
43  else
45 
46  _pos = _center_pos;
47  _keep_counter = 20;
48  }
49 
50  void execute()
51  {
52  if(_timer_inc >= 1.0)
53  {
54  //if we exeeded the array keep the colors for a few steps
55  //and reset afterwards
56  if(_pos == -1 || _pos == _num_leds)
57  {
58  _keep_counter--;
59  if(_keep_counter == 0)
60  {
61  _keep_counter = 20;
62  _pos = _center_pos;
63  _colors.assign(_num_leds, color::rgba());
64  }
65  }
66  else
67  {
68  _colors[_pos] = _color;
69  _pos += _dir;
70  }
71 
73 
74  _timer_inc = 0.0;
75  }
76  else
77  _timer_inc += _inc;
78  }
79 
80  std::string getName(){ return std::string("TurnIndicatorMode"); }
81 
82 private:
83  double _timer_inc;
84  double _inc;
85  double _pos;
86  double _dir;
89  int _num_leds;
90 };
91 
92 #endif
color::rgba _color
Definition: mode.h:121
std::vector< color::rgba > _colors
Definition: mode.h:122
Definition: mode.h:26
static const unsigned int UPDATE_RATE_HZ
Definition: mode.h:126
std::string getName()
TurnIndicatorMode(color::rgba color, size_t num_leds, int dir, int priority=0, double freq=0.25, int pulses=0, double timeout=0)
double _freq
Definition: mode.h:114
boost::signals2::signal< void(std::vector< color::rgba > &colors)> m_sigColorsReady
Definition: mode.h:129


cob_light
Author(s): Benjamin Maidel
autogenerated on Thu Nov 17 2022 03:17:28