-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Healthcheck * Update healthcheck.cpp * Timeout * New version of Healthcheck * timeout + formatting * Fix first healthcheck running * Add entrypoint * Delete debug msg * refactor * suggestions
- Loading branch information
1 parent
d638521
commit 8aa41f3
Showing
8 changed files
with
162 additions
and
19 deletions.
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
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,59 @@ | ||
#include "fstream" | ||
#include "rclcpp/rclcpp.hpp" | ||
#include "sensor_msgs/msg/image.hpp" | ||
|
||
using namespace std::chrono_literals; | ||
|
||
#define LOOP_PERIOD 2s | ||
#define MSG_VALID_TIME 5s | ||
|
||
std::chrono::steady_clock::time_point last_msg_time; | ||
|
||
void write_health_status(const std::string &status) { | ||
std::ofstream healthFile("/health_status.txt"); | ||
healthFile << status; | ||
} | ||
|
||
void msg_callback(const sensor_msgs::msg::Image::SharedPtr msg) { | ||
last_msg_time = std::chrono::steady_clock::now(); | ||
} | ||
|
||
void healthy_check() { | ||
std::chrono::steady_clock::time_point current_time = | ||
std::chrono::steady_clock::now(); | ||
std::chrono::duration<double> elapsed_time = current_time - last_msg_time; | ||
bool is_msg_valid = elapsed_time.count() < MSG_VALID_TIME.count(); | ||
|
||
if (is_msg_valid) { | ||
write_health_status("healthy"); | ||
} else { | ||
write_health_status("unhealthy"); | ||
} | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
rclcpp::init(argc, argv); | ||
auto node = rclcpp::Node::make_shared("healthcheck_node"); | ||
char *zed = std::getenv("CAMERA_LAUNCH"); | ||
|
||
if (zed) { | ||
std::string zed_str(zed); | ||
zed_str = zed_str.substr(0, zed_str.find('.')); | ||
std::string topic_name = zed_str + "/zed_node/rgb/image_rect_color"; | ||
|
||
std::cout << topic_name << std::endl; | ||
auto sub = node->create_subscription<sensor_msgs::msg::Image>( | ||
topic_name, rclcpp::SensorDataQoS(), msg_callback); | ||
|
||
while (rclcpp::ok()) { | ||
rclcpp::spin_some(node); | ||
healthy_check(); | ||
std::this_thread::sleep_for(LOOP_PERIOD); | ||
} | ||
} else { | ||
std::cerr << "CAMERA_LAUNCH environment variable not set" << std::endl; | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} |
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,17 @@ | ||
#!/bin/bash | ||
|
||
HEALTHCHECK_FILE="/health_status.txt" | ||
|
||
|
||
# Now check the health status | ||
if [ -f "$HEALTHCHECK_FILE" ]; then | ||
status=$(cat "$HEALTHCHECK_FILE") | ||
if [ "$status" == "healthy" ]; then | ||
exit 0 | ||
else | ||
exit 1 | ||
fi | ||
else | ||
echo "Healthcheck file still not found. There may be an issue with the node." | ||
exit 1 | ||
fi |
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 |
---|---|---|
@@ -1,13 +1,16 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
output=$(husarnet-dds singleshot) || true | ||
if [[ "$HUSARNET_DDS_DEBUG" == "TRUE" ]]; then | ||
echo "$output" | ||
fi | ||
# Run husarnet-dds singleshot and capture the output | ||
output=$(husarnet-dds singleshot || true) | ||
[[ "$HUSARNET_DDS_DEBUG" == "TRUE" ]] && echo "$output" | ||
|
||
# setup ROS2 environment | ||
# Setup ROS environment | ||
source "/opt/ros/$ROS_DISTRO/setup.bash" | ||
test -f "/ros2_ws/install/setup.bash" && source "/ros2_ws/install/setup.bash" | ||
|
||
exec "$@" | ||
# Run healthcheck in the background | ||
ros2 run healthcheck_pkg healthcheck_node & | ||
|
||
# Execute additional commands | ||
exec "$@" |