00001 #include "RandomMotionReceiver.h" 00002 #include <unistd.h> 00003 #include <cstdlib> 00004 00005 RandomMotionReceiver::~RandomMotionReceiver() 00006 { 00007 if (isRunning()) 00008 stop(); 00009 } 00010 00011 void RandomMotionReceiver::stop() 00012 { 00013 setRunning(false); 00014 } 00015 00016 void RandomMotionReceiver::run() 00017 { 00018 setRunning(true); 00019 Vector3d v; 00020 while (isRunning()) { 00021 v[0] += static_cast<double>((rand() % 70) - 35) / 100.0f; 00022 if (v[0] > 3.0) v[0] = 3.0; 00023 if (v[0] < -3.0) v[0] = -3.0; 00024 v[1] += static_cast<double>((rand() % 70) - 35) / 100.0f; 00025 if (v[1] > 3.0) v[1] = 3.0; 00026 if (v[1] < -3.0) v[1] = -3.0; 00027 v[2] += static_cast<double>((rand() % 70) - 35) / 100.0f; 00028 if (v[2] > 3.0) v[2] = 3.0; 00029 if (v[2] < -3.0) v[2] = -3.0; 00030 notify(v); 00031 00032 usleep(20000); 00033 } 00034 }