Skip to content

Commit 9542f08

Browse files
Run system sumo with snap Webots (cyberbotics#6253)
* Adjust SumoInterface to run externController * Update sumo-interface.md * Update sumo-interface.md * Update projects/default/controllers/sumo_supervisor/sumo_supervisor.py Co-authored-by: Olivier Michel <Olivier.Michel@cyberbotics.com> --------- Co-authored-by: Olivier Michel <Olivier.Michel@cyberbotics.com>
1 parent cdd2794 commit 9542f08

4 files changed

Lines changed: 22 additions & 3 deletions

File tree

docs/automobile/sumo-interface.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ sudo apt install sumo sumo-tools sumo-doc
2121

2222
`SUMO_HOME` environment variable will be automatically set during the installation, but it may be necessary to logout and login, or even reboot, after the installation to correctly run the SUMO Interface.
2323

24+
<br />
25+
26+
Note that if you installed Webots using the snap package, Webots will be unable to launch the SUMO because of the snap sand-boxing.
27+
To work around this problem, the `SumoInterface.exterController` field should be set to TRUE and the controller should be launched as [extern controller](../guide/running-extern-robot-controllers.md) from outside Webots by running these commands:
28+
```sh
29+
export WEBOTS_HOME=/snap/webots/current/usr/share/webots
30+
$WEBOTS_HOME/webots-controller $WEBOTS_HOME/projects/default/controllers/sumo_supervisor/sumo_supervisor.py
31+
```
32+
2433
#### macOS
2534

2635
Using [Homebrew](https://brew.sh), first install [XQuartz](https://www.xquartz.org) for the SUMO interface, that relies on X11, to work:

docs/guide/installation-procedure.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ However, when developing robot controllers, it is often useful to use various co
145145
If such components are needed, users can install them on their system or local environment to create, possibly compile and link their robot controllers.
146146
However, because of the snap sand-boxing, Webots will be unable to launch these controller itself.
147147
To work around this problem, such controllers should be launched as extern controllers from outside of Webots.
148-
Before launching extern controllers, you should set the `WEBOTS_HOME` environment variable to point to `/snap/webots/current/usr/share/webots` and add `$WEBOTS_HOME/lib/controller` to your `LD_LIBRARY_PATH` environment variable, so that your controllers will find the necessary shared libraries.
148+
Before launching extern controllers, you should set the `WEBOTS_HOME` environment variable to point to `/snap/webots/current/usr/share/webots` and run the `$WEBOTS_HOME/webots-controller` launcher.
149149
The chapter entitled [running extern robot controllers](running-extern-robot-controllers.md) details how to run extern controllers, including with the snap version of Webots.
150150

151151
#### Installing the Docker Image

projects/default/controllers/sumo_supervisor/sumo_supervisor.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,15 @@
2828
def sumoImportError():
2929
sys.stderr.write("SUMO not found.\n")
3030
if sys.platform.startswith('linux'):
31-
sys.stderr.write("Please install it with `sudo apt install sumo sumo-tools` and reboot.\n")
31+
if os.getenv('SNAP_NAME'):
32+
sys.stderr.write("Please set the 'SumoInterface.externController' field to TRUE and "
33+
"launch the controller as extern controller.\n"
34+
"Install SUMO ")
35+
else:
36+
sys.stderr.write("Please install it ")
37+
sys.stderr.write("with `sudo apt install sumo sumo-tools` and reboot.\n")
3238
else:
3339
sys.stderr.write("Please install it following the instructions at https://sumo.dlr.de/docs/Installing/.\n")
34-
pass
3540
sys.exit("Or check that the SUMO_HOME environment variable points to the directory of your SUMO installation.")
3641

3742

projects/default/protos/SumoInterface.proto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ PROTO SumoInterface [
2525
field SFNode display NULL
2626
field SFBool verbose FALSE
2727
field SFBool synchronization TRUE
28+
field SFBool externController FALSE
2829
field MFNode children []
2930
hiddenField SFBool enableWheelsRoattion FALSE # deprecated in Webots 2018a.
3031
hiddenField SFInt32 maxVehicules 100 # deprecated in Webots 2018a.
@@ -86,7 +87,11 @@ PROTO SumoInterface [
8687
Robot {
8788
name IS name
8889
model "SUMO interface"
90+
%< if (fields.externController.value) { >%
91+
controller "<extern>"
92+
%< } else { >%
8993
controller "sumo_supervisor"
94+
%< } >%
9095
controllerArgs [
9196
%< for (let i = 0; i < controllerArguments.length; ++i) { >%
9297
%<= '"' + controllerArguments[i] + '"\n' >%

0 commit comments

Comments
 (0)