4 #include "GVONoncopyable.h"
6 class GVOSpeedMeter : private GVONoncopyable {
8 typedef std::deque<double> Array;
9 struct VelocityLogItem {
18 VelocityLogItem( const uint32_t timeStamp, const double velocity ) :
19 timeStamp( timeStamp ),
24 typedef std::deque<VelocityLogItem> VelocityyArray;
25 typedef std::deque<double> VelocityLog;
26 const uint32_t k_velocityMeasuringDistance = 5000;
29 VelocityyArray m_velocityArray;
30 VelocityLog m_velocityLog;
44 inline void updateVelocity( const double velocity, const uint32_t timeStamp )
46 m_velocityArray.push_back( VelocityLogItem( timeStamp, velocity ) );
48 removeOldItem( timeStamp );
51 m_velocity = fastestVelocity();;
54 double velocity() const
60 inline double calcVelocityPerSecond()
62 double velocity = 0.0;
64 if ( m_velocityArray.size() < 2 ) {
68 //
\88Ú
\93®
\95½
\8bÏ
\92l
69 for ( VelocityyArray::const_iterator it = m_velocityArray.begin(); it != m_velocityArray.end(); ++it ) {
70 velocity += it->velocity;
72 velocity /= m_velocityArray.size();
76 inline void removeOldItem(const uint32_t timeStamp)
78 VelocityyArray::const_iterator removeMark = m_velocityArray.end();
79 for ( VelocityyArray::const_iterator it = m_velocityArray.begin(); it != m_velocityArray.end(); ++it ) {
80 const uint32_t dt = timeStamp - it->timeStamp;
81 if ( dt <= k_velocityMeasuringDistance ) {
86 if ( removeMark != m_velocityArray.end() ) {
87 m_velocityArray.erase( m_velocityArray.begin(), removeMark );
91 inline void updateVelocityLog()
93 m_velocityLog.push_back( calcVelocityPerSecond() );
94 if ( 3 < m_velocityLog.size() ) {
95 m_velocityLog.pop_front();
99 inline double fastestVelocity() const
101 double fastest = 0.0;
103 VelocityLog::const_iterator it = std::max_element( m_velocityLog.begin(), m_velocityLog.end() );
104 if ( it != m_velocityLog.end() ) {