00001
00002
00003
00004
00005
00006
00007
00008 #include "UgvSystem.h"
00009 #include <iostream>
00010 #include <uvsim/utilities/RealtimeThread.h>
00011
00012 namespace uvsim
00013 {
00014
00015 VisionThread::VisionThread(const char * port, float freq, int priority) :
00016 RealtimeThread(priority, freq)
00017 {
00018 std::cout << "\nVision thread initialized." << std::endl;
00019 }
00020
00021 void VisionThread::loop()
00022 {
00023
00024 }
00025
00026 VisionThread::~VisionThread()
00027 {
00028 }
00029
00030 ControlThread::ControlThread(std::string port, float freq, int priority,
00031 bool useJoystick) :
00032 RealtimeThread(priority, freq)
00033 {
00034 m_controlComm = new ControlComm(port, useJoystick);
00035 std::cout << "Control thread initialized." << std::endl;
00036 }
00037
00038 void ControlThread::loop()
00039 {
00040
00041 m_controlComm->update();
00042 }
00043
00044 ControlThread::~ControlThread()
00045 {
00046
00047
00048 }
00049
00050 NavigationThread::NavigationThread(const char * port, float freq, int priority) :
00051 RealtimeThread(priority, freq)
00052 {
00053 vector<double> freqCutMb(3), freqCutFb(3), freqCutWb(3);
00054
00055
00056 freqCutMb(0) = 312;
00057 freqCutMb(1) = 312;
00058 freqCutMb(2) = 312;
00059
00060
00061 freqCutFb(0) = 350;
00062 freqCutFb(1) = 350;
00063 freqCutFb(2) = 150;
00064
00065
00066 freqCutWb(0) = 120;
00067 freqCutWb(1) = 120;
00068 freqCutWb(2) = 120;
00069
00070
00071 imu = new Imu6DofSensor(port, freqCutMb, freqCutFb, freqCutWb);
00072
00073
00074 ins = new Ins(std::string(DATADIR)+="/data/Ins15g.dat",
00075 std::string(DATADIR)+="/data/Gyro.dat",
00076 std::string(DATADIR)+="/data/Mag.dat",
00077 freq,imu);
00078 }
00079
00080 void NavigationThread::loop()
00081 {
00082 std::cout << "\nNavigation thread running." << std::endl;
00083 }
00084
00085 NavigationThread::~NavigationThread()
00086 {
00087 delete imu;
00088 delete ins;
00089 }
00090
00091 UgvSystem::UgvSystem()
00092 {
00093 m_visionThread = NULL;
00094 m_navigationThread = NULL;
00095 m_controlThread = NULL;
00096 }
00097
00098 UgvSystem::UgvSystem(const char * visionPort, float visionFreq,
00099 int visionPriority, const char * controlPort, float controlFreq,
00100 int controlPriority, bool useJoystick, const char * navigationPort,
00101 float navigationFreq, int navigationPriority)
00102 {
00103 m_visionThread = new VisionThread(visionPort, visionFreq, visionPriority);
00104 m_controlThread = new ControlThread(controlPort, controlFreq, controlPriority, useJoystick);
00105 m_navigationThread = new NavigationThread(navigationPort, navigationFreq, navigationPriority);
00106 std::cout << "\nThreads initialized." << std::endl;
00107 }
00108
00109 UgvSystem::~UgvSystem()
00110 {
00111
00112 if (m_controlThread != NULL) m_controlThread->stop();
00113 if (m_navigationThread != NULL) m_navigationThread->stop();
00114 if (m_visionThread != NULL) m_visionThread->stop();
00115
00116
00117 if (m_visionThread != NULL) delete m_visionThread;
00118 if (m_controlThread != NULL) delete m_controlThread;
00119 if (m_navigationThread != NULL) delete m_navigationThread;
00120 }
00121
00122 void UgvSystem::run()
00123 {
00124 std::cout << "\nLaunching threads." << std::endl;
00125 if (m_visionThread != NULL) m_visionThread->start();
00126 if (m_navigationThread != NULL) m_navigationThread->start();
00127 if (m_controlThread != NULL) m_controlThread->start();
00128 }
00129
00130 }