Class LEDSegment

Class Documentation

class LEDSegment

Class that represents virtual LED segment of the robot.

Public Functions

LEDSegment(const YAML::Node &segment_description, const float controller_frequency)

Parses basic parameters of the LED segment.

Parameters:
  • segment_description – YAML description of the segment. Must contain given keys:

    • led_range (string) - two numbers with hyphen in between, eg.: ‘0-45’,

    • channel (int) - id of physical LED channel to which segment is assigned.

  • controller_frequency – frequency at which animation will be updated.

Throws:

std::runtime_error – or std::invalid_argument if missing required description key or key couldn’t be parsed

inline ~LEDSegment()
void SetAnimation(const std::string &type, const YAML::Node &animation_description, const bool repeating, const std::uint8_t priority, const std::string &param = "")

Overwrite current animation.

Parameters:
  • animation_description – YAML description of the animation. Must contain ‘type’ key - pluginlib animation type

  • repeating – if true, will set the default animation for the panel

  • priority – priority of the animation

  • param – optional parameter to pass to animation when initializing

Throws:

std::runtime_error – if ‘type’ key is missing, given pluginlib fails to load or animation fails to initialize

void UpdateAnimation()

Update animation frame.

Throws:

std::runtime_error – if fails to update animation

bool IsAnimationFinished(AnimationPriority layer) const

Check if animation is finished.

Parameters:

layer – layer (priority) of the animation to check

Returns:

True if animation at given layer is finished, false otherwise

std::vector<std::uint8_t> GetAnimationFrame() const

Get current animation frame.

Returns:

Current animation frame or an empty animation frame if animation was not defined or the main animation has finished

float GetAnimationProgress(AnimationPriority layer) const

Get current animation progress.

Throws:

std::runtime_error – if segment animation is not defined

Returns:

Current animation progress

void ResetAnimation(AnimationPriority layer)

Reset current animation.

Throws:

std::runtime_error – if segment animation is not defined

std::size_t GetFirstLEDPosition() const
inline std::size_t GetChannel() const
bool LayerHasAnimation(AnimationPriority layer) const
bool HasAnimation() const

Protected Functions

std::vector<std::uint8_t> MergeLayersFrames() const

Merge all layers animations into one frame.

Returns:

Merged frame

void MergeFrames(std::vector<std::uint8_t> &base_frame, const std::vector<std::uint8_t> &overlay_frame) const

Merge two frames into one using alpha blending.

Parameters:
  • base_frame – frame to merge into

  • overlay_frame – frame to merge on top of original frame