How to disable lane changes in SuMO? - veins

I am using a TraCI call to set the lane change mode of a vehicle to 0 to disable all lane changing:
TraCICommandInterface::setLaneChangeMode(0b000000000000);
However, the vehicle still does a lane change afterwards. I also tried 256 (i.e. 0b000100000000 and 512 (i.e. 0b001000000000) as indicated in the wiki or in this post.
It seems that the executed lane change action was queued earlier (i.e. before the TraCI call), because the vehicle is flashing its turn light, and could not be executed due to a blocked lane. After the target lane is free, the vehicle executes the lane change, even though I set the lane change mode to 0.
Is there a way to abort already queued lane changes?
Or is this a bug in SuMO?
Or am I doing it completely wrong?

it works by setting setLaneChangeMode(0b000000000000)
for example
traci.vehicle.setLaneChangeMode("rear", 0b001000000000)

i have disabled lane change mode by this code and it worked but after i have specified the location where i want lane change mode to be 0.
traciVehicle->setLaneChangeMode(0b001000000000);

Related

Getting notified when an I2C-Value changes in C++

I recently started experimenting with I2C-Hardware on my raspberry pi. Following this tutorial Using the I2C interface I already know how to read and set values. However, the program I want to realize needs the current value on a specific address all the time. So, I made a thread and query the value constantly in a never ending loop, which seems primitive to me. Is it possible to get notified in an event-like manner when a value on an I2C-adress changes?
A platform independend solution would also be much welcomed.
I was able to get what I wanted.
I use the following repeater for the I2C-Bus: link and it turns out there is a soldering bridge (LB2) you can set that sets a signal on GPIO17 whenever a value on the I2C-Bus changes since it has last been changed. I can now listen on this events accordingly.
Generally speaking, the I2C bus has no interrupt capability. So with only I2C, all you can do is poll the chip for a certain event to happen or value to change.
Most chips do have an interrupt line (sometimes even more than one) that can be programmed to trigger on certain events. The behavior of this line depends on the chip. Usually it needs to be enabled (using I2C commands) and it needs to be linked to a GPIO input line. For these, interrupt support is available.

How to change the speed of a road segment after simulation starts?

I want to change the speed of a road section after sometime from the simulation start. For an example, at time step = 50, the speed of a particular road segment should be set to 5 m/s though its original speed has been something else (e.g. 15 m/s) before the specified time step.
Any advice is appreciated.
SUMO's TraCI interface supports both changing the state of individual lanes or changing the state of entire edges. All you need to do is send the required command (0xc3 or 0xca) and the required variable (0x41 in both cases).

Limit a Game Server Thread loop to 30FPS without a game engine/rendering window

I'll try to explain this as easily as I can.
I basically have a game that hosts multiple matches.
All the matches on the server are all processed by the server, no players host a match on their computers via port forwarding, it's all done by the server so they don't have to.
When a player requests to make a match, a match object with a thread is made on the server. This works fine. Each match object has it's own list of players. However, the game client runs at 30FPS and it needs to be in sync with the server, so just updating all the players in the thread loop will not do since it's not run at 30FPS.
What I'm doing right now is I use a game engine: SFML, which in its window loop, goes through all the players in the server and runs their update code at 30FPS.
This is fine however, when there comes a time where they may be a huge chunk of people, it will be better that the players are updated via the match threads so as not to slow down the processing speed by having it all done in one render loop.
What I want to know is, how would I simulate 30FPS in a match's thread loop? Basically have it so each player's update() function is called in the timeframe of 30FPS, without having to use a rendering engine such as SFML to limit how fast the code is to be run? The code is run in the background and output is shown on a console, no rendering is needed on the server.
Or put simply, how do I limit a while loop code to run in 30FPS without a game engine?
This seems a bit like a X Y problem : You try to sync players via server "FPS" limit. Server side doesn't really work like that.
Servers sync with clients in terms of time by passing to the client the server's time on each package or via a specific package (in other words, all clients have only the server's time).
But regarding server side implementations for gaming :
The problem is a bit more broad than what you mentioned. I'll post some guidelines which hopefully will help your research.
First of all, on server you don't require rendering, so FPS is not relevant (30 fps is required in order to give our eyes the sensation of fluidity). Server usually handles logic, like for example various events (for example someone fires a rocket, or a new enemy has spawned). As you can see events don't require FPS, and they are randomly triggered.
Something else that is done on the server is the Physics (or other player-player or player-environment interactions ). Collisions are done using a fixed update step. Physics are usually calculated at 20 FPS for example. Moving objects get capsule colliders in order to properly simulate interaction. In other words, severs ,while not rendering anything, are responsible for movement/collisions (meaning that if you don't have a connection to the server you won't move / go through walls , etc - implementation dependent).
Modern games also have prediction in order to reduce lagging (after all, after you give any input to your character, that input needs to get to the server first, get processed and be received back in order to have any effect on the client). This means that when you have an input on a client (let's take moving for example) , the client starts making the action in anticipation , and when the server response comes (for our example the new position) it will be considered as a correction. That's why sometimes in a game when you have lag you perceive that you are moving in a certain direction then all of a sudden you are somewhere completely different.
Regarding your question :
Inside your while loop, make a deltaT , and if that deltaT is lesser than 33 miliseconds use sleep(33-deltaT) .
As you requested, I'm posting a sample of deltaT Code :
while (gameIsRunning)
{
double time = GetTickCount();
UpdateGame();
double deltaT = GetTickCount()-time;
if (deltaT < 33 )
{
sleep(33- deltaT);
}
}
Where gameIsRunning is a global boolean, and UpdateGame is your game update function.
Please note that the code above works on Windows. For linux, you will require other functions instead of GetTicksCount and sleep.

Multiple functions with same controller

I'm on a project using arduinos.This is my idea:
I have a squared signal that can slightly change. This signal gives me 58 pulses and then 2 empty spaces, indicating the cycle's beginning.
My objective is to generate another signal that changes according to this one.
My idea is to first get a sample of the signal for each X time, to get the number of pulses.After this, I want to read my cycle's start, to be able to know where my signal is every time.Then I'll generate my signal depending on that.
My problem is that I think I'll need a loop for getting my sample, which lasts as long as the pulse of the signal that I want to generate, or probably even longer, and another loop for detecting my start.
Is there any way of doing this with the same chip?Or my function is always gonna get stuck with the sample instead of generating my pulses?
Thanks!
yes it is possible, and there are a lot of way to solve this problem.
I would use a state machine.
In the first state, you are waiting for your "start", so you do a pulseln() on the input pin, if the pulase duration is good you'll increase a variable, if not reset that variable.
After that look at variabile value: if it is 56 you enter the second state.
In the second state you do what you have to do, and eventually fall back to state 1 (waiting a new "start") or enter another state.
As you can see, that approach is good if you have a finite (and relativly small) number of state, like a protocol. You can just use the code from state 1 if you need only to do something after the "start" and go backj to wait "start"

How to stop or pause glutTimerFunc in GLUT?

In my project i'm running a train which stops moving when it reaches a particular point this moving is carried out by glutTimerFunc .I once again want the train to start from the location where i click my mouse to a particular location
BUT THE PROBLEM HERE IS,
My timer still running even after reaching that location,so even when i initialise the starting point its not working(it continues from the left location).
Now i need to stop the timer and start the train timer for the new location.
The API documentation has the following to say:
There is no support for canceling a registered callback. Instead, ignore a callback based on its value parameter when it is triggered.
So, add a boolean to your software and ignore the event whenever it is triggered. It would be better to use a clock-based timer rather than an event-driven timer and do your timed updates manually everytime the main loop runs (you detect the amount of time since the last update, and you determine whether to perform an update tick(s)), in the long run however. This is how physics and various other time-based simulations are handled in most professional software, using the event-driven model sets you up to miss or frequently wind up handling a timed event excessively late.
Welcome to the world of game engines and actors.
My recommendation is that you don't try to do this by turning glutTimerFunc on or off directly. The timer function should be the top level "heartbeat" for the entire program, and it's job is just to tell every object that has behaviour - an "actor" - that it should update itself. The train should have its own internal state that knows where it is and whether it should be moving or not.