Skip to content

Commit

Permalink
Fixed exception in environment settings and display issues
Browse files Browse the repository at this point in the history
* Fixed the following issues
- Environment values are stringified to prevent passing floats into XOSC
- Default environments are set when non are detected
- Separate pop up window when warnings are detected during export
- Added file name extension checking when choosing export location

* Updated known issues
  • Loading branch information
seowwj authored May 6, 2021
1 parent 422fb33 commit 80463f4
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 59 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pip3 install --user -r /path/to/requirements.txt
## Known Issues
- Non CARLA maps are not fully supported
- Entity spawn z coordinates need to be manually adjusted
- When map is unloaded and reloaded with AD Map Access, exporting scenarios might not work

## OpenSCENARIO Support List

Expand Down
34 changes: 14 additions & 20 deletions osc_generator/edit_environment_widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@
<height>280</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>360</width>
<height>138</height>
</size>
</property>
<property name="windowTitle">
<string>Edit Environment</string>
</property>
Expand Down Expand Up @@ -45,28 +39,34 @@
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QGroupBox" name="DateTimeGroup">
<property name="minimumSize">
<size>
<width>0</width>
<height>70</height>
</size>
</property>
<property name="title">
<string>Time of Day</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QCheckBox" name="TimeAnimation">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Animation</string>
</property>
</widget>
</item>
<item>
<widget class="QDateTimeEdit" name="TimeofDay">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="dateTime">
<datetime>
<hour>8</hour>
<hour>6</hour>
<minute>0</minute>
<second>0</second>
<year>2020</year>
Expand All @@ -83,7 +83,7 @@
</property>
<property name="time">
<time>
<hour>8</hour>
<hour>6</hour>
<minute>0</minute>
<second>0</second>
</time>
Expand All @@ -101,12 +101,6 @@
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="WeatherGroup">
<property name="minimumSize">
<size>
<width>0</width>
<height>310</height>
</size>
</property>
<property name="title">
<string>Weather</string>
</property>
Expand Down
95 changes: 56 additions & 39 deletions osc_generator/export_xosc.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def select_output(self):
filter="OpenSCENARIO (*.xosc)")
# Update text field only if user press 'OK'
if filename:
filename += ".xosc"
if filename[-4:] != "xosc":
filename += ".xosc"
self.select_path.setText(filename)

def save_file(self):
Expand Down Expand Up @@ -484,41 +485,51 @@ def get_environment_actions(self, init_act):
time_of_day = feature["Datetime"]
time_animation = str(feature["Datetime Animation"]).lower()
cloud_state = feature["Cloud State"]
fog_range = feature["Fog Visual Range"]
sun_intensity = feature["Sun Intensity"]
sun_azimuth = feature["Sun Azimuth"]
sun_elevation = feature["Sun Elevation"]
fog_range = str(feature["Fog Visual Range"])
sun_intensity = str(feature["Sun Intensity"])
sun_azimuth = str(feature["Sun Azimuth"])
sun_elevation = str(feature["Sun Elevation"])
percip_type = feature["Precipitation Type"]
percip_intensity = feature["Precipitation Intensity"]

global_act = etree.SubElement(init_act, "GlobalAction")
env_act = etree.SubElement(global_act, "EnvironmentAction")
environ = etree.SubElement(env_act, "Environment")
environ.set("name", "Environment1")

env_time = etree.SubElement(environ, "TimeOfDay")
env_time.set("animation", time_animation)
env_time.set("dateTime", time_of_day)

weather = etree.SubElement(environ, "Weather")
weather.set("cloudState", cloud_state)
weather_sun = etree.SubElement(weather, "Sun")
weather_sun.set("intensity", sun_intensity)
weather_sun.set("azimuth", sun_azimuth)
weather_sun.set("elevation", sun_elevation)
weather_fog = etree.SubElement(weather, "Fog")
weather_fog.set("visualRange", fog_range)
weather_percip = etree.SubElement(weather, "Precipitation")
weather_percip.set("precipitationType", percip_type)
weather_percip.set("intensity", percip_intensity)

env_road = etree.SubElement(environ, "RoadCondition")
env_road.set("frictionScaleFactor", "1.0")
percip_intensity = str(feature["Precipitation Intensity"])
except IndexError:
error_message = "No environment variables detected"
iface.messageBar().pushMessage("Error", error_message, level=Qgis.Critical)
QgsMessageLog.logMessage(error_message, level=Qgis.Critical)
self._warning_message.append(f"Critical: {error_message}")
error_message = "No environment variables detected, using defaults"
iface.messageBar().pushMessage("Info", error_message, level=Qgis.Info)
QgsMessageLog.logMessage(error_message, level=Qgis.Info)
self._warning_message.append(f"Info: {error_message}")

time_of_day = "2020-10-23T06:00:00"
time_animation = "false"
cloud_state = "free"
fog_range = "100000"
sun_intensity = "0.85"
sun_azimuth = "0"
sun_elevation = "1.31"
percip_type = "dry"
percip_intensity = "0"

global_act = etree.SubElement(init_act, "GlobalAction")
env_act = etree.SubElement(global_act, "EnvironmentAction")
environ = etree.SubElement(env_act, "Environment")
environ.set("name", "Environment1")

env_time = etree.SubElement(environ, "TimeOfDay")
env_time.set("animation", time_animation)
env_time.set("dateTime", time_of_day)

weather = etree.SubElement(environ, "Weather")
weather.set("cloudState", cloud_state)
weather_sun = etree.SubElement(weather, "Sun")
weather_sun.set("intensity", sun_intensity)
weather_sun.set("azimuth", sun_azimuth)
weather_sun.set("elevation", sun_elevation)
weather_fog = etree.SubElement(weather, "Fog")
weather_fog.set("visualRange", fog_range)
weather_percip = etree.SubElement(weather, "Precipitation")
weather_percip.set("precipitationType", percip_type)
weather_percip.set("intensity", percip_intensity)

env_road = etree.SubElement(environ, "RoadCondition")
env_road.set("frictionScaleFactor", "1.0")

def set_init_speed(self, entity, init_speed):
"""
Expand Down Expand Up @@ -1136,14 +1147,20 @@ def write_xosc(self, generated_xml):
xosc_file.write(reparsed_xml)
xosc_file.close()

if self._warning_message:
text = f"Exported OpenSCENARIO file to {self._filepath} with warning: \n\n"
text += "\n".join(self._warning_message)
else:
text = f"Successfully exported OpenSCENARIO file to {self._filepath}"
text = f"Successfully exported OpenSCENARIO file to {self._filepath}"
msg = QMessageBox()
msg.setIcon(QMessageBox.Information)
msg.setText(text)
msg.setWindowTitle("OpenSCENARIO Export")
msg.setStandardButtons(QMessageBox.Ok)
msg.exec()

if self._warning_message:
warn_msg = QMessageBox()
warn_msg.setIcon(QMessageBox.Warning)
warn_msg_text = "Exported OpenSCENARIO file has warnings!\n\n"
warn_msg_text += "\n".join(self._warning_message)
warn_msg.setText(warn_msg_text)
warn_msg.setWindowTitle("OpenSCENARIO Export Warnings")
warn_msg.setStandardButtons(QMessageBox.Ok)
warn_msg.exec()

0 comments on commit 80463f4

Please sign in to comment.