20 #include <std_srvs/Trigger.h> 21 #include <geometry_msgs/Twist.h> 22 #include <controller_manager_msgs/SwitchController.h> 37 controller_manager_msgs::SwitchController switch_srv;
39 switch_srv.request.strictness = 1;
42 if (g_switch_client.
call(switch_srv))
44 if (switch_srv.response.ok)
46 ROS_INFO(
"Successfully switched controllers");
50 ROS_ERROR(
"Could not switch controllers");
55 ROS_ERROR(
"ServiceCall failed: switch_controller");
61 std_srvs::Trigger srv;
63 g_recover_client.
call(srv);
88 ROS_DEBUG(
"Robot is moving, restarting halt timer");
95 std_srvs::Trigger srv;
96 ROS_INFO_STREAM(
"Halt, no movement commands received for " << g_timeout <<
" seconds");
97 g_halt_client.
call(srv);
100 int main(
int argc,
char* argv[])
102 ros::init(argc, argv,
"cob_stop_detector");
108 if(!nh_priv.
getParam(
"timeout", timeout) || timeout <= 0.0){
109 ROS_ERROR(
"Please provide valid timeout");
114 ROS_ERROR(
"Please provide stop threshold");
123 g_halt_client = nh.
serviceClient<std_srvs::Trigger>(
"driver/halt");
124 g_recover_client = nh.
serviceClient<std_srvs::Trigger>(
"driver/recover");
125 g_switch_client = nh.
serviceClient<controller_manager_msgs::SwitchController>(
"controller_manager/switch_controller");
127 g_recover_client.waitForExistence();
128 g_switch_client.waitForExistence();
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
int main(int argc, char *argv[])
void haltCallback(const ros::TimerEvent &)
ros::Timer g_silence_timer
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void commandsCallback(const geometry_msgs::Twist::ConstPtr &msg)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool call(MReq &req, MRes &res)
ros::ServiceClient g_switch_client
bool waitForExistence(ros::Duration timeout=ros::Duration(-1))
bool getParam(const std::string &key, std::string &s) const
std::vector< std::string > g_controller_spawn
#define ROS_INFO_STREAM(args)
ros::ServiceClient g_recover_client
ros::ServiceClient g_halt_client