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 #ifndef TURNINDICATORMODE_H
18 #define TURNINDICATORMODE_H
19 
20 #include <mode.h>
21 
22 class TurnIndicatorMode : public Mode {
23 public:
24  TurnIndicatorMode(color::rgba color, size_t num_leds, int dir,
25  int priority = 0, double freq = 0.25, int pulses = 0,
26  double timeout = 0)
27  : Mode(priority, freq, pulses, timeout), _num_leds(num_leds),
28  _timer_inc(0), _toggle(false) {
29  _color = color;
30  _inc = (1. / UPDATE_RATE_HZ) * _freq;
31 
32  _colors.assign(_num_leds, color::rgba());
33  _dir = dir;
34  // If the direction is -1 (left), then the LED indices are set to to the
35  // first and last quarters of the LEDs.
36  if (dir == -1) {
37  size_t from = 0;
38  size_t until = _num_leds / 4;
39  for (size_t i = from; i < until; ++i) {
40  _led_indices.push_back(i);
41  }
42  from = 3 * _num_leds / 4;
43  until = _num_leds;
44  for (size_t i = from; i < until; ++i) {
45  _led_indices.push_back(i);
46  }
47  } else {
48  // If the direction is not -1 (right), then the LED indices are set to the
49  // second and third quarters of the LEDs.
50  size_t from = _num_leds / 4;
51  size_t until = 3 * _num_leds / 4;
52  for (size_t i = from; i < until; ++i) {
53  _led_indices.push_back(i);
54  }
55  }
56  }
57 
58  void execute() {
59  if (_timer_inc >= 1.0) {
60  color::rgba col;
61  col.r = _color.r;
62  col.g = _color.g;
63  col.b = _color.b;
64  col.a = _color.a * (int)_toggle;
65  _toggle = !_toggle;
66  for (size_t i = 0; i < _led_indices.size(); ++i) {
67  _colors[_led_indices[i]] = col;
68  }
70  _timer_inc = 0.0;
71  } else {
72  _timer_inc += _inc;
73  }
74  }
75 
76  std::string getName() { return std::string("TurnIndicatorMode"); }
77 
78 private:
79  double _timer_inc;
80  double _inc;
81  double _dir;
82  int _num_leds;
83  bool _toggle;
84  std::vector<size_t> _led_indices;
85 };
86 
87 #endif
color
Definition: colorUtils.h:24
TurnIndicatorMode::_dir
double _dir
Definition: turnIndicatorMode.h:81
mode.h
TurnIndicatorMode::getName
std::string getName()
Definition: turnIndicatorMode.h:76
Mode::_colors
std::vector< color::rgba > _colors
Definition: mode.h:122
TurnIndicatorMode
Definition: turnIndicatorMode.h:22
color::rgba
Definition: colorUtils.h:26
TurnIndicatorMode::TurnIndicatorMode
TurnIndicatorMode(color::rgba color, size_t num_leds, int dir, int priority=0, double freq=0.25, int pulses=0, double timeout=0)
Definition: turnIndicatorMode.h:24
Mode::m_sigColorsReady
boost::signals2::signal< void(std::vector< color::rgba > &colors)> m_sigColorsReady
Definition: mode.h:129
color::rgba::g
float g
Definition: colorUtils.h:30
TurnIndicatorMode::execute
void execute()
Definition: turnIndicatorMode.h:58
Mode::UPDATE_RATE_HZ
static const unsigned int UPDATE_RATE_HZ
Definition: mode.h:126
color::rgba::b
float b
Definition: colorUtils.h:31
TurnIndicatorMode::_toggle
bool _toggle
Definition: turnIndicatorMode.h:83
TurnIndicatorMode::_inc
double _inc
Definition: turnIndicatorMode.h:80
Mode
Definition: mode.h:26
TurnIndicatorMode::_led_indices
std::vector< size_t > _led_indices
Definition: turnIndicatorMode.h:84
color::rgba::r
float r
Definition: colorUtils.h:29
TurnIndicatorMode::_num_leds
int _num_leds
Definition: turnIndicatorMode.h:82
Mode::_color
color::rgba _color
Definition: mode.h:121
color::rgba::a
float a
Definition: colorUtils.h:32
TurnIndicatorMode::_timer_inc
double _timer_inc
Definition: turnIndicatorMode.h:79
Mode::_freq
double _freq
Definition: mode.h:114


cob_light
Author(s): Benjamin Maidel
autogenerated on Wed Nov 8 2023 03:47:37