sudo sumo --remote-port 47000 -c map.sumocfg &
#include
<iostream>
#include
<stdlib.h>
#include <string>
#include
"TraCIAPI.h"
class Client :
public TraCIAPI {
public:
Client() {};
~Client() {};
};
int main(int
argc, char* argv[]) {
Client client;
int order = atoi(argv[1]);
client.connect("localhost",
47000);
std::cout << "run 5 steps ...\n";
TraCIAPI::VehicleScope vehicleScope(client);
while(true
) {
client.simulationStep();
libsumo::TraCIPosition pos = vehicleScope.getPosition(std::to_string(order));
std::cout << pos.x << ", " << pos.y
<< std::endl;
}
std::cout << "time in ms: " << client.simulation.getCurrentTime() <<
"\n";
client.close();
}
Here is my client code.
I run sumo like this: sudo
sumo --remote-port 47000 -c map.sumocfg &
Then I run
client program: ./client 1
So the program
should continuously print the position of vehicle with id 1. It is printing for some time, and after some time the program is throwing the following error:
terminate called after throwing an instance of 'tcpip::SocketException'
what(): .. Answered with error to command (164), [description: Vehicle '1' is not known]
Aborted (core dumped)
What might
have caused this error?
Muktadir
You have full control over the simulation duration. As long as the while loop is executed, your simulation continues. Jakob just wrote it as some sample code to adapt to your purpose. Could be something like:
runSim = True
steps = 0
while runSim:
traci.simulationStep()
steps += 1
# stop criterion - can be any other condition
runSim = steps < 3600
Regards
Mirko
Am 08.09.2018 um 17:56 schrieb Muktadir R Chowdhury (mrchwdhr):
Will the following loop continue to run till the simulation finishes?
while True:
traci.simulationStep()
Muktadir
_______________________________________________
sumo-user mailing list
sumo-user@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/sumo-user