34 namespace joint_trajectory_streamer
37 const std::map<std::string, double> &velocity_limits)
41 ROS_INFO(
"FSRoboRJointTrajectoryStreamer: init");
65 ROS_INFO(
"Receiving joint trajectory message");
73 if (msg->points.empty())
74 ROS_INFO(
"Empty trajectory received, canceling current trajectory");
76 ROS_ERROR(
"Trajectory splicing not yet implemented, stopping current motion.");
84 if (msg->points.empty())
86 ROS_INFO(
"Empty trajectory received while in IDLE state, send abort command anyway.");
94 std::vector<JointTrajPtMessage> new_traj_msgs;
100 const float coefficient = 0.5;
101 for(
auto itr = new_traj_msgs.begin(); itr != new_traj_msgs.end(); ++itr){
103 float vel = itr->point_.getVelocity();
104 float prev_vel = (itr - 1)->point_.getVelocity();
105 ROS_DEBUG(
"prev_vel[%d] => %f, vel[%d] => %f", pos, prev_vel, pos, vel);
106 float new_vel = prev_vel + coefficient*(vel - prev_vel);
107 ROS_DEBUG(
"new_vel[%d] => %f", pos, new_vel);
108 itr->point_.setVelocity(new_vel);
119 ROS_INFO(
"Loading trajectory, setting state to streaming");
122 ROS_INFO(
"Executing trajectory of size: %d", (
int)messages.size());
144 msgs->push_back(msgs->back());
153 int connectRetryCount = 1;
155 ROS_INFO(
"Starting joint trajectory streamer thread");
161 if (connectRetryCount-- > 0)
163 ROS_INFO(
"Connecting to robot motion server");
168 connectRetryCount = 0;
169 else if (connectRetryCount <= 0)
171 ROS_ERROR(
"Timeout connecting to robot controller. Send new motion command to retry.");
190 ROS_INFO(
"Trajectory streaming complete, setting state to IDLE");
197 ROS_INFO(
"First trajectory remove");
204 ROS_DEBUG(
"Robot disconnected. Attempting reconnect...");
205 connectRetryCount = 5;
212 ROS_DEBUG(
"Sending joint trajectory point");
213 if (this->
connection_->sendAndReceiveMsg(msg, reply,
false))
215 ROS_INFO(
"Point[%d of %d] sent to controller",
220 ROS_WARN(
"Failed sent joint point, will try again");
224 ROS_ERROR(
"Joint trajectory streamer: unknown state");
232 ROS_WARN(
"Exiting trajectory streamer thread");
239 ROS_DEBUG(
"Stop command sent, entering idle mode");
255 res.result = exec_result;
259 ROS_ERROR(
"Executing robot program %s failed", req.name.c_str());
~FSRoboRJointTrajectoryStreamer()
bool executeRobotProgramCB(fsrobo_r_msgs::ExecuteRobotProgram::Request &req, fsrobo_r_msgs::ExecuteRobotProgram::Response &res)
SmplMsgConnection * connection_
virtual void jointTrajectoryCB(const trajectory_msgs::JointTrajectoryConstPtr &msg)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
virtual bool trajectory_to_msgs(const trajectory_msgs::JointTrajectoryConstPtr &traj, std::vector< JointTrajPtMessage > *msgs)
virtual bool toRequest(industrial::simple_message::SimpleMessage &msg)
virtual bool init(SmplMsgConnection *connection, const std::vector< std::string > &joint_names, const std::map< std::string, double > &velocity_limits=std::map< std::string, double >())
Class initializer.
bool send_to_robot(const std::vector< JointTrajPtMessage > &messages)
virtual bool init(std::string default_ip="", int default_port=StandardSocketPorts::MOTION)
RobotProgramExecutor robot_program_executor_
bool init(SmplMsgConnection *connection)
virtual void trajectoryStop()
ros::ServiceServer srv_execute_robot_program
bool execute(std::string name, std::string param, bool &result)
Execute robot program on the controller.
ros::Time streaming_start_
std::vector< JointTrajPtMessage > current_traj_
boost::thread * streaming_thread_
virtual bool trajectory_to_msgs(const trajectory_msgs::JointTrajectoryConstPtr &traj, std::vector< JointTrajPtMessage > *msgs)