dummy_agent.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/usr/bin/env python
  2. # This work is licensed under the terms of the MIT license.
  3. # For a copy, see <https://opensource.org/licenses/MIT>.
  4. """
  5. This module provides a dummy agent to control the ego vehicle
  6. """
  7. from __future__ import print_function
  8. import carla
  9. from srunner.autoagents.autonomous_agent import AutonomousAgent
  10. class DummyAgent(AutonomousAgent):
  11. """
  12. Dummy autonomous agent to control the ego vehicle
  13. """
  14. def setup(self, path_to_conf_file):
  15. """
  16. Setup the agent parameters
  17. """
  18. def sensors(self):
  19. """
  20. Define the sensor suite required by the agent
  21. :return: a list containing the required sensors in the following format:
  22. [
  23. {'type': 'sensor.camera.rgb', 'x': 0.7, 'y': -0.4, 'z': 1.60, 'roll': 0.0, 'pitch': 0.0, 'yaw': 0.0,
  24. 'width': 300, 'height': 200, 'fov': 100, 'id': 'Left'},
  25. {'type': 'sensor.camera.rgb', 'x': 0.7, 'y': 0.4, 'z': 1.60, 'roll': 0.0, 'pitch': 0.0, 'yaw': 0.0,
  26. 'width': 300, 'height': 200, 'fov': 100, 'id': 'Right'},
  27. {'type': 'sensor.lidar.ray_cast', 'x': 0.7, 'y': 0.0, 'z': 1.60, 'yaw': 0.0, 'pitch': 0.0, 'roll': 0.0,
  28. 'id': 'LIDAR'}
  29. """
  30. sensors = [{'type': 'sensor.camera.rgb', 'x': 0.7, 'y': 0.0, 'z': 1.60, 'roll': 0.0, 'pitch': 0.0, 'yaw': 0.0,
  31. 'width': 800, 'height': 600, 'fov': 100, 'id': 'Center'},
  32. {'type': 'sensor.camera.rgb', 'x': 0.7, 'y': -0.4, 'z': 1.60, 'roll': 0.0, 'pitch': 0.0,
  33. 'yaw': -45.0, 'width': 800, 'height': 600, 'fov': 100, 'id': 'Left'},
  34. {'type': 'sensor.camera.rgb', 'x': 0.7, 'y': 0.4, 'z': 1.60, 'roll': 0.0, 'pitch': 0.0, 'yaw': 45.0,
  35. 'width': 800, 'height': 600, 'fov': 100, 'id': 'Right'},
  36. {'type': 'sensor.lidar.ray_cast', 'x': 0.7, 'y': -0.4, 'z': 1.60, 'roll': 0.0, 'pitch': 0.0,
  37. 'yaw': -45.0, 'id': 'LIDAR'},
  38. {'type': 'sensor.other.gnss', 'x': 0.7, 'y': -0.4, 'z': 1.60, 'id': 'GPS'},
  39. {'type': 'sensor.can_bus', 'reading_frequency': 25, 'id': 'can_bus'},
  40. {'type': 'sensor.hd_map', 'reading_frequency': 1, 'id': 'hdmap'},
  41. ]
  42. return sensors
  43. def run_step(self, input_data, timestamp):
  44. """
  45. Execute one step of navigation.
  46. """
  47. print("=====================>")
  48. for key, val in input_data.items():
  49. if hasattr(val[1], 'shape'):
  50. shape = val[1].shape
  51. print("[{} -- {:06d}] with shape {}".format(key, val[0], shape))
  52. else:
  53. print("[{} -- {:06d}] ".format(key, val[0]))
  54. print("<=====================")
  55. # DO SOMETHING SMART
  56. # RETURN CONTROL
  57. control = carla.VehicleControl()
  58. control.steer = 0.0
  59. control.throttle = 0.0
  60. control.brake = 0.0
  61. control.hand_brake = False
  62. return control