Hi,

I'm new to sumo and I'm able to run a TraCI c++ to insert a vehicle into the 
simulation.


But when I try to use the commands


void moveTo();
void moveToXY();

to control the vehicle using real time inputs, it does not behave as I want it 
to.


I saw one post regarding the same topic but there was no clear solution there.


There was something mentioned about C++ hacking. I'm not sure what that means.


It would be really helpful if someone can suggest me a solution.


Thanks & Regards

Sriram


PS: I'm attaching the TraCI C++ client file I'm using
#include <iostream>
#include <utils/traci/TraCIAPI.h>

#include <boost/thread.hpp>
#include <unistd.h>
#include <stdlib.h>
#include <ncurses.h>
#include<math.h>

class Client : public TraCIAPI 

{
private:

    bool stop;
    bool flag;
    int i;
    
    std::string strv;
    std::string strr;
    std::string stre;
    
    std::vector<std::string> l;
    
    SUMOReal speed;
    int key;
    double temp;
    
    TraCIAPI::TraCIPosition p;
    SUMOReal angle;
    double da;
    double x;
    double y;
    
public:

    void loopsim () 
    
    {       
    std::string& rID = this->strr;
    std::string& vID = this->strv;
    std::string& eID = this->stre;


    std::vector<std::string> l;
    this->speed = 0;
   // this->temp = this->speed;
    
    this->connect("localhost", 1337);
    std::cout << "time in ms: " << this->simulation.getCurrentTime() << "\n";
    std::cout << "run 5 steps ...\n";

        
    //l = client.vehicle.getIDList(); // Vehicle ID list 
    //for (std::vector<std::string>::const_iterator s = l.begin(); s != l.end(); ++s)
    //std::cout << *s << ' ';
    
    for (this->i=0;this->i<10000;this->i++)
    {
      this->simulationStep(i * 1000);
      
      if(this->i==1)
        {
        this->vehicle.add(vID ,rID); 
        this->vehicle.setSpeed(vID, 0);
        this->angle = this->vehicle.getAngle(vID); 
        }
      if (i>1)
      {
      
      
      this->p = this->vehicle.getPosition(vID);
      std::cout<< this->x << "\n";  
           
       /* if(this->speed != 0 && this->speed > 0)
          {         
          this->vehicle.setSpeed(vID, this->speed); 
          }    
      */
        if(flag)    
          {
          this->x = this->speed * cos(da);
          this->y = this->speed * sin(da);
         // this->angle = this->angle + this->da;
          this->vehicle.moveToXY(vID, eID, 0, (this->p.x+this->x) , (this->p.y+this->y), (this->da+90) , 1);
          flag = false;
          }
          
          
       // this->speed= this->speed - 0.25;  
      }   
    }
    std::cout << "time in ms: " << this->simulation.getCurrentTime() << "\n";
    this->close();
    stop = true;
    };
       
    void contsim () 
    {    
    
    initscr();
    crmode();
    keypad(stdscr, TRUE);

    this->key = getch();
    while(!this->stop)
      { 
      //this->x=0; this->da=0;
      switch(this->key)
	      {
	      case KEY_RIGHT: this->da= this->da - 10; flag = true; break;
	      case KEY_LEFT:  this->da = this->da + 10; flag = true; break;
	      case KEY_UP:  this->speed = this->speed+ 0.1; flag = true; break;
	      case KEY_DOWN:  this->speed = this->speed - 0.1;  flag = true; break;
	      }	
	      if (this->speed < 0)
	      this->speed = 0;
	      this->key = getch();	
      }
    endwin(); 
    exit(EXIT_SUCCESS);   
    };
    
    Client()  
    {    
    this->flag = false;
    this->stop = false;
    this->strv = "veh1";
    this->strr = "route0";
    this->stre = "1to2";
    this->y = 0;
    this->x = 0;
    this->speed = 0;
    this->da = 0; 
    int key;    
    };
    ~Client() {};
};

int main(int argc, char* argv[]) 
{
    Client client;
    boost::thread th1(&Client::loopsim,&client);
    boost::thread th2(&Client::contsim,&client);
    th1.join();
    th2.join();   
}
 
------------------------------------------------------------------------------
_______________________________________________
sumo-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sumo-user

Reply via email to