test-BeoSubIMUFilter.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "BeoSub/BeoSubIMU.H"
00039 #include "Devices/HMR3300.H"
00040 #include "Component/ModelManager.H"
00041 #include <math.h>
00042
00043
00044 float xAccel = 0, yAccel = 0, zAccel = 0;
00045 Angle xVel = 0, yVel = 0, zVel = 0, cHeading = 0, cPitch = 0, cRoll = 0;
00046 Angle hError = 0, pError = 0, rError = 0;
00047 Angle realPitch = 0, realRoll = 0;
00048 float realXAccel = 0, realZAccel = 0;
00049
00050 bool firstTime = true;
00051 pthread_mutex_t outLock;
00052
00053 class TestHMR3300Listener : public HMR3300Listener {
00054 public:
00055
00056 virtual ~TestHMR3300Listener() {};
00057
00058
00059 virtual void newData(const Angle heading, const Angle pitch,
00060 const Angle roll)
00061 {
00062 pthread_mutex_lock(&outLock);
00063 printf("CH: %3.4f CP: %3.4f CR: %3.4f\n", heading.getVal(), pitch.getVal(), roll.getVal());
00064 pthread_mutex_unlock(&outLock);
00065 }
00066 };
00067
00068
00069 #include <cstdio>
00070
00071
00072 class TestBeoSubIMUListener : public BeoSubIMUListener {
00073 public:
00074
00075 virtual ~TestBeoSubIMUListener() {}
00076
00077
00078 virtual void newData(const float xa, const float ya, const float za,
00079 const Angle xv, const Angle yv, const Angle zv)
00080 {
00081 pthread_mutex_lock(&outLock);
00082 printf("XA: %3.4f YA:%3.4f ZA:%3.4f XV:%3.4f XY:%3.4f XZ: %3.4f\n", xa, xa, xa, xv.getVal(), yv.getVal(), zv.getVal());
00083 pthread_mutex_unlock(&outLock);
00084 }
00085 };
00086
00087 int main(const int argc, const char **argv)
00088 {
00089
00090 ModelManager manager("IMU Manager");
00091
00092
00093 nub::soft_ref<BeoSubIMU> imu(new BeoSubIMU(manager));
00094 manager.addSubComponent(imu);
00095
00096 nub::soft_ref<HMR3300> hmr(new HMR3300(manager) );
00097 manager.addSubComponent(hmr);
00098
00099
00100
00101 if (manager.parseCommandLine(argc, argv, "<serdev>", 2, 2) == false)
00102 return(1);
00103
00104
00105 imu->setModelParamVal("IMUSerialPortDevName",
00106 manager.getExtraArg(0), MC_RECURSE);
00107
00108 hmr->setModelParamVal("HMR3300SerialPortDevName",
00109 manager.getExtraArg(1), MC_RECURSE);
00110
00111
00112 rutz::shared_ptr<TestBeoSubIMUListener> lis(new TestBeoSubIMUListener);
00113 rutz::shared_ptr<BeoSubIMUListener> lis2; lis2.dynCastFrom(lis);
00114 imu->setListener(lis2);
00115
00116 rutz::shared_ptr<TestHMR3300Listener> lisn(new TestHMR3300Listener);
00117 rutz::shared_ptr<HMR3300Listener> lisn2; lisn2.dynCastFrom(lisn);
00118 hmr->setListener(lisn2);
00119
00120
00121 pthread_mutex_init(&outLock, NULL);
00122
00123
00124 manager.start();
00125
00126
00127
00128 while (1) sleep(1000);
00129
00130
00131 manager.stop();
00132 return 0;
00133 }
00134
00135
00136
00137
00138
00139