Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POMDPs.generate_s, POMDPs.generate_sr... and POMPDs.gen, PIMPDs.sampletype. #349

Closed
miguzca opened this issue Jun 9, 2021 · 0 comments
Closed

Comments

@miguzca
Copy link

miguzca commented Jun 9, 2021

Hi all!,

Thank you for the nice framework!. I am super new to Julia, and I am trying to run an implementation of a project that was done a while a go, but it seems that the implementation does not run in new versions of POMDPs framework and I am trying to figure out how to make it run. The implementation is provided here (https://github.com/biy001/UAV-autonomous-landing/blob/master/UAVLanding.jl) and I have noticed that there are mainly issues in the way "generate_s", "generate_o" and "generate_sr" are implemented in new versions of the framework. In current versions, apparently you have to use "POMDPs.gen" and return a NamedTuple with next state (sp), observation (o), and reward (r). So, basically I have modified for example

function POMDPs.generate_s(pp::UAVchaseProblem, s::MDPState, a::MDPAction, rng::AbstractRNG)
    p = mdp(pp)
    # calculate target state
    target_dt_distance = p.dt*p.target_velocity
    ## sensor_noise = Base.rand(Normal(0, p.target_std), 2)
    target_dynamic_cov = Matrix(p.target_std*Diagonal{Float64}(I, 2))
    sensor_noise = rand(rng, MvNormal(target_dynamic_cov))
    ## sensor_noise = SVector(0,0)
    curr_targ_true = s.targetPose_true + target_dt_distance
    if if_in_FOV(pp, s)
        curr_targ = curr_targ_true + sensor_noise
    else
        curr_targ = s.targetPose + target_dt_distance + sensor_noise # next_target_pos(p, s.targetPose)
    end
    # calculate UAV state
    curr_angle = s.uavHeading + a.angle
    xy_dt_distance = p.dt*a.xy_speed*SVector(cosd(curr_angle), sind(curr_angle)) # careful
    z_dt_distance = p.dt*a.z_speed
    xyz_dt_distance = SVector(xy_dt_distance[1], xy_dt_distance[2], z_dt_distance)
    curr_pos = s.uavPose + xyz_dt_distance
    return MDPState(curr_pos, curr_angle, curr_targ, curr_targ_true)
end

with

function POMDPs.gen(pp::UAVchaseProblem, s::MDPState, a::MDPAction, rng::AbstractRNG)
    p = mdp(pp)
    # calculate target state
    target_dt_distance = p.dt*p.target_velocity
    ## sensor_noise = Base.rand(Normal(0, p.target_std), 2)
    target_dynamic_cov = Matrix(p.target_std*Diagonal{Float64}(I, 2))
    sensor_noise = rand(rng, MvNormal(target_dynamic_cov))
    ## sensor_noise = SVector(0,0)
    curr_targ_true = s.targetPose_true + target_dt_distance
    if if_in_FOV(pp, s)
        curr_targ = curr_targ_true + sensor_noise
    else
        curr_targ = s.targetPose + target_dt_distance + sensor_noise # next_target_pos(p, s.targetPose)
    end
    # calculate UAV state
    curr_angle = s.uavHeading + a.angle
    xy_dt_distance = p.dt*a.xy_speed*SVector(cosd(curr_angle), sind(curr_angle)) # careful
    z_dt_distance = p.dt*a.z_speed
    xyz_dt_distance = SVector(xy_dt_distance[1], xy_dt_distance[2], z_dt_distance)
    curr_pos = s.uavPose + xyz_dt_distance
    return (sp=MDPState(curr_pos, curr_angle, curr_targ, curr_targ_true))
end

and

function POMDPs.generate_sr(pp::UAVchasePOMDP, s::MDPState, a::MDPAction, rng::AbstractRNG)
    sp = generate_s(pp, s, a, rng)
    return sp, reward(pp,a, sp)
end

with

function POMDPs.gen(pp::UAVchasePOMDP, s::MDPState, a::MDPAction, rng::AbstractRNG) #(**)
    #here generate_s is called in the old implementation.
    sp=@gen(:sp)(pp,s,a,rng) #Seems to be calling recursively the implementation we are doing here. (*)
    return (sp=sp, r=reward(pp,a, sp))
end

But I get an "StackOverflowError" because it seems to be looping (calling recursively (*) and (**)). So I guess I just do not know how to call the different implementations of "POMDPs.gen", could you please explain me how to do it?. Similarly, there is an issue with

POMDPs.sampletype(::Type{MDPStateDistribution}) = MDPState

And I have modified the code like this

function sampletype end

sampletype(d::Any) = sampletype(typeof(d))
sampletype(t::Type) = throw(MethodError(sampletype, (t,)))

But I do not think that is going to work (so far it does not show any errors there). Do you have any ideas about how to solve these issues? :).

Thank you very much in advance.!

@lassepe lassepe closed this as completed Jun 9, 2021
@JuliaPOMDP JuliaPOMDP locked and limited conversation to collaborators Jun 9, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants