Go to the documentation of this file.00001 #include <carl_estop/carl_estop_node.h>
00002
00003 carl_estop::carl_estop()
00004 {
00005
00006 last_receive = ros::Time::now();
00007
00008
00009 ros::NodeHandle private_nh("~");
00010 private_nh.param<double>("stop_time_delay", stop_time_delay, 1.5);
00011 private_nh.param<double>("check_frequency", check_frequency, 3.0);
00012
00013 spoke = false;
00014
00015
00016 estop_sub = node.subscribe("carl_estop", 1000, &carl_estop::update_time, this);
00017
00018
00019 rmp_pub = node.advertise<rmp_msgs::RMPCommand>("rmp_command", 10);
00020
00021
00022 actionClient = new ActionClient("move_base", true);
00023 last_receive = ros::Time::now();
00024 }
00025
00026 void carl_estop::estop(void)
00027 {
00028 ros::Time current_time = ros::Time::now();
00029
00030
00031 if ((current_time.toSec() - last_receive.toSec()) > stop_time_delay)
00032 {
00033 if (!spoke)
00034 {
00035 spoke = true;
00036 ROS_ERROR("Stopping! Estop Connection Lost.");
00037 system("espeak \"Stopping! Estop Connection Lost.\"");
00038 }
00039
00040 actionClient->waitForServer();
00041 actionClient->cancelAllGoals();
00042 rmp.cmd_id = rmp_msgs::RMPCommand::RMP_CFG_CMD_ID;
00043 rmp.arg1 = rmp_msgs::RMPCommand::RMP_CMD_SET_OPERATIONAL_MODE;
00044 rmp.arg2 = rmp_msgs::RMPCommand::STANDBY_REQUEST;
00045 rmp_pub.publish(rmp);
00046 }
00047 else
00048 {
00049 if (spoke)
00050 {
00051 ROS_INFO("Estop Connection Resumed.");
00052 system("espeak \"Estop Connection Resumed.\"");
00053 spoke = false;
00054 rmp.cmd_id = rmp_msgs::RMPCommand::RMP_CFG_CMD_ID;
00055 rmp.arg1 = rmp_msgs::RMPCommand::RMP_CMD_SET_OPERATIONAL_MODE;
00056 rmp.arg2 = rmp_msgs::RMPCommand::TRACTOR_REQUEST;
00057 rmp_pub.publish(rmp);
00058 }
00059 }
00060 }
00061
00062 void carl_estop::update_time(const std_msgs::Empty::ConstPtr& msg)
00063 {
00064
00065 last_receive = ros::Time::now();
00066 }
00067
00068 double carl_estop::get_frequency()
00069 {
00070 return check_frequency;
00071 }
00072
00073 int main(int argc, char **argv)
00074 {
00075
00076 ros::init(argc, argv, "carl_estop");
00077
00078
00079 carl_estop carl;
00080
00081
00082 ros::Rate loop_rate(carl.get_frequency());
00083 while (ros::ok())
00084 {
00085 ros::spinOnce();
00086 carl.estop();
00087 loop_rate.sleep();
00088 }
00089
00090 return EXIT_SUCCESS;
00091 }