Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cob_light] added new modes #411

Open
wants to merge 1 commit into
base: noetic-devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cob_light/common/include/distApproxMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ class DistApproxMode : public Mode
sectors.assign(_num_leds, 0.0);

//calculate sector values
for(int i = 0; i < _num_leds; i++)
for(unsigned int i = 0; i < _num_leds; i++)
{
float sum = std::numeric_limits<float>::max();
//float sum = 0;
for(int j = i*(int)sector_size; j < (i+1)*(int)sector_size; j++)
for(unsigned int j = i*(int)sector_size; j < (i+1)*(int)sector_size; j++)
{
if(ranges.at(j) != 0){
sum = std::min(ranges.at(j), sum);
Expand All @@ -80,7 +80,7 @@ class DistApproxMode : public Mode
sectors.at(i) = sum;
}

for(int i = 0; i < _num_leds; i++)
for(unsigned int i = 0; i < _num_leds; i++)
{
color::rgba col;

Expand Down
2 changes: 1 addition & 1 deletion cob_light/common/include/sequenceMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class SequenceMode : public Mode

private:
std::vector<seq_t> _seqences;
int _seqidx;
unsigned int _seqidx;
bool _init;
float _int_inc;
float _int_count;
Expand Down
2 changes: 2 additions & 0 deletions cob_light/common/include/serialIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class SerialIO
void start();
void stop();

const std::string& getDeviceString() const;

private:
//ioQueue
ConcurrentQueue<std::vector<struct ioData> > _oQueue;
Expand Down
70 changes: 70 additions & 0 deletions cob_light/common/include/signalLeftMode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#ifndef SIGNAL_LEFT_H
#define SIGNAL_LEFT_H

#include <vector>

#include "mode.h"

class SignalLeft : public Mode
{
public:
SignalLeft(color::rgba color, uint16_t nLeds, uint8_t priority = 0, double freq = 0.25, uint8_t pulses = 0,
double timeout = 0)
: Mode(priority, freq, pulses, timeout), _num_leds(nLeds), _toggle(false), _timer_inc(0), leds_margin(5), leds_margin_left(7)
{
_color = color;
if (_pulses != 0)
{
_pulses *= 2;
_pulses += 1;
}
_inc = (1. / UPDATE_RATE_HZ) * _freq;
}

virtual void execute()
{
std::vector<color::rgba> cols;
color::rgba turnedOff;
turnedOff.a = 0;

for (uint16_t i = 0; i < (_num_leds / 2) + leds_margin; ++i)
{
cols.push_back(turnedOff);
}
for (uint16_t i = (_num_leds / 2) + leds_margin; i < _num_leds - leds_margin_left; ++i)
{
cols.push_back(_color);
}

if (_timer_inc >= 1.0)
{
for(color::rgba& color : cols)
{
color.a = color.a * (int)_toggle;
}
_pulsed++;
_toggle = !_toggle;
m_sigColorsReady(cols);
_timer_inc = 0.0;
}
else
{
_timer_inc += _inc;
}
}

std::string getName()
{
return std::string("SignalLeft");
}

private:
uint16_t _num_leds;
bool _toggle;
double _timer_inc;
double _inc;
uint8_t leds_margin;
uint8_t leds_margin_left;
};

#endif // !SIGNAL_LEFT_H
75 changes: 75 additions & 0 deletions cob_light/common/include/signalRightMode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#ifndef SIGNAL_RIGHT_H
#define SIGNAL_RIGHT_H

#include <vector>

#include "mode.h"

class SignalRight : public Mode
{
public:
SignalRight(color::rgba color, uint16_t nLeds, uint8_t priority = 0, double freq = 0.25, uint8_t pulses = 0,
double timeout = 0)
: Mode(priority, freq, pulses, timeout), _num_leds(nLeds), _toggle(false), _timer_inc(0), leds_margin(5)
{
_color = color;
if (_pulses != 0)
{
_pulses *= 2;
_pulses += 1;
}
_inc = (1. / UPDATE_RATE_HZ) * _freq;
}

virtual void execute()
{
std::vector<color::rgba> cols;
color::rgba turnedOff;
turnedOff.a = 0;

cols.push_back(turnedOff);
cols.push_back(turnedOff);
cols.push_back(turnedOff);
cols.push_back(turnedOff);
cols.push_back(turnedOff);

for (uint16_t i = leds_margin; i < (_num_leds / 2) - leds_margin; ++i)
{
cols.push_back(_color);
}
for (uint16_t i = (_num_leds / 2) - leds_margin; i < _num_leds; ++i)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the only difference between the left and right modes, correct?
Is there really no way to have these both derive from a common class (eg. DirectionIndicatorMode or something better) and have a direction variable set to either left/right that makes the quintessential difference between these modes?

{
cols.push_back(turnedOff);
}

if (_timer_inc >= 1.0)
{
for (color::rgba& color : cols)
{
color.a = color.a * (int)_toggle;
}
_pulsed++;
_toggle = !_toggle;
m_sigColorsReady(cols);
_timer_inc = 0.0;
}
else
{
_timer_inc += _inc;
}
}

std::string getName()
{
return std::string("SignalRIght");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small typo.

}

private:
uint16_t _num_leds;
bool _toggle;
double _timer_inc;
double _inc;
uint8_t leds_margin;
};

#endif // !SIGNAL_RIGHT_H
4 changes: 2 additions & 2 deletions cob_light/common/include/sweepColorMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class SweepColorMode : public Mode
{
if(_timer_inc >= 1.0)
{
for(int i = _num_leds/2; i < _num_leds; i++)
for(unsigned int i = _num_leds/2; i < _num_leds; i++)
{
_colors[i].a *= 0.7;
}
Expand Down Expand Up @@ -82,7 +82,7 @@ class SweepColorMode : public Mode
double _timer_inc;
double _inc;
size_t _num_leds;
int _pos;
unsigned int _pos;
color::rgba _startcolor;
};

Expand Down
6 changes: 3 additions & 3 deletions cob_light/common/include/xmasMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ class XMasMode : public Mode
if(_num_leds >= _chucksize*2)
{
int n_chunks = _num_leds / _chucksize + (_num_leds%_chucksize ? 1 : 0);
int k = 0;
unsigned int k = 0;
for(int i = 0; i < n_chunks; i++)
{
for(int j = 0; j < _chucksize; j++)
for(unsigned int j = 0; j < _chucksize; j++)
{
if(k >= _num_leds)
break;
Expand All @@ -52,7 +52,7 @@ class XMasMode : public Mode
}
else
{
for(int i = 0; i < _num_leds; i++)
for(unsigned int i = 0; i < _num_leds; i++)
{
if(i%2==0)
{
Expand Down
Loading