Skip to content

Commit

Permalink
Fixed motor error lighting sequence (#120)
Browse files Browse the repository at this point in the history
* Update motor error lighting sequence if motor_states changes without the lighting state changing
Added lighting emulator script

* Removed light emulator
  • Loading branch information
roni-kreinin authored Jan 16, 2025
1 parent e680bdc commit 04492f0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ struct hsv_t {
s = 0.0;
v = 0.0;
}

bool operator==(hsv_t const& other)
{
return (h == other.h && s == other.s && v == other.v);
}

bool operator!=(hsv_t const& other)
{
return !(*this == other);
}
};

static const hsv_t COLOR_RED = hsv_t(0.0, 100.0, 37.5);
Expand All @@ -85,9 +95,9 @@ class ColorHSV
ColorHSV(hsv_t hsv);
static std::vector<ColorHSV> fade(ColorHSV start, ColorHSV end, uint32_t steps);
clearpath_platform_msgs::msg::RGB getRgbMsg();
double h() { return hsv_.h; };
double s() { return hsv_.s; };
double v() { return hsv_.v; };
double h() const { return hsv_.h; };
double s() const { return hsv_.s; };
double v() const { return hsv_.v; };

void setH(const double h)
{
Expand All @@ -104,6 +114,16 @@ class ColorHSV
hsv_.v = v;
}

bool operator==(const ColorHSV other) const
{
return (h() == other.h() && s() == other.s() && v() == other.v());
}

bool operator!=(const ColorHSV other) const
{
return !(*this == other);
}

private:
hsv_t hsv_;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,29 @@ class Sequence
return s;
}

bool operator==(Sequence const& other)
{
LightingSequence ls, other_ls;

ls = sequence_;
other_ls = other.getSequence();

for (std::size_t i = 0; i < sequence_.size(); i++)
{
if (ls.at(i) != other_ls.at(i))
{
return false;
}
}

return true;
}

bool operator!=(Sequence const& other)
{
return !(sequence_ == other.getSequence());
}

protected:
LightingSequence sequence_;
uint16_t current_state_, num_states_;
Expand Down
2 changes: 1 addition & 1 deletion clearpath_hardware_interfaces/src/lighting/lighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void Lighting::spinOnce()
}

// Change lighting sequence if state has changed
if (old_state_ != state_)
if (old_state_ != state_ || current_sequence_ != lighting_sequence_.at(old_state_))
{
current_sequence_ = lighting_sequence_.at(state_);
current_sequence_.reset();
Expand Down

0 comments on commit 04492f0

Please sign in to comment.