AbstractGraphNode.cpp
Go to the documentation of this file.
00001 /*
00002  * AbstractGraphNode.cpp
00003  *
00004  *  Created on: Nov 12, 2011
00005  *      Author: mriedel
00006  */
00007 
00008 #include "AbstractGraphNode.hpp"
00009 
00010 #include <telekyb_base/ROS.hpp>
00011 
00012 // Declare // This is not a loadable Plugin
00013 //PLUGINLIB_DECLARE_CLASS(tk_formation, AbstractGraphNode, telekyb_behavior::AbstractGraphNode, TELEKYB_NAMESPACE::Behavior);
00014 
00015 namespace telekyb_behavior {
00016 
00017 AbstractGraphNode::AbstractGraphNode(const std::string& name_, const BehaviorType& type_)
00018         : Behavior(name_, type_), nodeID(-1)
00019 {
00020         // get Nodehandle
00021         nodeHandle = ROSModule::Instance().getMainNodeHandle();
00022 
00023         // Create Publishers
00024         vpPublisher = nodeHandle.advertise<geometry_msgs::PointStamped>(VP_TOPIC, 1);
00025         initDonePublisher = nodeHandle.advertise<std_msgs::Bool>(INITDONE_TOPIC, 1);
00026         formationConditionDonePublisher = nodeHandle.advertise<std_msgs::Bool>(CONDITIONDONE_TOPIC, 1);
00027 
00028         Option<int>* tRobotID = OptionContainer::getGlobalOptionByName<int>("TeleKybCore","tRobotID");
00029         if (!tRobotID) {
00030                 ROS_ERROR("Unable to get Option TeleKybCore/tRobotID. Cannot use GraphBehaviors without a valid id!");
00031         } else {
00032                 nodeID = tRobotID->getValue();
00033         }
00034 }
00035 
00036 AbstractGraphNode::~AbstractGraphNode()
00037 {
00038 
00039 }
00040 
00041 void AbstractGraphNode::publishVP(const Eigen::Vector3d& virtualPoint) const
00042 {
00043         geometry_msgs::PointStamped vpMsg;
00044         vpMsg.header.stamp = ros::Time::now();
00045         vpMsg.point.x = virtualPoint(0);
00046         vpMsg.point.y = virtualPoint(1);
00047         vpMsg.point.z = virtualPoint(2);
00048         vpPublisher.publish(vpMsg);
00049 }
00050 
00051 void AbstractGraphNode::publishInitDone(bool initDone_) const
00052 {
00053         std_msgs::Bool initDoneMsg;
00054         initDoneMsg.data = initDone_;
00055         initDonePublisher.publish(initDoneMsg);
00056 }
00057 
00058 void AbstractGraphNode::publishConditionDone(bool conditionDone_) const
00059 {
00060         std_msgs::Bool initDoneMsg;
00061         initDoneMsg.data = conditionDone_;
00062         formationConditionDonePublisher.publish(initDoneMsg);
00063 }
00064 
00065 
00066 void AbstractGraphNode::addNeighbor(int robotID)
00067 {
00068         if (neighbors.count(robotID)) {
00069                 ROS_WARN("Trying to add a robotID that was already added!");
00070                 return;
00071         }
00072 
00073         neighbors[robotID] = new Neighbor(robotID);
00074 }
00075 
00076 void AbstractGraphNode::removeNeighbor(int robotID)
00077 {
00078         if (neighbors.count(robotID)) {
00079                 delete neighbors[robotID];
00080                 neighbors.erase(robotID);
00081         }
00082 }
00083 
00084 bool AbstractGraphNode::allNeighborsValid() const
00085 {
00086         bool retValue = true;
00087         std::map<int, Neighbor*>::const_iterator c_it;
00088         for (c_it = neighbors.begin(); c_it != neighbors.end(); c_it++) {
00089                 if (c_it->second->getElapsedMessageTime().toDSec() > 0.04) { // 25hz
00090                         retValue = false;
00091                         ROS_ERROR("Robot %d, Neighbor %d: Elapsed: %f", nodeID, c_it->first, c_it->second->getElapsedMessageTime().toDSec());
00092                 }
00093         }
00094 
00095         return retValue;
00096 }
00097 
00098 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines


tk_formation
Author(s): Martin Riedel
autogenerated on Mon Nov 11 2013 11:14:18