Skip to content

Commit

Permalink
Implement tests for lights driver
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelirh committed Sep 5, 2024
1 parent aab6fa3 commit fb71613
Show file tree
Hide file tree
Showing 3 changed files with 261 additions and 165 deletions.
48 changes: 24 additions & 24 deletions panther_lights/include/panther_lights/lights_driver_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,31 +48,11 @@ class LightsDriverNode : public rclcpp::Node
const rclcpp::NodeOptions & options = rclcpp::NodeOptions());

protected:
int num_led_;
double frame_timeout_;
bool led_control_granted_;
bool led_control_pending_;

rclcpp::Time channel_1_ts_;
rclcpp::Time channel_2_ts_;

private:
void OnShutdown();

void InitializationTimerCB();

/**
* @brief Clears all LEDs on both channels.
*/
void ClearLEDs();

/**
* @brief Toggles LED control ON or OFF.
*
* @param enable True to enable LED control, false to disable.
*/
void ToggleLEDControl(const bool enable);

/**
* @brief Callback to execute when service invoked to toggle LED control returns response.
*
Expand All @@ -93,10 +73,6 @@ class LightsDriverNode : public rclcpp::Node
const ImageMsg::UniquePtr & msg, const APA102Interface::SharedPtr & panel,
const rclcpp::Time & last_time, const std::string & panel_name);

void SetBrightnessCB(
const SetLEDBrightnessSrv::Request::SharedPtr & request,
SetLEDBrightnessSrv::Response::SharedPtr response);

/**
* @brief Logs a warning message to the panel throttle log. Since this is throttle warning, we
* need to add panel name condition to log from both panels.
Expand All @@ -107,6 +83,30 @@ class LightsDriverNode : public rclcpp::Node
*/
void PanelThrottleWarnLog(const std::string panel_name, const std::string message);

int num_led_;
double frame_timeout_;
bool led_control_granted_;
bool led_control_pending_;

rclcpp::Time channel_1_ts_;
rclcpp::Time channel_2_ts_;

private:
void OnShutdown();

void InitializationTimerCB();

/**
* @brief Toggles LED control ON or OFF.
*
* @param enable True to enable LED control, false to disable.
*/
void ToggleLEDControl(const bool enable);

void SetBrightnessCB(
const SetLEDBrightnessSrv::Request::SharedPtr & request,
SetLEDBrightnessSrv::Response::SharedPtr response);

void DiagnoseLights(diagnostic_updater::DiagnosticStatusWrapper & status);

static constexpr unsigned kMaxInitializationAttempts = 3;
Expand Down
4 changes: 2 additions & 2 deletions panther_lights/src/lights_driver_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ void LightsDriverNode::ToggleLEDControlCB(
}

void LightsDriverNode::FrameCB(
const ImageMsg::UniquePtr & msg, const APA102::SharedPtr & panel, const rclcpp::Time & last_time,
const std::string & panel_name)
const ImageMsg::UniquePtr & msg, const APA102Interface::SharedPtr & panel,
const rclcpp::Time & last_time, const std::string & panel_name)
{
if (!led_control_granted_) {
PanelThrottleWarnLog(
Expand Down
Loading

0 comments on commit fb71613

Please sign in to comment.