Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10448


Ignore:
Timestamp:
May 21, 2015, 2:55:51 PM (10 years ago)
Author:
rgraczyk
Message:

Various changes, see comments in cpp file

Location:
code/branches/SciptableControllerFS15
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/SciptableControllerFS15/data/gui/scripts/testscript.lua

    r10262 r10448  
    2222-- If it worked, call its "movetoposition" function
    2323if ctrl ~= nil then
    24   -- Move to the starting point at (xl+3000,yl,zl) while looking
    25   -- at xl,yl,zl over the time span of 3 seconds
    26   ctrl:eventScheduler("mal", xl+3000,yl,zl, xl,yl,zl, 1, 0)
    2724
    28   -- From there, perform a rotation around the harvester placed there
    29   -- in 100 steps
    30   dt = math.pi/100
    31   for t = 0,math.pi,dt do
    32     xt = math.cos(t)
    33     yt = math.sin(t)
    34 
    35     ctrl:eventScheduler("mal", xl+3000*xt, yl+3000*yt, zl, xl, yl, zl, dt, t+0.9)
    36   end
    37 
    38 
    39   -- Update absolute time
    40   Tabs = math.pi + 0.9
    41 
    42  
    43 
    44   -- Move away again, still looking at the station
    45   ctrl:eventScheduler("mal", 0,0,1000, xl,yl,zl, 3, Tabs+0.4)
    46 
    47 
    48 
    49   -- Update absolute time
    50   Tabs = Tabs + 0.4 + 3
    51 
    52  
    53 
    54  
    55 
    56   -- Transition the look from (xl,yl,zl) to (3500,0,0) in 3 seconds
    57   ctrl:eventScheduler("chl", xl, yl, zl, xr, yr, zr, 2, Tabs+0.2)
    58 
    59   Tabs = Tabs + 2 + 0.2
    60 
    61    ctrl:eventScheduler("mal", xr + 600,yr,zr, xr,yr,zr, 4, Tabs+0)
    62 
    63    Tabs = Tabs + 4
    64 
    65   for t = 0,math.pi,dt do
    66     xt = math.cos(t)
    67     zt = math.sin(t)
    68 
    69     ctrl:eventScheduler("mal", xr+600*xt, yr, zr+600*zt, xr, yr, zr, dt, Tabs+t)
    70   end
    71 
    72   Tabs = Tabs + math.pi
    73 
    74   ctrl:eventScheduler("chl", xr, yr, zr, xl, yl, zl, 3, Tabs+0.2)
    75 
    76   Tabs = Tabs + 3 + 0.2
    77 
    78   ctrl:eventScheduler("mal", xm,ym,zm, xl,yl,zl, 4, Tabs+2.5)
    79 
     25  ctrl:eventScheduler("mal", xl,yl,zl, xl,yl,zl, 2)
     26  ctrl:eventScheduler("idle", 1)
     27  ctrl:eventScheduler("ral", xl, yl, zl, 3, 0, 0, math.pi)
     28  ctrl:eventScheduler("idle", 1)
     29  ctrl:eventScheduler("mal", 0,0,1000, xl,yl,zl, 3)
     30  ctrl:eventScheduler("idle", 1)
     31  ctrl:eventScheduler("chl", xl, yl, zl, xr, yr, zr, 2)
     32  ctrl:eventScheduler("idle", 1)
     33  ctrl:eventScheduler("mal", xr + 600,yr,zr, xr,yr,zr, 4)
     34  ctrl:eventScheduler("idle", 1)
     35  ctrl:eventScheduler("chl", xr, yr, zr, xl, yl, zl, 3)
     36  ctrl:eventScheduler("idle", 1)
     37  ctrl:eventScheduler("spi", xm,ym,zm, 0,0,0, 4)
     38  ctrl:eventScheduler("idle", 600)
    8039
    8140end
    82 
    83 
    8441
    8542-- Output the newctrlid variable we set from the C++ code
     
    8946
    9047--orxonox.execute("setPause 1")
    91 
    92 
  • code/branches/SciptableControllerFS15/src/orxonox/controllers/ScriptController.cc

    r10262 r10448  
    2626 *
    2727 */
     28
     29 /*
     30  * Currently available lua commands:
     31  *
     32  * IMPORTANT: ALL COMMANDS DO REQUIRE 7 PARAMETERS TO BE PROVIDED. FILL UP WITH ZEROES IN UNIMPORTANT PLACES.
     33  *
     34  * Command             | Abbreviation | Parameter 1          | '' 2     | '' 3    | '' 4                 | '' 5     | '' 6     | '' 7
     35  *
     36  * "Move And Look"     | mal          | GoTo X Coordinate    | '' Y ''  | '' Z '' | LookAt X Coordinate  |  '' Y '' |  '' Y '' | Duration
     37  * "Rotate And Look"   | ral          | GoTo X Coordinate    | '' Y ''  | '' Z '' | Axis (1=x, 2=z, 3=z) |     -    |     -    | Duration
     38  * "Spiral"            | spi          | GoTo X Coordinate    | '' Y ''  | '' Z '' |          -           |     -    |     -    | Duration
     39  * "Transition Look"   | chl          | From X Coordinate    | '' Y ''  | '' Z '' | To X Coordinate      |  '' Y '' |  '' Y '' | Duration
     40  * "Idle (Do nothing)" | idle         | Duration
     41  /
     42
     43// TODO: Which library can this be found in?
     44#define M_PI 3.14159265358979323846 /* pi */
    2845
    2946#include "ScriptController.h"
     
    3249#include "worldentities/ControllableEntity.h"
    3350#include "core/LuaState.h"
     51#include "core/LuaState.h"
    3452#include <cmath>
     53
    3554
    3655namespace orxonox
     
    6685        this->eventno = 0;
    6786
     87        /* - First "previous event" scheduled at t=0 */
     88        /* - Needed for automatically updating event times */
     89        this->prevEventTime = 0;
     90
     91        /* hack */
     92        this->deltat;
    6893    }
    6994
     
    146171    void ScriptController::tick(float dt)
    147172    {
     173        /* hack */
     174        this->deltat = dt;
     175
    148176        /* Call the tick function of the classes we derive from */
    149177        SUPER(ScriptController, tick, dt);
     
    178206
    179207        /* Get a variable that specifies how far along the trajectory
    180          * we are
     208         * we are currently.
    181209         */
    182210        float dl = eventTime / currentEvent.duration;
    183211
    184         /* Depending */
     212        /* Depending on command */
    185213        /* Do some moving */
    186214        if( this->processing )
    187         {
    188           if( this->currentEvent.fctName == "mal" )
     215        {
     216          // Abbreviation for "spiral" (rotation + translation)
     217          if (this->currentEvent.fctName == "spi") {
     218
     219            // Need to know a perpendicular basis to the translation vector:
     220            // Given (a, b, c) we chose (b, -a, 0)norm and (0, c, -b)norm
     221            // Currently we set a fix rotational radius of 400
     222            // TODO: Add an option to adjust radius of spiral movement
     223            Vector3 direction = this->currentEvent.v1 - startpos;
     224
     225            Vector3* ortho1 = new Vector3(direction.y, -direction.x, 0);
     226            float absOrtho1 = sqrt(direction.y * direction.y + direction.x * direction.x);
     227            *ortho1 = 400 * cos(2 * M_PI * dl) * (*ortho1)/absOrtho1;
     228
     229            Vector3* ortho2 = new Vector3(0, direction.z, -direction.y);
     230            float absOrtho2 = sqrt(direction.y * direction.y + direction.z * direction.z);
     231            *ortho2 = 400 * sin(2 * M_PI * dl) * (*ortho2)/absOrtho2;
     232
     233            this->entity_->setPosition( (1-dl)*startpos + dl * this->currentEvent.v1 + *ortho1 + *ortho2);
     234
     235            delete ortho1;
     236            delete ortho2;
     237          }
     238
     239          // Abbreviation for "rotate and look"
     240          if (this->currentEvent.fctName == "ral")
     241          {
     242            // Specify the axis
     243            Vector3* a;
     244              switch ((int) currentEvent.d) {
     245                case 3:
     246                  a = new Vector3(this->currentEvent.v1.x + 3000*cos(2*M_PI*dl),
     247                                  this->currentEvent.v1.y + 3000*sin(2*M_PI*dl),
     248                                  this->currentEvent.v1.z);
     249                break;
     250                case 2:
     251                  a = new Vector3(this->currentEvent.v1.x + 3000*cos(2*M_PI*dl),
     252                                  this->currentEvent.v1.y,
     253                                  this->currentEvent.v1.z + 3000*cos(2*M_PI*dl));
     254                break;
     255                case 1:
     256                  a = new Vector3(this->currentEvent.v1.x,
     257                                  this->currentEvent.v1.y + 3000*sin(2*M_PI*dl),
     258                                  this->currentEvent.v1.z + 3000*cos(2*M_PI*dl));
     259                break;
     260              }
     261
     262            this->entity_->setPosition(*a);
     263
     264            /* Look at the specified position */
     265            this->entity_->lookAt(this->currentEvent.v1);
     266          }
     267          else if( this->currentEvent.fctName == "mal" )
    189268          {
    190269            /* Set the position to the correct place in the trajectory */
     
    193272            /* Look at the specified position */
    194273            this->entity_->lookAt(this->currentEvent.v2);
    195 
    196             /* Update look at position */
    197             //this->lookAtPosition = this->currentEvent.v2;
    198274          }
    199275          else if( this->currentEvent.fctName == "chl" )
     
    224300      /* Fill the structure with all the provided information */
    225301      tmp.fctName = instruction;
     302
    226303      //tmp.x1 = x1; tmp.y1 = y1; tmp.z1 = z1;
    227304      //tmp.x2 = x2; tmp.y2 = y2; tmp.z2 = z2;
    228305      tmp.v1 = Vector3(x1,y1,z1);
    229306      tmp.v2 = Vector3(x2,y2,z2);
     307
     308      // the parameters are not required to be vector coordinates!
     309      // for convenience they are however stored twice if they have some kind of different meaning
     310      tmp.a = x1;
     311      tmp.b = y1;
     312      tmp.c = z1;
     313      tmp.d = x2;
     314      tmp.e = y2;
     315      tmp.f = z2;
     316
    230317      tmp.duration = duration;
    231       tmp.eventTime = executionTime;
    232 
    233       orxout(verbose) << tmp.fctName << endl;
     318
     319      /* This is kind of a hack. If we hit the function idle all we want to do is
     320         advance event execution time, not schedule anything */
     321      if (instruction == "idle") {
     322        tmp.eventTime = this->prevEventTime;
     323        this->prevEventTime += x1;
     324        return;
     325      } else {
     326        tmp.eventTime = this->prevEventTime;
     327        this->prevEventTime += duration;
     328      }
    234329
    235330      /* Add the created event to the event list */
  • code/branches/SciptableControllerFS15/src/orxonox/controllers/ScriptController.h

    r10315 r10448  
    5151        Vector3 v2;
    5252
     53        /** The parameters are additionally stored as a set of 6 numerical values **/
     54        float a, b, c, d, e, f;
     55
    5356        /** Time span of the event */
    5457        float duration;
     
    7275            // LUA interface
    7376            // tolua_begin
    74             void eventScheduler(std::string instruction,
    75               float x1, float y1, float z1,
    76               float x2, float y2, float z2,
    77               float duration, float executionTime);
     77            void eventScheduler(std::string instruction = "",
     78              float x1 = 0, float y1 = 0, float z1 = 0,
     79              float x2 = 0, float y2 = 0, float z2 = 0,
     80              float duration = 0, float executionTime = 0);
    7881
    7982            static ScriptController* getScriptController();
     
    119122            Vector3 startpos;
    120123
     124            /* Time of the previously scheduled event */
     125            float prevEventTime;
     126
     127            /* Hack: Gain access to delta t */
     128            float deltat;
     129
    121130            /* - Position to look at during that transition */
    122131            //Vector3 lookAtPosition;
Note: See TracChangeset for help on using the changeset viewer.