# Copyright (c) 2022-2025, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md).
# All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause

from __future__ import annotations

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from isaaclab.envs import ManagerBasedRLEnv


from isaaclab.envs.mdp import modify_term_cfg 

def annealing_std(
    env: ManagerBasedRLEnv, 
    env_ids: torch.Tensor, 
    current_value: float, 
    start_step: int, 
    end_step: int, 
    start_std: float, 
    end_std: float
):
    """
    根据步数线性退火 std 值。
    
    Args:
        current_value: 当前的参数值 (系统自动传入)
        start_step: 开始退火的步数
        end_step: 结束退火的步数
        start_std: 初始 std
        end_std: 最终 std
    """
    current_step = env.common_step_counter
    
    # 1. 还没到开始时间 -> 保持初始值 (或者不改)
    if current_step < start_step:
        # 如果当前值还没被设为 start_std，就强制设一下，否则不动
        return start_std
        
    # 2. 已经超过结束时间 -> 保持最终值
    elif current_step >= end_step:
        return end_std
        
    # 3. 在中间 -> 线性插值
    else:
        ratio = (current_step - start_step) / (end_step - start_step)
        new_std = start_std + (end_std - start_std) * ratio
        return new_std