Go to the documentation of this file.00001 #include <robodyn_controllers/JointTrajectoryManager.h>
00002 #include "nasa_common_logging/Logger.h"
00003
00008 JointTrajectoryManager::JointTrajectoryManager()
00009 {
00010
00011 }
00012
00013 JointTrajectoryManager::~JointTrajectoryManager()
00014 {
00015
00016 }
00017
00024 void JointTrajectoryManager::addToJointGoalMap(const std::vector<std::string>& jointNames, const actionlib_msgs::GoalID goalId)
00025 {
00026
00027
00028
00029
00030 for (std::vector<std::string>::const_iterator nameIt = jointNames.begin();
00031 nameIt != jointNames.end(); ++nameIt)
00032 {
00033 jointGoalMap.insert(std::make_pair(*nameIt, goalId));
00034 }
00035 }
00036
00043 void JointTrajectoryManager::removeFromJointGoalMap(const std::vector<std::string>& jointNames)
00044 {
00045 for (std::vector<std::string>::const_iterator nameIt = jointNames.begin(); nameIt != jointNames.end(); ++nameIt)
00046 {
00047
00048 std::map<std::string, actionlib_msgs::GoalID>::iterator goalIt = jointGoalMap.find(*nameIt);
00049
00050 if (goalIt != jointGoalMap.end())
00051 {
00052 if (isActive(goalIt->second))
00053 {
00054
00055 std::stringstream err;
00056 err << "JointTrajectoryManager::removeFromJointGoalMap() - trying to remove an active goal";
00057 NasaCommonLogging::Logger::log("gov.nasa.controllers.JointTrajectoryManager", log4cpp::Priority::ERROR, err.str());
00058 throw std::runtime_error(err.str());
00059 return;
00060 }
00061 else
00062 {
00063 jointGoalMap.erase(goalIt);
00064 }
00065 }
00066 }
00067 }
00068
00075 void JointTrajectoryManager::removeFromJointGoalMap(const actionlib_msgs::GoalID& goal)
00076 {
00077 if (isActive(goal))
00078 {
00079
00080 std::stringstream err;
00081 err << "JointTrajectoryManager::removeFromJointGoalMap() - trying to remove an active goal";
00082 NasaCommonLogging::Logger::log("gov.nasa.controllers.JointTrajectoryManager", log4cpp::Priority::ERROR, err.str());
00083 throw std::runtime_error(err.str());
00084 return;
00085 }
00086 else
00087 {
00088 for (std::map<std::string, actionlib_msgs::GoalID>::iterator it = jointGoalMap.begin(); it != jointGoalMap.end();)
00089 {
00090 if (it->second.id == goal.id && it->second.stamp == goal.stamp)
00091 {
00092 jointGoalMap.erase(it++);
00093 }
00094 else
00095 {
00096 ++it;
00097 }
00098 }
00099 }
00100 }
00101
00102
00108 std::string JointTrajectoryManager::jointGoalMapToString(void) const
00109 {
00110 std::stringstream msg;
00111 std::map<std::string, actionlib_msgs::GoalID>::const_iterator jointGoalIt;
00112 msg << std::endl << "jointGoalMap" << std::endl;
00113 msg << "------------" << std::endl;
00114
00115 for (jointGoalIt = jointGoalMap.begin(); jointGoalIt != jointGoalMap.end(); ++jointGoalIt)
00116 {
00117 msg << jointGoalIt->first << ": " << jointGoalIt->second.stamp << ", " << jointGoalIt->second.id << std::endl;
00118 }
00119
00120 return msg.str();
00121 }