-
Notifications
You must be signed in to change notification settings - Fork 164
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
JeroenKempen
wants to merge
1
commit into
4am-robotics:noetic-devel
Choose a base branch
from
JeroenKempen:kinetic_dev
base: noetic-devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
{ | ||
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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 adirection
variable set to either left/right that makes the quintessential difference between these modes?