INTRODUCTION
Overview
Download and Install
Quick Start
Documentation
Publications

NONFRAMEWORK CODE
Driver Interfaces
Drivers
Libraries
Utilities

FRAMEWORK CODE
Interfaces
Components
Libraries
Utilities

Full Software Listings

DEVELOPER
Tutorials
Examples
Dev Guide
Dashboard

PEOPLE
Contributors
Users

SourceForge.net Logo
Project
Download
Mailing lists

 

         

histogramconsumerImpl.h

00001 /*
00002  * Orca-Robotics Project: Components for robotics 
00003  *               http://orca-robotics.sf.net/
00004  * Copyright (c) 2004-2009 Alex Brooks, Alexei Makarenko, Tobias Kaupp
00005  *
00006  * This copy of Orca is licensed to you under the terms described in
00007  * the LICENSE file included in this distribution.
00008  *
00009  */
00010  
00011 #ifndef HISTOGRAM_CONSUMER_IMPL_H
00012 #define HISTOGRAM_CONSUMER_IMPL_H
00013 
00014 #include <orcaice/timeutils.h>
00015 #include <orcaifaceimpl/consumerImpl.h>
00016 #include <orcaifaceutil/laserscanner2d.h>
00017 #include "histogram.h"
00018 #include "histogram2d.h"
00019 #include <iostream>
00020 
00021 namespace delaymon
00022 {
00023 
00024 // this will work for any interface and data type
00025 template<class ProviderType, class ConsumerType, class ObjectType>
00026 class HistogramConsumerImpl : 
00027         public orcaifaceimpl::ConsumerImpl<ProviderType,ConsumerType,ObjectType>
00028 {
00029 using orcaifaceimpl::ConsumerImpl<ProviderType,ConsumerType,ObjectType>::context_;
00030 public:
00031     // start, end, stride in [ms]
00032     HistogramConsumerImpl( const orcaice::Context &context, int start, int end, int stride, 
00033                         const std::string& fileprefix, int maxCount=-1, int sendWarningMs = 1000 ) :
00034         orcaifaceimpl::ConsumerImpl<ProviderType,ConsumerType,ObjectType>(context),
00035         receiveHistogram_(start,end,stride,fileprefix+"_rec"),
00036         sendHistogram_(start,end,stride,fileprefix+"_send"),
00037         sendRecHistogram_(start,end,stride,fileprefix),
00038         dataCounter_(0),
00039         maxCount_(maxCount),
00040         sendWarningMs_(sendWarningMs)
00041     {
00042     }
00043 
00044     virtual void dataEvent( const ObjectType& data ) 
00045     {
00046         IceUtil::Time recCurTimeStamp = IceUtil::Time::now();
00047         ++dataCounter_;
00048     
00049         // need at least 2 data points (the 1st one is sent by IceStorm on subscription)
00050         if ( dataCounter_<3 ) {
00051             sendPrevTimeStamp_ = orcaice::toIceTime(data->timeStamp);
00052             recPrevTimeStamp_ = recCurTimeStamp;
00053             return;
00054         }
00055     
00056         // Receive histogram
00057         int recDiffMs = (recCurTimeStamp-recPrevTimeStamp_).toMilliSeconds();
00058         receiveHistogram_.addValue( recDiffMs );
00059         recPrevTimeStamp_ = recCurTimeStamp;
00060     
00061         // Send histogram
00062         IceUtil::Time sendCurTimestamp = orcaice::toIceTime(data->timeStamp);
00063         int sendDiffMs = (sendCurTimestamp-sendPrevTimeStamp_).toMilliSeconds();
00064         if (sendDiffMs > sendWarningMs_) {
00065             std::cout << "Time difference of send msg: " << sendDiffMs << "ms. Warning threshhold is " << sendWarningMs_ << "ms." << std::endl;
00066             std::cout << "Timestamp of send msg: " << sendCurTimestamp.toDateTime() << std::endl;
00067         }
00068         sendHistogram_.addValue( sendDiffMs );
00069         sendPrevTimeStamp_ = orcaice::toIceTime(data->timeStamp);
00070 
00071         // 2d histogram
00072         sendRecHistogram_.addValue( sendDiffMs, recDiffMs );
00073         
00074         if ( maxCount_>0 && dataCounter_>maxCount_ )
00075             context_.shutdown();
00076     
00077         if ( (dataCounter_ % 100) == 0 )
00078             std::cout<<"processed "<<dataCounter_<<" messages"<<std::endl;
00079     }
00080 
00081 private:
00082     
00083     Histogram receiveHistogram_;
00084     Histogram sendHistogram_;
00085     Histogram2d sendRecHistogram_;
00086     
00087     IceUtil::Time recPrevTimeStamp_;
00088     IceUtil::Time sendPrevTimeStamp_;
00089     int dataCounter_;
00090     int maxCount_;
00091     int sendWarningMs_;
00092 };
00093 
00094 } // namespace
00095 
00096 #endif
 

Webmaster: Tobias Kaupp (tobasco at users.sourceforge.net)


Generated for Orca Robotics by  doxygen 1.4.5