Skip to content
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

Use system tool to ping connection of a sick scanner #109

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/sick_safetyscanners/SickSafetyscannersRos.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ class SickSafetyscannersRos

bool getFieldData(sick_safetyscanners::FieldData::Request& req,
sick_safetyscanners::FieldData::Response& res);
std::function<void(void)> watchdog();
void run(const int duration);
};

} // namespace sick
Expand Down
29 changes: 29 additions & 0 deletions src/SickSafetyscannersRos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ SickSafetyscannersRos::SickSafetyscannersRos()
ROS_ERROR("Could not read parameters.");
ros::requestShutdown();
}
run(1000);
// tcp port can not be changed in the sensor configuration, therefore it is hardcoded
m_communication_settings.setSensorTcpPort(2122);
m_laser_scan_publisher = m_nh.advertise<sensor_msgs::LaserScan>("scan", 100);
Expand Down Expand Up @@ -828,6 +829,34 @@ bool SickSafetyscannersRos::getFieldData(sick_safetyscanners::FieldData::Request

return true;
}
std::function<void(void)> SickSafetyscannersRos::watchdog()
{

int sick_1 = system("ping -c1 -s1 192.168.1.11 > /dev/null 2>&1");

if (sick_1 == 0)
{
ROS_INFO("ICMP Connection Alive !");
}
else
{
ROS_ERROR("ICMP Connection Failed, Shutdown the node...");
ros::requestShutdown();
}

}

void SickSafetyscannersRos::run(const int duration)
{
std::thread([this, duration]() {
while (true)
{
watchdog();
auto ms = std::chrono::steady_clock::now() + std::chrono::milliseconds(duration);
std::this_thread::sleep_until(ms);
}
}).detach();
}


} // namespace sick