Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <ros/console.h>
00018 #include <mtconnect_state_machine/utilities.h>
00019 #include <mtconnect_task_parser/task_parser.h>
00020 #include <boost/tuple/tuple.hpp>
00021 #include "boost/make_shared.hpp"
00022
00023 using namespace mtconnect_state_machine;
00024
00025
00026
00027 bool mtconnect_state_machine::parseTaskXml(const std::string & xml,
00028 std::map<std::string, trajectory_msgs::JointTrajectoryPtr> & paths,
00029 std::map<std::string, boost::shared_ptr<mtconnect::JointPoint> > & points)
00030 {
00031 typedef std::map<std::string, boost::shared_ptr<mtconnect::Path> >::iterator PathMapIter;
00032 bool rtn;
00033
00034 mtconnect::Task task;
00035
00036 if (mtconnect::fromXml(task, xml))
00037 {
00038
00039 for (PathMapIter iter = task.paths_.begin(); iter != task.paths_.end(); ++iter)
00040 {
00041 trajectory_msgs::JointTrajectoryPtr jt(new trajectory_msgs::JointTrajectory());
00042
00043 if (toJointTrajectory(iter->second, jt))
00044 {
00045 paths[iter->first] = jt;
00046 ROS_DEBUG_STREAM("Converted path: " << iter->first << " to joint trajectory");
00047 rtn = true;
00048 }
00049 else
00050 {
00051 ROS_ERROR_STREAM("Failed to convert path: " << iter->first << " to joint trajectory");
00052 rtn = false;
00053 break;
00054 }
00055
00056 }
00057 ROS_DEBUG_STREAM("Converted " << task.paths_.size() << " paths to "
00058 << paths.size() << " joint paths");
00059
00060 ROS_DEBUG_STREAM("Copying " << task.points_.size() << " to defined points");
00061 points = task.points_;
00062 }
00063 else
00064 {
00065 ROS_ERROR("Failed to parse task xml string");
00066 rtn = false;
00067 }
00068
00069 return rtn;
00070
00071 }
00072
00073 bool mtconnect_state_machine::toJointTrajectory(boost::shared_ptr<mtconnect::Path> & path,
00074 trajectory_msgs::JointTrajectoryPtr & traj)
00075 {
00076 typedef std::vector<mtconnect::JointMove>::iterator JointMovesIter;
00077
00078
00079
00080 traj->joint_names = path->moves_.front().point_->group_->joint_names_;
00081 traj->points.clear();
00082 for (JointMovesIter iter = path->moves_.begin(); iter != path->moves_.end(); iter++)
00083 {
00084 ROS_DEBUG("Converting point to joint trajectory point");
00085 trajectory_msgs::JointTrajectoryPoint jt_point;
00086 jt_point.positions = iter->point_->values_;
00087 traj->points.push_back(jt_point);
00088 ROS_DEBUG_STREAM("Added point to trajectory, new size: " << traj->points.size());
00089
00090 }
00091 return true;
00092 }
00093
00094
00095
00096