[Python] How could I get the images in custom policy in metadrive?

Discussão em 'Python' iniciado por Stack, Abril 20, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to custom a policy using metadrive frame work.To make a decision, I want to get the rgb_camera information in vehicle. I've already check the official files and I just know I can get frame from obs. But the image should get in the policy class. Then I using self.control_object to check if there is image. But I didn't find it. My policy class is degsined:

    class FastSlowPolicy(BasePolicy):
    def __init__(self, control_object, agent_id):
    super().__init__(control_object)
    self.target_acc = None
    self.current_acc = 0
    self.acc_map = {
    "speed_up": 1.0,
    "speed_down": -1.0,
    "speed_keep": 0.0,
    }
    self.vehicle = self.control_object
    self.use_llm = True
    self.step = 0
    self.heading_pid = PIDController(1.7, 0.01, 3.5)
    self.lateral_pid = PIDController(0.3, 0.002, 0.05)

    def act(self, agent_names):
    acceleration = self.control_acceleration()
    steering = self.control_steering()

    return [steering, acceleration]

    def control_steering(self):
    lane = self.vehicle.lane
    vehicle = self.vehicle
    long, lat = lane.local_coordinates(vehicle.position)
    lane_heading = lane.heading_theta_at(long + 1)
    v_heading = vehicle.heading_theta

    steering = self.heading_pid.get_result(-wrap_to_pi(lane_heading - v_heading))
    steering += self.lateral_pid.get_result(-lat)

    return steering

    def control_acceleration(self):
    if self.use_llm:
    self.use_llm = False
    print(f"[[Slow System Process]]: Decision by Large Language Model...")
    decision = decision_by_llm(self.step)
    self.step = self.step + 1
    self.target_acc = self.acc_map.get(decision['acceleration'], 0)
    if self.target_acc == 0.0:
    acceleration = 0
    else:
    acceleration = self._interpolate_acceleration(self.step)

    else:
    if self.step % 20 == 0:
    self.use_llm = True
    acceleration = self._interpolate_acceleration(self.step)

    return acceleration



    I want to get the frame image in self.control_acceleration so that I can send the images to a LLM to make a decision. The official files is: https://metadrive-simulator.readthedocs.io/en/latest/action.html#policy

    Continue reading...

Compartilhe esta Página