LocalizationParticle.h
Go to the documentation of this file.00001 #ifndef INCLUDED_LocalizationParticle_h
00002 #define INCLUDED_LocalizationParticle_h
00003
00004 #include "Shared/ParticleFilter.h"
00005 #include "Shared/Measures.h"
00006 #include "Shared/zignor.h"
00007 #include <iostream>
00008 #include <cmath>
00009
00010 template<typename ParticleT> class LocalizationParticleDistributionPolicy;
00011
00012
00013 class LocalizationParticle : public ParticleBase<LocalizationParticle> {
00014 public:
00015 float x;
00016 float y;
00017 AngTwoPi theta;
00018
00019
00020 typedef LocalizationParticleDistributionPolicy<LocalizationParticle> DistributionPolicy;
00021
00022
00023 LocalizationParticle() : ParticleBase<LocalizationParticle>(), x(0), y(0), theta(0) {}
00024
00025
00026 LocalizationParticle(float xp, float yp, AngTwoPi tp) : ParticleBase<LocalizationParticle>(), x(xp), y(yp), theta(tp) {}
00027
00028
00029 float sumSqErr(const LocalizationParticle& lp) const {
00030
00031 float dx=x-lp.x;
00032 float dy=y-lp.y;
00033 float dt=theta-lp.theta;
00034 return dx*dx+dy*dy+dt*dt;
00035 }
00036
00037 };
00038
00039
00040 template<typename ParticleT>
00041 class LocalizationParticleDistributionPolicy : public ParticleFilter<ParticleT>::DistributionPolicy {
00042 public:
00043 typedef ParticleT particle_type;
00044 typedef typename ParticleFilter<ParticleT>::index_t index_t;
00045
00046 float mapMinX;
00047 float mapWidth;
00048 float mapMinY;
00049 float mapHeight;
00050 float positionVariance;
00051 float orientationVariance;
00052
00053
00054 LocalizationParticleDistributionPolicy()
00055 : mapMinX(-1000), mapWidth(2000), mapMinY(-1000), mapHeight(2000),
00056 positionVariance(50), orientationVariance(0.18f)
00057 {}
00058
00059 virtual void randomize(particle_type* begin, index_t num) {
00060 particle_type* end=&begin[num];
00061 while(begin!=end) {
00062 begin->x = float(rand())/RAND_MAX * mapWidth + mapMinX;
00063 begin->y = float(rand())/RAND_MAX * mapHeight + mapMinY;
00064 begin->theta = direction_t(rand())/RAND_MAX * 2 * direction_t(M_PI);
00065
00066 ++begin;
00067 }
00068 }
00069 virtual void jiggle(float var, particle_type* begin, index_t num) {
00070 if(var==0)
00071 return;
00072 particle_type* end=&begin[num];
00073 while(begin!=end) {
00074 begin->x+=(float)DRanNormalZig32()*positionVariance*var;
00075 begin->y+=(float)DRanNormalZig32()*positionVariance*var;
00076 begin->theta+=(float)DRanNormalZig32()*orientationVariance*var;
00077
00078 ++begin;
00079 }
00080 }
00081 };
00082
00083
00084 inline std::ostream& operator << (std::ostream& os, const LocalizationParticle &p) {
00085 os << "Particle(p=" << p.weight
00086 << ", dx=" << p.x
00087 << ", dy=" << p.y
00088 << ", th=" << p.theta
00089 << ")";
00090 return os;
00091 }
00092
00093
00094
00095
00096
00097
00098
00099
00100 #endif