-
Notifications
You must be signed in to change notification settings - Fork 1
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
Heartbeat #57
Open
GLDuval
wants to merge
14
commits into
master
Choose a base branch
from
heartbeat
base: master
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
Heartbeat #57
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
017517d
Create node to receive and handle heartbeats.
myriamlacroix 61427e0
Create node to receive/handle heartbeats.
myriamlacroix 4007c74
Estop on heartbeat timeout.
myriamlacroix 56d8b77
Merge branch 'master' into heartbeat
GLDuval 8a9d233
Fix build, change interval and timeout rate
GLDuval 631c7f9
Merge branch 'master' into heartbeat
GLDuval 218cf77
Add autonomy mode to prevent estop when autonomy is running
GLDuval 64c096f
Advertise service
GLDuval a83fbef
Add navigation fallback logic
GLDuval 6a0eedc
Add navigation heartbeat logic
GLDuval b02ab59
Merge branch 'enrich' into heartbeat
saxtot 937e7a8
Small fix
GLDuval 80f02b7
Merge branch 'heartbeat' of https://github.com/clubcapra/markhor into…
saxtot f298fe5
:sparkles: Fix build
saxtot 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
cmake_minimum_required(VERSION 3.0.2) | ||
project(markhor_heartbeat) | ||
|
||
find_package(catkin REQUIRED COMPONENTS | ||
roscpp | ||
) | ||
|
||
catkin_package( | ||
CATKIN_DEPENDS | ||
roscpp | ||
) | ||
include_directories( | ||
src | ||
${catkin_INCLUDE_DIRS} | ||
) | ||
|
||
add_executable(${PROJECT_NAME}_node src/heartbeat.cpp) | ||
|
||
target_link_libraries(${PROJECT_NAME}_node | ||
${catkin_LIBRARIES} | ||
) | ||
|
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,7 @@ | ||
<launch> | ||
<node pkg="markhor_heartbeat" type="markhor_heartbeat_node" name="markhor_heartbeat_node" ns="/markhor" output="screen"> | ||
<param name="heartbeat_interval" type="int" value="1000" /> | ||
<param name="ui_timeout" type="int" value="45000" /> | ||
<param name="navigation_timeout" type="int" value="5000" /> | ||
</node> | ||
</launch> |
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,62 @@ | ||
<?xml version="1.0"?> | ||
<package format="2"> | ||
<name>markhor_heartbeat</name> | ||
<version>0.0.0</version> | ||
<description>The markhor_heartbeat package</description> | ||
|
||
<!-- One maintainer tag required, multiple allowed, one person per tag --> | ||
<!-- Example: --> | ||
<!-- <maintainer email="jane.doe@example.com">Jane Doe</maintainer> --> | ||
<maintainer email="myriam.lacroix.1@ens.etsmtl.ca">Myriam</maintainer> | ||
|
||
|
||
<!-- One license tag required, multiple allowed, one license per tag --> | ||
<!-- Commonly used license strings: --> | ||
<!-- BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 --> | ||
<license>TODO</license> | ||
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. MIT |
||
|
||
|
||
<!-- Url tags are optional, but multiple are allowed, one per tag --> | ||
<!-- Optional attribute type can be: website, bugtracker, or repository --> | ||
<!-- Example: --> | ||
<!-- <url type="website">http://wiki.ros.org/markhor_heartbeat</url> --> | ||
|
||
|
||
<!-- Author tags are optional, multiple are allowed, one per tag --> | ||
<!-- Authors do not have to be maintainers, but could be --> | ||
<!-- Example: --> | ||
<!-- <author email="jane.doe@example.com">Jane Doe</author> --> | ||
|
||
|
||
<!-- The *depend tags are used to specify dependencies --> | ||
<!-- Dependencies can be catkin packages or system dependencies --> | ||
<!-- Examples: --> | ||
<!-- Use depend as a shortcut for packages that are both build and exec dependencies --> | ||
<!-- <depend>roscpp</depend> --> | ||
<!-- Note that this is equivalent to the following: --> | ||
<!-- <build_depend>roscpp</build_depend> --> | ||
<!-- <exec_depend>roscpp</exec_depend> --> | ||
<!-- Use build_depend for packages you need at compile time: --> | ||
<!-- <build_depend>message_generation</build_depend> --> | ||
<!-- Use build_export_depend for packages you need in order to build against this package: --> | ||
<!-- <build_export_depend>message_generation</build_export_depend> --> | ||
<!-- Use buildtool_depend for build tool packages: --> | ||
<!-- <buildtool_depend>catkin</buildtool_depend> --> | ||
<!-- Use exec_depend for packages you need at runtime: --> | ||
<!-- <exec_depend>message_runtime</exec_depend> --> | ||
<!-- Use test_depend for packages you need only for testing: --> | ||
<!-- <test_depend>gtest</test_depend> --> | ||
<!-- Use doc_depend for packages you need only for building documentation: --> | ||
<!-- <doc_depend>doxygen</doc_depend> --> | ||
<buildtool_depend>catkin</buildtool_depend> | ||
<build_depend>roscpp</build_depend> | ||
<build_export_depend>roscpp</build_export_depend> | ||
<exec_depend>roscpp</exec_depend> | ||
|
||
|
||
<!-- The export tag contains other, unspecified, tags --> | ||
<export> | ||
<!-- Other tools can request additional information be placed here --> | ||
|
||
</export> | ||
</package> |
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,78 @@ | ||
#include <ros/ros.h> | ||
#include <std_srvs/SetBool.h> | ||
#include <std_msgs/String.h> | ||
#include <chrono> | ||
#include <std_srvs/Trigger.h> | ||
#include <map> | ||
|
||
int ui_timeout; | ||
int navigation_timeout; | ||
int heartbeat_interval; | ||
std::map<std::string, std::chrono::_V2::system_clock::time_point> last_heartbeats; | ||
|
||
void heartbeat(const std_msgs::String message) | ||
{ | ||
last_heartbeats.at(message.data) = std::chrono::system_clock::now(); | ||
} | ||
|
||
// Function that returns to known connection points until the heartbeat is back. | ||
bool return_to_last_connection_point() | ||
{ | ||
// Call service | ||
return true; | ||
} | ||
|
||
bool validate_heartbeat(std::chrono::_V2::system_clock::time_point last_heartbeat, int timeout) | ||
{ | ||
std::chrono::_V2::system_clock::time_point now = std::chrono::system_clock::now(); | ||
std::chrono::duration<double, std::milli> since_last_heartbeat = now - last_heartbeat; | ||
if (since_last_heartbeat.count() > timeout) | ||
{ | ||
return false; | ||
} | ||
else | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
void check_heartbeat(const ros::TimerEvent& event) | ||
{ | ||
if (!validate_heartbeat(last_heartbeats.at("navigation"), navigation_timeout) && | ||
!validate_heartbeat(last_heartbeats.at("ui"), ui_timeout)) | ||
{ | ||
bool success = return_to_last_connection_point(); | ||
std_srvs::Trigger service; | ||
if (ros::service::exists("/markhor/estop_disable", true)) | ||
{ | ||
ros::service::call("/markhor/estop_disable", service); | ||
} | ||
} | ||
} | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
ros::init(argc, argv, "markhor_heartbeat_node"); | ||
ros::NodeHandle nh; | ||
|
||
// Get parameters from launch file. | ||
nh.getParam("/markhor/heartbeat/markhor_heartbeat_node/heartbeat_interval", heartbeat_interval); | ||
nh.getParam("/markhor/heartbeat/markhor_heartbeat_node/navigation_timeout", navigation_timeout); | ||
nh.getParam("/markhor/heartbeat/markhor_heartbeat_node/ui_timeout", ui_timeout); | ||
|
||
ROS_INFO("Heartbeat interval is : %d ms", heartbeat_interval); | ||
ROS_INFO("Navigation timeout is : %d ms", navigation_timeout); | ||
ROS_INFO("UI timeout is : %d ms", ui_timeout); | ||
|
||
// Init heartbeats | ||
last_heartbeats.at("navigation") = std::chrono::system_clock::now(); | ||
last_heartbeats.at("ui") = std::chrono::system_clock::now(); | ||
|
||
// Subscribe to heartbeat topic to receive heartbeats from web ui. | ||
ros::Subscriber heartbeat_subscriber = nh.subscribe("heartbeat", 5, heartbeat); | ||
|
||
// Timer for UI heartbeat | ||
ros::Timer timer1 = nh.createTimer(ros::Duration(heartbeat_interval / 1000), check_heartbeat); | ||
|
||
ros::spin(); | ||
} |
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.
use capra@ens.etsmtl.ca instead