ValueError with CurvilinearCoordinateSystem during training with certain scenario

Hi, when I try to start training in CommonRoad RL, for some scenarios, I immediately get the following error related to the calculation of observations:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/tmp/xpython_79/1068470329.py in <module>
     22 eval_callback = EvalCallback(test_env, eval_freq=2500, n_eval_episodes=1)
     23 
---> 24 model.learn(1000000, CallbackList([checkpoint_callback, eval_callback]))

/opt/conda/envs/cr37/lib/python3.7/site-packages/stable_baselines/ppo2/ppo2.py in learn(self, total_timesteps, callback, log_interval, tb_log_name, reset_num_timesteps)
    334                 callback.on_rollout_start()
    335                 # true_reward is the reward without discount
--> 336                 rollout = self.runner.run(callback)
    337                 # Unpack
    338                 obs, returns, masks, actions, values, neglogpacs, states, ep_infos, true_reward = rollout

/opt/conda/envs/cr37/lib/python3.7/site-packages/stable_baselines/common/runners.py in run(self, callback)
     46         self.callback = callback
     47         self.continue_training = True
---> 48         return self._run()
     49 
     50     @abstractmethod

/opt/conda/envs/cr37/lib/python3.7/site-packages/stable_baselines/ppo2/ppo2.py in _run(self)
    480             if isinstance(self.env.action_space, gym.spaces.Box):
    481                 clipped_actions = np.clip(actions, self.env.action_space.low, self.env.action_space.high)
--> 482             self.obs[:], rewards, self.dones, infos = self.env.step(clipped_actions)
    483 
    484             self.model.num_timesteps += self.n_envs

/opt/conda/envs/cr37/lib/python3.7/site-packages/stable_baselines/common/vec_env/base_vec_env.py in step(self, actions)
    148         """
    149         self.step_async(actions)
--> 150         return self.step_wait()
    151 
    152     def get_images(self) -> Sequence[np.ndarray]:

/opt/conda/envs/cr37/lib/python3.7/site-packages/stable_baselines/common/vec_env/vec_normalize.py in step_wait(self)
     89         where 'news' is a boolean vector indicating whether each element is new.
     90         """
---> 91         obs, rews, news, infos = self.venv.step_wait()
     92         self.old_obs = obs
     93         self.old_rews = rews

/opt/conda/envs/cr37/lib/python3.7/site-packages/stable_baselines/common/vec_env/dummy_vec_env.py in step_wait(self)
     42         for env_idx in range(self.num_envs):
     43             obs, self.buf_rews[env_idx], self.buf_dones[env_idx], self.buf_infos[env_idx] =\
---> 44                 self.envs[env_idx].step(self.actions[env_idx])
     45             if self.buf_dones[env_idx]:
     46                 # save final observation where user can get it, then reset

/opt/conda/envs/cr37/lib/python3.7/site-packages/stable_baselines/bench/monitor.py in step(self, action)
     89         if self.needs_reset:
     90             raise RuntimeError("Tried to step environment that needs reset")
---> 91         observation, reward, done, info = self.env.step(action)
     92         self.rewards.append(reward)
     93         if done:

/opt/conda/envs/cr37/lib/python3.7/site-packages/gym/wrappers/order_enforcing.py in step(self, action)
      9     def step(self, action):
     10         assert self._has_reset, "Cannot call env.step() before calling reset()"
---> 11         observation, reward, done, info = self.env.step(action)
     12         return observation, reward, done, info
     13 

/commonroad-rl/commonroad_rl/gym_commonroad/commonroad_env.py in step(self, action)
    234         # Make action and observe result
    235         self.ego_action.step(action, local_ccosy=self.observation_collector.local_ccosy)
--> 236         observation = self.observation_collector.observe(self.ego_action.vehicle)
    237 
    238         # Check for termination

/commonroad-rl/commonroad_rl/gym_commonroad/observation/observation_collector.py in observe(self, ego_vehicle)
    180                                                                                                       self._collision_checker,
    181                                                                                                       self.local_ccosy,
--> 182                                                                                                       self._ego_lanelet_ids)
    183         observation_dict_lanelet = self.lanelet_network_observation.observe(self._scenario, ego_vehicle,
    184                                                                             self._ego_lanelet, self._road_edge,

/commonroad-rl/commonroad_rl/gym_commonroad/observation/surrounding_observation.py in observe(self, scenario, ego_vehicle, time_step, connected_lanelet_dict, ego_lanelet, collision_checker, local_ccosy, ego_lanelet_ids)
    164                 self._add_leading_following_distance_lidar_lane()
    165             if self.observe_relative_priority:
--> 166                 self._add_relative_priority(_detected_obstacles, ego_lanelet, ego_vehicle)
    167 
    168         if self.observe_lane_change:

/commonroad-rl/commonroad_rl/gym_commonroad/observation/surrounding_observation.py in _add_relative_priority(self, obstacles, ego_lanelet, ego_vehicle, turn_threshold, scan_range)
    254                 ego_curv_coords = self._local_ccosy.convert_to_curvilinear_coords(self._ego_state.position[0],
    255                                                                                   self._ego_state.position[1])
--> 256                 ego_proj_pos = self._local_ccosy.convert_to_cartesian_coords(ego_curv_coords[0], 0)
    257                 t_type = self.trajectory_type_from_path(
    258                     self._local_ccosy.reference_path(), turn_threshold, pycrcc.Circle(scan_range, ego_proj_pos[0],

ValueError: <CurvilinearCoordinateSystem/convertToCurvilinearCoords> Coordinate outside of projection domain.

I am using the default environment settings (from commonroad_rl/gym_commonroad/configs.yaml), with the hybrid reward setting and a point mass model (the error also occurs for the kinematic bicycle model). The benchmark used for training is C-DEU_B471-2_1 from the CommonRoad website. Why does this error occur? Is there a way to fix it or to configure the observations as a workaround?

Hi Tristan, could you please print the position of the ego vehicle when this error happens?