tipping_safety.cpp
Go to the documentation of this file.
00001 #include <carl_safety/tipping_safety.h>
00002 
00003 TippingSafety::TippingSafety()
00004 {
00005   // a private handle for this ROS node (allows retrieval of relative parameters)
00006   ros::NodeHandle private_nh("~");
00007   private_nh.param<bool>("enable_audible_warnings", enableAudibleWarnings, false);
00008 
00009   jointStateSubscriber = node.subscribe("frame_joint_states", 1, &TippingSafety::jointStateCallback, this);
00010   safetyErrorPublisher = node.advertise<carl_safety::Error>("carl_safety/error", 1);
00011 
00012   // ROS services
00013   jacoEStopClient = node.serviceClient<wpi_jaco_msgs::EStop>("jaco_arm/software_estop");
00014   safeNavStopClient = node.serviceClient<std_srvs::Empty>("carl_safety/stop_base_nav");
00015 }
00016 
00017 void TippingSafety::jointStateCallback(const sensor_msgs::JointState::ConstPtr& msg)
00018 {
00019   int pitchIndex = 0;
00020   int rollIndex = 1;
00021   for (unsigned int i = 0; i < msg->name.size(); i ++)
00022   {
00023     if (msg->name[i].compare("base_footprint_base_link_pitch_joint") == 0)
00024     {
00025       pitchIndex = i;
00026     }
00027     else if (msg->name[i].compare("base_footprint_base_link_roll_joint") == 0)
00028     {
00029       rollIndex = i;
00030     }
00031   }
00032 
00033   if (fabs(msg->position[pitchIndex]) > BASE_PITCH_THRESHOLD || fabs(msg->position[rollIndex]) > BASE_ROLL_THRESHOLD)
00034   {
00035     ROS_INFO("Tipping detected, sending stop commands!");
00036     wpi_jaco_msgs::EStop armStopSrv;
00037     armStopSrv.request.enableEStop = true;
00038     std_srvs::Empty baseStopSrv;
00039     if (!jacoEStopClient.call(armStopSrv))
00040     {
00041       ROS_INFO("Could not call jaco estop service.");
00042     }
00043     if (!safeNavStopClient.call(baseStopSrv))
00044     {
00045       ROS_INFO("Could not call safe nav stop service.");
00046     }
00047 
00048     //feedback
00049     carl_safety::Error error;
00050     error.message = "Tipping detected.  Please wait until the robot is re-enabled.";
00051     error.severity = 2;
00052     error.resolved = false;
00053     safetyErrorPublisher.publish(error);
00054 
00055     if (enableAudibleWarnings)
00056     {
00057       system("mpg123 /etc/carl/mario.mp3 >/dev/null 2>&1");
00058     }
00059   }
00060 }
00061 
00062 int main(int argc, char **argv)
00063 {
00064   // initialize ROS and the node
00065   ros::init(argc, argv, "tipping_safety");
00066 
00067   TippingSafety ts;
00068 
00069   ros::spin();
00070 
00071   return EXIT_SUCCESS;
00072 }


carl_safety
Author(s): David Kent , Brian Hetherman
autogenerated on Thu Jun 6 2019 19:03:13