[Orxonox-commit 6564] r11204 - in code/branches/plehmannFS16: data/gui/scripts src/orxonox/controllers src/orxonox/controllers/scriptTasks

plehmann at orxonox.net plehmann at orxonox.net
Thu May 26 15:54:24 CEST 2016


Author: plehmann
Date: 2016-05-26 15:54:24 +0200 (Thu, 26 May 2016)
New Revision: 11204

Modified:
   code/branches/plehmannFS16/data/gui/scripts/testscript.lua
   code/branches/plehmannFS16/src/orxonox/controllers/ControllerDirector.h
   code/branches/plehmannFS16/src/orxonox/controllers/NewScriptController.cc
   code/branches/plehmannFS16/src/orxonox/controllers/NewScriptController.h
   code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/CMakeLists.txt
   code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/MoveToTask.cc
   code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/MoveToTask.h
Log:
implemented the update function of MoveToTask. but it does not yet work right. it might be more a problem of the controllerDirector than the task.

Modified: code/branches/plehmannFS16/data/gui/scripts/testscript.lua
===================================================================
--- code/branches/plehmannFS16/data/gui/scripts/testscript.lua	2016-05-26 13:38:27 UTC (rev 11203)
+++ code/branches/plehmannFS16/data/gui/scripts/testscript.lua	2016-05-26 13:54:24 UTC (rev 11204)
@@ -22,9 +22,9 @@
 -- If it worked, call its "movetoposition" function
 if ctrl ~= nil then
 
-  ctrl:printDebug()
-  ctrl:debugOut(5)
-  ctrl:stringOut(3, "hello")
+  ctrl:moveTo(1, 0, 0, 100, 200)
+  ctrl:moveTo(20, 0, 0, 100, 200)
+  ctrl:moveTo(40, 0, 100, 0, 200)
   --ctrl:eventScheduler("mal", xl,yl,zl, xl,yl,zl, 10)
   -- ctrl:eventScheduler("ral", xl, yl, zl, 3, 3000, 0, math.pi)
   -- ctrl:eventScheduler("idle", 1)

Modified: code/branches/plehmannFS16/src/orxonox/controllers/ControllerDirector.h
===================================================================
--- code/branches/plehmannFS16/src/orxonox/controllers/ControllerDirector.h	2016-05-26 13:38:27 UTC (rev 11203)
+++ code/branches/plehmannFS16/src/orxonox/controllers/ControllerDirector.h	2016-05-26 13:54:24 UTC (rev 11204)
@@ -26,6 +26,12 @@
  *
  */
 
+/*
+ at todo:
+
+in the take control or preparationToTakeControl functions remove the former controller and store it somewhere so it can be put back later.
+
+*/
 #ifndef _ControllerDirector_H__
 #define _ControllerDirector_H__
 

Modified: code/branches/plehmannFS16/src/orxonox/controllers/NewScriptController.cc
===================================================================
--- code/branches/plehmannFS16/src/orxonox/controllers/NewScriptController.cc	2016-05-26 13:38:27 UTC (rev 11203)
+++ code/branches/plehmannFS16/src/orxonox/controllers/NewScriptController.cc	2016-05-26 13:54:24 UTC (rev 11204)
@@ -45,6 +45,7 @@
 
 #include "scriptTasks/DebugTask.h"
 #include "scriptTasks/stringOutTask.h"
+#include "scriptTasks/MoveToTask.h"
 #include "scriptTasks/Task.h"
 #include "infos/PlayerInfo.h"
 #include "core/CoreIncludes.h"
@@ -101,7 +102,7 @@
         this->entity_->setController(this);
         this->setControllableEntity(this->entity_);
         this->entity_->mouseLook();
-        this->entity_->setVisible(false);
+        this->entity_->setVisible(true);
         
         // TODO take the human Controllers control  dont forget to give it back in the destructor
     }
@@ -116,19 +117,6 @@
         // If this controller has no entity entry, do nothing 
         if( !(this->entity_) ) return;
 
-
-/*
-        if(taskQueue_.front()->getStartTime() <= scTime_)
-        {
-          activeTasks_.push_back(taskQueue_.front());
-          taskQueue_.pop();
-        }
-
-        for(Task* task : activeTasks_)
-        {
-          task->tick(dt);
-        }*/
-
         if(!this->taskList_.empty())
         {
            orxout() << scTime_ << endl;
@@ -241,6 +229,45 @@
 
     }
 
+    void NewScriptController::moveTo(float startTime, float x, float y, float z, float velocity)
+    {
+
+      MoveToTask* task = new MoveToTask(context_);
+
+      Vector3 destination = Vector3(x,y,z);
+
+      task->initialize(startTime, player_, destination, velocity);
+
+      bool inserted = false;
+
+      if(taskList_.empty())
+      {
+        taskList_.push_front(task);
+        inserted = true;
+      }
+
+      else
+      {
+        for (std::list<Task*>::iterator it = taskList_.begin(); it != taskList_.end(); it++) // insert sorted by starttime
+        {
+          orxout() << "stringOutTask" << endl;
+
+          if(task->getStartTime() < (*it)->getStartTime() )
+          {
+            taskList_.insert(it, task);
+            inserted = true;
+            break;
+          }
+        }
+      }
+
+      if (!inserted)
+      {
+        taskList_.push_back(task);
+      }
+
+    }
+
     NewScriptController* NewScriptController::getNewScriptController() 
     {
       /* Output a message that confirms this function was called */

Modified: code/branches/plehmannFS16/src/orxonox/controllers/NewScriptController.h
===================================================================
--- code/branches/plehmannFS16/src/orxonox/controllers/NewScriptController.h	2016-05-26 13:38:27 UTC (rev 11203)
+++ code/branches/plehmannFS16/src/orxonox/controllers/NewScriptController.h	2016-05-26 13:54:24 UTC (rev 11204)
@@ -24,6 +24,8 @@
  *   Co-authors:
  *      ...
  *
+ *
+ *
  */
 
 #ifndef _NewScriptController_H__
@@ -31,6 +33,7 @@
 
 #include "scriptTasks/DebugTask.h"
 #include "scriptTasks/stringOutTask.h"
+#include "scriptTasks/MoveToTask.h"
 #include "scriptTasks/Task.h"
 #include "OrxonoxPrereqs.h"                 /* die ganzen tolua, kopiert aus Dock.h*/
 #include "ArtificialController.h"
@@ -41,8 +44,28 @@
 namespace orxonox  // tolua_export
 {  // tolua_export
 
+    /**
+    @brief
 
+    A scriptController to carry out tasks on an entity.
+    The tasks are provided as a lua script.
+    The commands which are exported to lua have to create the specified task, initialze it and add it to the TaskList.
 
+    Important add the export comment after functions that need to be accessed from the lua script.
+
+    @todo
+
+    take away the human controller and put it back into place when this controller is deleted.
+    This is probably better done in the controller director class.
+
+    remove the startTimes of the tasks so that the lua script is just carried out one task after the other.
+    to avoid problems when to tasks are carried out simultainiously.
+
+    also the velocity while the controller is taking control is kept and hinders the tasks.
+
+    the moveToTask does not work right.
+    */
+
     class _OrxonoxExport NewScriptController // tolua_export 
        : public ArtificialController, public Tickable
     {  // tolua_export
@@ -61,6 +84,8 @@
 
             void stringOut(float startTime, std::string output);// tolua_export
 
+            void moveTo(float startTime, float x, float y, float z, float velocity);// tolua_export
+
             static NewScriptController* getNewScriptController();// tolua_export 
 
             int getID() { return ctrlid_; }// tolua_export 

Modified: code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/CMakeLists.txt
===================================================================
--- code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/CMakeLists.txt	2016-05-26 13:38:27 UTC (rev 11203)
+++ code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/CMakeLists.txt	2016-05-26 13:54:24 UTC (rev 11204)
@@ -2,4 +2,5 @@
   Task.cc
   DebugTask.cc
   stringOutTask.cc
+  MoveToTask.cc
 )
\ No newline at end of file

Modified: code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/MoveToTask.cc
===================================================================
--- code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/MoveToTask.cc	2016-05-26 13:38:27 UTC (rev 11203)
+++ code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/MoveToTask.cc	2016-05-26 13:54:24 UTC (rev 11204)
@@ -22,7 +22,7 @@
  *   Author:
  *      Paul Lehmann
  *   Co-authors:
- *      ...
+ *      ..
  *
  */
 
@@ -44,26 +44,37 @@
 
     void MoveToTask::initialize(float startTime, PlayerInfo* player, Vector3 destination, float velocity)
     {
-        this->starTime_ = startTime;
+        this->startTime_ = startTime;
         this->player_ = player;
         this->entity_ = this->player_->getControllableEntity();
         this->destination_ = destination;
         this->velocity_ = velocity;
-        this->entity->setVelocity( Vector3(0,0,0) )
+        this->entity_->setVelocity( Vector3(0,0,0) );
+        // unit vector in the direction of travel
+        this->direction_ = (destination - this->entity_->getPosition() )/( (destination - this->entity_->getPosition() ).length() );
+
     }
 
     bool MoveToTask::update(float dt)
     {
 
-        float dl = this->velocity_ * dt;
+        /* Look at the specified position */
+        this->entity_->lookAt(this->destination_);  
 
-        
-        /* Set the position to the correct place in the trajectory */
-        this->entity_->setPosition( (1-dl)*startpos + dl * this->currentEvent.v1);
+        this->entity_->setPosition(this->entity_->getPosition() + velocity_ * dt * direction_);
 
-        /* Look at the specified position */
-        this->entity_->lookAt(this->currentEvent.v2);
+        //this->entity_->setVelocity( Vector3(0,0,0) );
 
+        orxout() << (this->entity_->getPosition() - destination_ ).length() << endl;
+
+        if ((this->entity_->getPosition() - destination_ ).length() > 30)
+        {
+            return true;
+        }
+        else
+        {
+            return false;
+        }
     }
 
 }
\ No newline at end of file

Modified: code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/MoveToTask.h
===================================================================
--- code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/MoveToTask.h	2016-05-26 13:38:27 UTC (rev 11203)
+++ code/branches/plehmannFS16/src/orxonox/controllers/scriptTasks/MoveToTask.h	2016-05-26 13:54:24 UTC (rev 11204)
@@ -42,7 +42,7 @@
             MoveToTask(Context* context);
             virtual ~MoveToTask(){}
 
-            void initialize(float startTime, PlayerInfo* player, vector3 destination);
+            void initialize(float startTime, PlayerInfo* player, Vector3 destination, float velocity);
 
             virtual bool update(float dt) override;
 
@@ -59,8 +59,11 @@
             //   player_->getControllableEntity() 
             ControllableEntity* entity_;
 
-            vector3 destination_;
+            Vector3 direction_;
 
+            Vector3 destination_;
+
+            // velocitz in m/s
             float velocity_;
 
     };




More information about the Orxonox-commit mailing list