simulation_execution_service.cpp
Go to the documentation of this file.
1 //
2 // Created by yijiangh on 7/12/17.
3 //
4 
6 
7 const static double ACTION_EXTRA_WAIT_RATIO = 2.0; // 20% past end of trajectory
8 const static double ACTION_SERVICE_WAIT_TIME = 30.0; // seconds
9 const static char* const ACTION_CONNECTION_FAILED_MSG = "[FF simulation execution] Could not connect to action server.";
10 
11 // subsribe to the simulation execution action call
12 const static std::string THIS_SERVICE_NAME = "simulation_execution";
13 
14 // joint trajectory action to send out
15 // industrial_robot_simulator in industrial_core packages subsribes to this action and is responsible
16 // to "move" the robot in rviz for simulation
17 const static std::string ACTION_SERVER_NAME = "joint_trajectory_action";
18 
20  : ac_(ACTION_SERVER_NAME, true)
21 {
22  server_ = nh.advertiseService<SimulationExecutionService, choreo_msgs::TrajectoryExecution::Request,
23  choreo_msgs::TrajectoryExecution::Response>(
25 
26  // Attempt to connect to the motion action service
28  {
30  throw std::runtime_error(ACTION_CONNECTION_FAILED_MSG);
31  }
32 }
33 
35  choreo_msgs::TrajectoryExecution::Request& req, choreo_msgs::TrajectoryExecution::Response& res)
36 {
37  // Check preconditions
38  if (!ac_.isServerConnected())
39  {
40  ROS_ERROR_STREAM("[FF Simulation Execution] Simulation Execution Action server is not connected.");
41  return false;
42  }
43 
44  if (req.trajectory.points.empty())
45  {
46  ROS_WARN_STREAM("[FF Simulation Execution] Trajectory Execution Service recieved an empty trajectory.");
47  return true;
48  }
49 
50  // Populate goal and send
51  control_msgs::FollowJointTrajectoryGoal goal;
52  goal.trajectory = req.trajectory;
53  ac_.sendGoal(goal);
54 
55  if (req.wait_for_execution)
56  {
57  ros::Duration extra_wait =
58  goal.trajectory.points.back().time_from_start * ACTION_EXTRA_WAIT_RATIO;
59  if (ac_.waitForResult(goal.trajectory.points.back().time_from_start + extra_wait))
60  {
61  return ac_.getState().state_ == ac_.getState().SUCCEEDED;
62  }
63  else
64  {
65  ROS_ERROR_STREAM(__FUNCTION__ << ": Goal failed or did not complete in time.");
66  return false;
67  }
68  }
69 
70  return true; // if we don't wait, then always return true immediately
71 }
bool waitForServer(const ros::Duration &timeout=ros::Duration(0, 0)) const
bool waitForResult(const ros::Duration &timeout=ros::Duration(0, 0))
static const double ACTION_EXTRA_WAIT_RATIO
static const std::string ACTION_SERVER_NAME
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
static const char *const ACTION_CONNECTION_FAILED_MSG
static const double ACTION_SERVICE_WAIT_TIME
#define ROS_WARN_STREAM(args)
void sendGoal(const Goal &goal, SimpleDoneCallback done_cb=SimpleDoneCallback(), SimpleActiveCallback active_cb=SimpleActiveCallback(), SimpleFeedbackCallback feedback_cb=SimpleFeedbackCallback())
actionlib::SimpleActionClient< control_msgs::FollowJointTrajectoryAction > ac_
SimpleClientGoalState getState() const
#define ROS_ERROR_STREAM(args)
bool executionCallback(choreo_msgs::TrajectoryExecution::Request &req, choreo_msgs::TrajectoryExecution::Response &res)
static const std::string THIS_SERVICE_NAME


choreo_simulation_executor
Author(s):
autogenerated on Thu Jul 18 2019 03:59:21