utilities.cpp
Go to the documentation of this file.
00001 
00004 /*****************************************************************************
00005 ** Includes
00006 *****************************************************************************/
00007 
00008 #include "../../include/cost_map_demos/utilities.hpp"
00009 
00010 /*****************************************************************************
00011 ** Namespaces
00012 *****************************************************************************/
00013 
00014 namespace cost_map_demos {
00015 
00016 /*****************************************************************************
00017 ** Implementation
00018 *****************************************************************************/
00019 
00020 void pretty_print(costmap_2d::Costmap2DROS &ros_costmap) {
00021   for ( unsigned int i = 0; i < ros_costmap.getCostmap()->getSizeInCellsX(); ++i ) {
00022     for ( unsigned int j = 0; j < ros_costmap.getCostmap()->getSizeInCellsY(); ++j ) {
00023       std::cout << static_cast<int>(ros_costmap.getCostmap()->getCost(i,j)) << " ";
00024     }
00025     std::cout << std::endl;
00026   }
00027 }
00028 
00029 std::ostream& operator <<(std::ostream& stream, costmap_2d::Costmap2DROS& ros_costmap) {
00030   for ( unsigned int i = 0; i < ros_costmap.getCostmap()->getSizeInCellsX(); ++i ) {
00031     for ( unsigned int j = 0; j < ros_costmap.getCostmap()->getSizeInCellsY(); ++j ) {
00032       stream << static_cast<int>(ros_costmap.getCostmap()->getCost(i,j)) << " ";
00033     }
00034     stream << std::endl;
00035   }
00036   return stream;
00037 }
00038 
00039 /*****************************************************************************
00040 ** TransformBroadcaster
00041 *****************************************************************************/
00042 
00043 TransformBroadcaster::~TransformBroadcaster() {
00044   broadcasting_thread.join();
00045 }
00046 
00047 void TransformBroadcaster::shutdown() {
00048   shutdown_flag = true;
00049 }
00050 
00051 void TransformBroadcaster::add(const std::string& name, tf::Vector3 origin, const tf::Quaternion& orientation) {
00052   tf::Transform transform;
00053   transform.setOrigin(origin);
00054   transform.setRotation(orientation);
00055   transforms.insert(std::pair<std::string, tf::Transform>(name, transform));
00056 }
00057 
00058 void TransformBroadcaster::startBroadCastingThread() {
00059   broadcasting_thread = std::thread(&TransformBroadcaster::broadcast, this);
00060 }
00061 
00062 void TransformBroadcaster::broadcast() {
00063   tf::TransformBroadcaster tf_broadcaster;
00064   while(ros::ok() && !shutdown_flag )
00065   {
00066     for (std::pair<std::string, tf::Transform> p: transforms) {
00067       tf::StampedTransform stamped_transform(p.second, ros::Time::now(), "map", p.first);
00068       tf_broadcaster.sendTransform(stamped_transform);
00069     }
00070     ros::Duration(0.1).sleep();
00071   }
00072 }
00073 
00074 /*****************************************************************************
00075  ** Trailers
00076  *****************************************************************************/
00077 
00078 } // namespace cost_map_demos


cost_map_demos
Author(s): Daniel Stonier
autogenerated on Thu Jun 6 2019 20:28:06