Browse Source

complete tool/tool_scheduler for task scheduler.

yuchuli 4 years ago
parent
commit
7eaa8bdb1e

+ 1 - 0
src/include/proto/scheduler.proto

@@ -14,6 +14,7 @@ message scheduler_unit
 message scheduler
 {
 	repeated scheduler_unit mscheduler_unit = 1;
+	required int32 mcyble = 2;
 };
 
 

+ 1 - 1
src/tool/adciv_replay/mainwindow.cpp

@@ -162,7 +162,7 @@ void MainWindow::onTimerReplay()
     QDateTime dtx = QDateTime::currentDateTime();
 
     qint64 timediff = mdtrpstart.msecsTo(dtx);
-    qDebug("diff is %d",timediff);
+ //   qDebug("diff is %d",timediff);
 
     bool bR= true;
 

+ 3 - 0
src/tool/tool_scheduler/Readme.md

@@ -0,0 +1,3 @@
+1.本工程用于调度。
+2.设置调度的方法有两种,一种时接收scheduler.proto格式的消息,另外一种是从界面里选取xml文件。
+3.调度是单元是一系列的经纬度和停留时间,参考本工程的xml文件。

+ 38 - 5
src/tool/tool_scheduler/ivscheduler.cpp

@@ -2,6 +2,9 @@
 
 #include <iostream>
 
+
+static ivscheduler * givs;
+
 static QMutex gMutexGPSIMU;
 
 static iv::gps::gpsimu ggpsimu;
@@ -26,7 +29,7 @@ void Listengpsimu(const char * strdata,const unsigned int nSize,const unsigned i
     iv::gps::gpsimu xgpsimu;
     if(!xgpsimu.ParseFromArray(strdata,nSize))
     {
-        std::cout<<"ListenRaw Parse error."<<std::endl;
+        std::cout<<"Listengpsimu Parse error."<<std::endl;
         return;
     }
     (void)&index;
@@ -39,10 +42,32 @@ void Listengpsimu(const char * strdata,const unsigned int nSize,const unsigned i
     gMutexGPSIMU.unlock();
 }
 
-ivscheduler::ivscheduler(std::string strmemname)
+void Listenscheduler(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
+{
+//        ggpsimu->UpdateGPSIMU(strdata,nSize);
+
+    iv::scheduler pscheduler;
+    if(!pscheduler.ParseFromArray(strdata,nSize))
+    {
+        std::cout<<"Listenscheduler Parse error."<<std::endl;
+        return;
+    }
+
+    (void)&index;
+    (void)dt;
+    (void)strmemname;
+
+    givs->setscheduler(&pscheduler);
+
+}
+
+ivscheduler::ivscheduler(std::string strmemname,std::string strschedulername)
 {
+    givs = this;
     mstrmemname = strmemname;
+    mstrschedulername = strschedulername;
     iv::modulecomm::RegisterRecv(mstrmemname.data(),Listengpsimu);
+    iv::modulecomm::RegisterRecv(mstrschedulername.data(),Listenscheduler);
     mpadst = iv::modulecomm::RegisterSend("xodrreq",1000,1);
 }
 
@@ -80,12 +105,14 @@ void ivscheduler::run()
                         mnLastSendObj = QDateTime::currentMSecsSinceEpoch();
                         SendObj(mfLonObj,mfLatObj);
                         mnstep = 1;
+                        emit updatestep(mnstep);
                     }
                         break;
                     case 1:
                         if(IsVehicleMoving(&xgpsimu))
                         {
                             mnstep = 2;
+                            emit updatestep(mnstep);
                         }
                         else
                         {
@@ -100,6 +127,7 @@ void ivscheduler::run()
                         {
                             mnArrivingTime = QDateTime::currentMSecsSinceEpoch();
                             mnstep = 3;
+                            emit updatestep(mnstep);
                         }
                         //Decide Vechicle Running.
                         break;
@@ -108,6 +136,7 @@ void ivscheduler::run()
                         {
                             mnArrivingTime = QDateTime::currentMSecsSinceEpoch();
                             mnstep = 3;
+                            emit updatestep(mnstep);
                         }
                         //Decide Vehiclde Arrive End Point;
                         break;
@@ -117,12 +146,14 @@ void ivscheduler::run()
                         if((QDateTime::currentMSecsSinceEpoch() - mnArrivingTime)>= (pscheduler_unit->mstopsecond()*1000) )
                         {
                             mnstep = 4;
+                            emit updatestep(mnstep);
                         }
                     }
                         //Count Stop Time;
                         break;
                     case 4:
                         mnstep = 0;
+                        emit updatestep(mnstep);
                         mnprocess++;
                         break;
                     default:
@@ -147,11 +178,13 @@ void ivscheduler::run()
     }
 }
 
-void ivscheduler::setscheduler(iv::scheduler *pscheduler, int ncyclecount)
+void ivscheduler::setscheduler(iv::scheduler *pscheduler)
 {
     mMutex.lock();
-    mpscheduler = pscheduler;
-    mncyclecount = ncyclecount;
+    if(mpscheduler != 0)delete mpscheduler;
+    mpscheduler = new iv::scheduler;
+    mpscheduler->CopyFrom(*pscheduler);
+    mncyclecount = pscheduler->mcyble();
     mncycle = 0;
     mnprocess = 0;
     mnstep = 0;

+ 4 - 2
src/tool/tool_scheduler/ivscheduler.h

@@ -15,11 +15,11 @@ class ivscheduler : public QThread
 {
         Q_OBJECT
 public:
-    ivscheduler(std::string strmemname);
+    ivscheduler(std::string strmemname = "hcp2_gpsimu",std::string strschedulername = "scheduler");
 
 
 public:
-    void setscheduler(iv::scheduler * pscheduler,int ncyclecount = 1);
+    void setscheduler(iv::scheduler * pscheduler);
     void run();
 
     void GetProcess(int & nProc, int & nProcTotal);
@@ -28,6 +28,7 @@ public:
 signals:
     void updategps(double flon,double flat,double fheading);
     void updatestate(int ncycle,int ncyclecount,int nprocess,int nprocesscount);
+    void updatestep(int nstep);
 
 
 private:
@@ -53,6 +54,7 @@ private:
     QMutex mMutex;
 
     std::string mstrmemname;
+    std::string mstrschedulername;
     void * mpadst;
 
 private:

+ 21 - 0
src/tool/tool_scheduler/main.cpp

@@ -2,9 +2,30 @@
 
 #include <QApplication>
 
+#include "xmlparam.h"
+
+std::string gstrgpsmsg;
+std::string gstrschmsg;
+
 int main(int argc, char *argv[])
 {
     QApplication a(argc, argv);
+
+    std::string strparapath;
+    if(argc<2)
+    {
+
+        strparapath = "./tool_scheduler.xml";
+    }
+    else
+    {
+
+        strparapath = argv[2];
+    }
+
+    iv::xmlparam::Xmlparam xp(strparapath);
+    gstrgpsmsg = xp.GetParam("gpsmsg","hcp2_gpsimu");
+    gstrschmsg = xp.GetParam("schmsg","scheduler");
     MainWindow w;
     w.show();
     return a.exec();

+ 34 - 1
src/tool/tool_scheduler/mainwindow.cpp

@@ -4,17 +4,23 @@
 #include <QFileDialog>
 #include <QMessageBox>
 
+extern std::string gstrgpsmsg;
+extern std::string gstrschmsg;
+
 MainWindow::MainWindow(QWidget *parent)
     : QMainWindow(parent)
     , ui(new Ui::MainWindow)
 {
     ui->setupUi(this);
 
-    mpivsch = new ivscheduler("hcp2_gpsimu");
+    mpivsch = new ivscheduler(gstrgpsmsg,gstrschmsg);
     mpivsch->start();
 
     connect(mpivsch,SIGNAL(updategps(double,double,double)),this,SLOT(onUpdatePos(double,double,double)));
     connect(mpivsch,SIGNAL(updatestate(int,int,int,int)),this,SLOT(onUpdateState(int,int,int,int)));
+    connect(mpivsch,SIGNAL(updatestep(int)),this,SLOT(onUpdateStep(int)));
+
+    setWindowTitle("Scheduler");
 }
 
 MainWindow::~MainWindow()
@@ -32,6 +38,9 @@ void MainWindow::on_pushButton_Start_clicked()
     }
 
 
+    int ncycle = ui->lineEdit_Cycle->text().toInt();
+    if(ncycle<1)ncycle = 1;
+    mpscheduler->set_mcyble(ncycle);
     mpivsch->setscheduler(mpscheduler);
 }
 
@@ -143,3 +152,27 @@ void MainWindow::onUpdateState(int ncycle, int ncyclecount, int nprocess, int np
     snprintf(strout,100,"%d/%d",nprocess,nprocesscount);
     ui->lineEdit_Process->setText(strout);
 }
+
+void MainWindow::onUpdateStep(int nstep)
+{
+    switch(nstep)
+    {
+    case 0:
+        ui->lineEdit_Step->setText("Init...");
+        break;
+    case 1:
+        ui->lineEdit_Step->setText("Decide Vehcile Moving...");
+        break;
+    case 2:
+        ui->lineEdit_Step->setText("Go to Destination...");
+        break;
+    case 3:
+        ui->lineEdit_Step->setText("Arrived. Stoping...");
+        break;
+    case 4:
+        ui->lineEdit_Step->setText("Complete...");
+        break;
+    }
+
+
+}

+ 1 - 0
src/tool/tool_scheduler/mainwindow.h

@@ -27,6 +27,7 @@ private slots:
 
     void onUpdatePos(double flon,double flat,double fheading);
     void onUpdateState(int ncycle,int ncyclecount,int nprocess,int nprocesscount);
+    void onUpdateStep(int nstep);
 
 private:
     Ui::MainWindow *ui;

+ 23 - 0
src/tool/tool_scheduler/mainwindow.ui

@@ -188,6 +188,29 @@
      <string>Process</string>
     </property>
    </widget>
+   <widget class="QLineEdit" name="lineEdit_Step">
+    <property name="geometry">
+     <rect>
+      <x>240</x>
+      <y>504</y>
+      <width>401</width>
+      <height>25</height>
+     </rect>
+    </property>
+   </widget>
+   <widget class="QLabel" name="label_7">
+    <property name="geometry">
+     <rect>
+      <x>110</x>
+      <y>508</y>
+      <width>67</width>
+      <height>17</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>Step</string>
+    </property>
+   </widget>
   </widget>
   <widget class="QMenuBar" name="menubar">
    <property name="geometry">

+ 93 - 0
src/ui/ui_osgviewer/viewer.cpp

@@ -1047,6 +1047,99 @@ void Viewer::SetCameraMode(int mode)
 	rubberbandManipulator_->setMode(camMode_);
 }
 
+EntityModel* Viewer::AddRadarModel(osg::Vec3 trail_color,std::string name)
+{
+
+    osg::ref_ptr<osg::Group> group = 0;
+
+        osg::ref_ptr<osg::Geode> geode = new osg::Geode;
+        geode->addDrawable(new osg::ShapeDrawable(new osg::Box()));
+
+        osg::ref_ptr<osg::Group> bbGroup = new osg::Group;
+        osg::ref_ptr<osg::PositionAttitudeTransform> tx = new osg::PositionAttitudeTransform;
+
+        osg::Material* material = new osg::Material();
+
+        // Set color of vehicle based on its index
+        double* color;
+        double b = 1.5;  // brighness
+        color = color_blue;
+
+        material->setDiffuse(osg::Material::FRONT, osg::Vec4(b * color[0], b * color[1], b * color[2], 1.0));
+        material->setAmbient(osg::Material::FRONT, osg::Vec4(b * color[0], b * color[1], b * color[2], 1.0));
+
+        if (group == 0)
+        {
+            // If no model loaded, make a shaded copy of bounding box as model
+            osg::ref_ptr<osg::Geode> geodeCopy = dynamic_cast<osg::Geode*>(geode->clone(osg::CopyOp::DEEP_COPY_ALL));
+            group = new osg::Group;
+            tx->addChild(geodeCopy);
+            geodeCopy->setNodeMask(NodeMask::NODE_MASK_ENTITY_MODEL);
+        }
+
+        // Set dimensions of the entity "box"
+
+            // Scale to something car-ish
+            tx->setScale(osg::Vec3(4.5, 1.8, 1.5));
+            tx->setPosition(osg::Vec3(1.5, 0, 0.75));
+
+        tx->addChild(geode);
+        tx->getOrCreateStateSet()->setAttribute(material);
+        bbGroup->setName("BoundingBox");
+        bbGroup->addChild(tx);
+
+//		group->addChild(bbGroup);
+//		group->setName(name);
+
+    EntityModel* model;
+//	if (type == EntityModel::EntityType::ENTITY_TYPE_VEHICLE)
+//	{
+//		model = new CarModel(osgViewer_, group, rootnode_, trails_, dot_node_, trail_color, name);
+//	}
+//	else
+//	{
+        model = new EntityModel(osgViewer_, group, rootnode_, trails_, dot_node_, trail_color, name);
+//	}
+
+    model->state_set_ = model->lod_->getOrCreateStateSet(); // Creating material
+    model->blend_color_ = new osg::BlendColor(osg::Vec4(1, 1, 1, 1));
+    model->state_set_->setAttributeAndModes(model->blend_color_);
+    model->blend_color_->setDataVariance(osg::Object::DYNAMIC);
+
+    osg::BlendFunc* bf = new osg::BlendFunc(osg::BlendFunc::CONSTANT_ALPHA, osg::BlendFunc::ONE_MINUS_CONSTANT_ALPHA);
+    model->state_set_->setAttributeAndModes(bf);
+    model->state_set_->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);
+    model->state_set_->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
+
+    entities_.push_back(model);
+
+//	// Focus on first added car
+//	if (entities_.size() == 1)
+//	{
+//		currentCarInFocus_ = 0;
+//		rubberbandManipulator_->setTrackNode(entities_.back()->txNode_,
+//			rubberbandManipulator_->getMode() == osgGA::RubberbandManipulator::CAMERA_MODE::RB_MODE_TOP ? false : true);
+//		nodeTrackerManipulator_->setTrackNode(entities_.back()->txNode_);
+//	}
+
+//	if (type == EntityModel::EntityType::ENTITY_TYPE_VEHICLE)
+//	{
+//		CarModel* vehicle = (CarModel*)entities_.back();
+//		CreateRoadSensors(vehicle);
+
+//		if (road_sensor)
+//		{
+//			vehicle->road_sensor_->Show();
+//		}
+//		else
+//		{
+//			vehicle->road_sensor_->Hide();
+//		}
+//	}
+
+    return entities_.back();
+}
+
 EntityModel* Viewer::AddEntityModel(std::string modelFilepath, osg::Vec3 trail_color, EntityModel::EntityType type, 
 	bool road_sensor, std::string name, OSCBoundingBox* boundingBox)
 {

+ 1 - 0
src/ui/ui_osgviewer/viewer.hpp

@@ -317,6 +317,7 @@ namespace viewer
 		int GetEntityInFocus() { return currentCarInFocus_; }
 		EntityModel* AddEntityModel(std::string modelFilepath, osg::Vec3 trail_color, EntityModel::EntityType type, 
 			bool road_sensor, std::string name, OSCBoundingBox *boundingBox);
+                EntityModel* AddRadarModel(osg::Vec3 trail_color,std::string name);
 		void RemoveCar(std::string name);
 		int LoadShadowfile(std::string vehicleModelFilename);
 		int AddEnvironment(const char* filename);