Page 1 of 1

Handling OMPL exceptions

Posted: 30 Mar 2021, 18:12
by TrimItOut
Hi,

I was wondering if it would be possible within the sim to handle errors from OMPL without them bringing the simulator to a halt. Here is an example of errors that I am trying to handle

[simExtOMPL:warning] OMPL: e:\ompl-1.4.1-source\src\ompl\base\src\planner.cpp:310: RRTConnect: Skipping invalid goal state (invalid state)
[simExtOMPL:error] OMPL: e:\ompl-1.4.1-source\src\ompl\geometric\planners\rrt\src\rrtconnect.cpp:252: RRTConnect: Unable to sample any valid states for goal tree

This is a valid error and is occuring when I am trying to plan a path and the goal is obscured, is there any way that I can handle this or check for invalid states before running simOMPL.compute?

Cheers!

Re: Handling OMPL exceptions

Posted: 01 Apr 2021, 13:15
by coppelia
Hello,

not sure what you mean when you say a valid error...
But from the message the calculation cannot happen. So an exception is generated.
Now, if you want to catch an exception without an error to be generated, you can do something like:

Code: Select all

function generateAnError()
    a=nil
    a=a+1
end

function sysCall_init()
    local result,errorMsg=pcall(generateAnError)
    if not result then
        print("Error is: "..errorMsg)
    end
end
Cheers

Re: Handling OMPL exceptions

Posted: 01 Apr 2021, 18:53
by TrimItOut
Hi,

Thanks for your response and your code example , this is exactly along the lines of what I'm looking for.

Would there be any way to handle this error if the function being tried (generateAnError in this case) has parameters and also returns a variable?

e.g. if the function does NOT throw an error then assign the variable otherwise result is set = false

As an example of what I'm trying to do

Code: Select all


function generateAnError(number)
    a=nil
    a=a+1
    
    return number
end

function sysCall_init()
    local result,errorMsg=pcall(return_number=generateAnError(2))
    if not result then
        print("Error is: "..errorMsg)
    end
end
I know the code above has obviously very poor syntax and doesn't work but my question is how to handle errors from functions that have paramaters such that when there is no error thrown variables can be assigned?

Thanks!

Re: Handling OMPL exceptions

Posted: 01 Apr 2021, 19:14
by TrimItOut
However, this is a workaround to solve a problem that possibly has an easier solution rather than handling the error.

Ultimately I want to check whether the start state and goal state provided to OMPL are valid (collision free) before I use simOMPL.compute so that it doesn't throw the error mentioned in my first post.

To put this into context I do not want to compute the path (which is causig the error) if either the goal state or start state are invalid.

So I either need a way of checking the validity of both the goal state and start state or handling the error in some way.

Cheers

Re: Handling OMPL exceptions

Posted: 01 Apr 2021, 20:06
by coppelia
You can have several arguments and return arguments too:

Code: Select all

function generateAnError(arg1,arg2,arg3)
    a=a+1
    return arg1,arg2,arg3
end

function sysCall_init()
    local arg1=42
    local arg2=57
    local arg3=21
    local result,retArg1OrErrorMsg,retArg2,retArg3=pcall(generateAnError,arg1,arg2,arg3)
    if not result then
        print("Error is: "..retArg1OrErrorMsg)
    else
        print("No errors. Return values are",retArg1OrErrorMsg,retArg2,retArg3)
    end
end
Now the best way to guarantee the validity of the start/goal states that you submit... is to check it yourself (you have all the infos needed to perform that check)

Cheers

Re: Handling OMPL exceptions

Posted: 02 Apr 2021, 12:11
by TrimItOut
That's perfect, exactly what I was looking for!

Cheers