function v_updated = update_v2(time, v0, Z1_diff, Z2_diff, Z2, Z1, v2)
alpha_3 = -0.017156;
alpha_4 = 0.023975;
v_split = 41.711;
u3_max = 1;
u4_max = 1;
update_time_limit = 25;

global bias_v2;
global v2_time_before_next_update_is_allowed;
%%%%%%%%%%%%%%%%%%%%
if Z2_diff ~= 0
    if v2 < v_split
        if time >= v2_time_before_next_update_is_allowed
        bias_v2 = (Z1-u3_max)/alpha_3 + v_split - v0;
        v2_time_before_next_update_is_allowed = time + update_time_limit;
        end
    end
end
%%%%%%%%%%%%%%%%%%%%
if Z1_diff ~= 0
    if v2 > v_split
        if time >= v2_time_before_next_update_is_allowed
        bias_v2 = (Z2-u4_max)/alpha_4 + v_split - v0;
        v2_time_before_next_update_is_allowed = time + update_time_limit;
        end
    end
end
%%%%%%%%%%%%%%%%%%%%
v_updated = v0 + bias_v2;
end