Closed Domsall closed 3 years ago
If I understand you correctly, you need an API to modify the speed computed by the SUMO models in accordance with an external model of how a physical vehicle reacts (engine response etc..). To do so you need "intendedAcceleration" and this should affect the observed vehicle acceleration, speed and position.
The existing commands are not well suited for this:
A new command vehicle.adaptPreviousSpeed(vehID, speed)
could fix this.
Would this solve your problem or did I misunderstand you?
Yes, I think that would actually solve the problem the same way and in a better form. I could get the "Intended Acceleration" in every step from getSpeed or getAcceleration and update the vehicle position and speed according to the Simulink physics before the next time step with the commands moveTo (or moveToXY when using lateral dynamics) and the new adaptPreviousSpeed.
As you pointed out, setSpeed overrides the actual speed calculation of SUMO, which I then can't extract anymore.
My idea for this command went even further: It should not only patch the speed but also reposition the vehicle as if it had driven with that speed in the previous step. While this can now be done with command vehicle.moveTo it's a bit awkward when this puts the vehicle onto a different edge (because you have to figure out which lane it came from / wants to go to)
yes that would be a great enhancement. For now I already do those calculation steps in Simulink with 2 different implementations (with and without lateral dynamics, which means moveToXY or moveTo). So Simulink already knows on which edge/lane the Vehicle is, what its route is, where it wants to go, etc.. As Simulink uses a different stepsize than SUMO, the actual vehicle position is not the one the SUMO Vehicle would have, when driven with that speed the whole previous step (with e.g. Euler). To get it Right, the adaptPreviousSpeed-command would Need to be a combination of setPreviousSpeed and moveTo and I thought it would maybe take a bit of time for such a code extension, so I just posted an easy way, which already works perfectly for me. At every Step I just need to check, if the Vehicle is going to be moved back on its old edge and therefor will loose its route.
Hello again :-)
I am updating my own SUMO-version to the newest one right now. I stumbled across this implementation again and am having problems with the command moveToXY. moveToXY actually overwrites other internal speed calculations, SUMO sees the vehicle as a remote controlled one. But my vehicle would like to receive the speed recommendations from SUMO, not the other way around. When I use the command setPreviousSpeed with moveTo everything works fine.
Is there an option to turn off this behavior and just move the vehicle to the given position?
When I outcomment the Line vNext = processTraCISpeedControl(vSafe, vNext);
, then everything works as intended for me, but that is not a great workaround.
I think it makes sense to set an implicit speed when calling moveToXY and I would not want to change this. However, the function vehicle.getSpeedWithoutTraci should be the solution to your use case. This would permit your loop which continuously reads and adapts the internal model speeds. Unfortunately, the speedwithoutTraCI doesn't correctly interact with implicitSpeedRemote yet but this can be fixed.
Thank you very much for your response and for solving my problem. My use case works perfectly now with your recommended idea to use vehicle.getSpeedWithoutTraci and your code changes. I also added a line of Code in setPreviousSpeed in MSVehicle.h so that not only the speed gets updated to the previous speed, but also the acceleration, because else I get some weird acceleration output (acceleration is calculated via movetoXY and not overwritten later like the speed):
void setPreviousSpeed(double prevspeed) {
myAcceleration = SPEED2ACCEL(MAX2(prevspeed, 0.) - myState.myPreviousSpeed);
myState.mySpeed = MAX2(0., prevspeed);
}
You know best if this creates some other problems or can be changed. As mentioned, my problems seem to be fully solved with these code changes and the different existing TraCI-commands.
added in 09259a35cf7b08652a5f55e83d4fe5de21f39117
Hi, I succeeded to connect SUMO and Matlab. However, I'm trying to establish a connection with SUMO starting from a Simulink model through a Matlab function block. The problem is that TraCI commands are not recognized by the Simulink compiler. The Matlab function contains the following code, but it gives errors:
javaaddpath('traci4matlab.jar') projectPath = [pwd filesep 'map.sumocfg']; system([' sumo-gui' ' -c ' projectPath ' --num-clients' ' 2' ' --remote-port 4001' ' --step-length 0.1' ' --start &']); traci.init();
How can I connect SUMO and Simulink? What commands do I have to use in simulink matlab function ? I will be glad to receive any recommendations to help solving this problem.
You need to look up the TraCi4Matlab commands. Try to start with the example there and directly with Matlab before using Simulink function blocks.
When connecting TraCi4Matlab with SUMO, you will need to start with a set of commands like this:
The TraCi4Matlab-Code has a great documentation, you can always check the files for information / which input is needed.
If you have a specific issue, you can create another thread, because this one was about a specific TraCi-command and is closed.
Thank you for replying sir. I really appreciated
2021년 9월 9일 (목) 오후 5:13, Dominik Salles @.***>님이 작성:
You need to look up the TraCi4Matlab commands. Try to start with the example there and directly with Matlab before using Simulink functions blocks.
When connecting TraCi4Matlab with SUMO, you will need to start with a set of commands like this:
- traci.init(port, numentries, host-ip, label)
- traci.setOrder(numorder)
- traci.switchConnection(label) (because you are using 2 clients, you have to switch between them in every step)
- traci.simulationStep()
- ...
The TraCi4Matlab-Code has a great documentation, you can always check the files for information / which input is needed.
If you have a specific issue, you can create another thread, because this one was about a specific TraCi-command and is closed.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/eclipse/sumo/issues/7190#issuecomment-915864952, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATOUYDVY72WWUO2YG5A7VWDUBBUENANCNFSM4OBKYKBQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
To create a submicroscopic simulation, I have combined a virtual vehicle in Simulink with SUMO via the C++ TraCI-API (or using TraCI4Matlab). Many different TraCI-commands already exist for achieving such tasks: e.g. with getLeader, getNextTLS, getBestLanes, and so on, one can retrieve the variables needed for a CF/LC-model working outside of SUMO. Another way of communicating with SUMO is to work with the CF-models already implemented in SUMO via commands like getfollowSpeed and getStopSpeed. In my opinion, it is a hard task to create own driver models for the submicroscopic simulation with SUMO, which should work similar to the included CF/LC/junction-models.
Back in my SUMO v1.0.1 fork, I added a TraCI-command which lets the Simulink model benefit from the extensive model library of SUMO. Now I would like to know if it makes sence to push this command back to the newest SUMO version in the main branch (or if such tasks "SUMO<->virtual vehicle" are normally handled differently). The command is called get/setFutureSpeed and works similar to get/setSpeed. When using the command setFutureSpeed, the SUMO-vehicle is put into a remote listening mode. In every time step and for every vehicle, SUMO calculates vNext. Instead of now updating the ego-vehicle with vNext, the intended acceleration is sent to the Simulink-vehicle, which tries to reach vNext. As the Simulink-vehicle will never perfectly reach this velocity, the actual achieved speed and position is sent back to SUMO (moveTo, setFutureSpeed). SUMO then calculates the next vNext with the new position and speed. The advantage of this operation mode is that the user can use the different models of SUMO (e. g. ACC, CACC, IDM) and benefit from further development without changing the control concept of the Simulink vehicle. Overriding vNext of SUMO is still possible (e. g. when transitioning between automated and conventional driving or to force a lane change).