Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: plotting path of a robot in an obstacle filled environment  (Read 3242 times)

0 Members and 1 Guest are viewing this topic.

RagingBull

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
plotting path of a robot in an obstacle filled environment
« on: September 04, 2012, 01:00:20 pm »
Hi guys!
I am writing code for rrt(rapidly exploring random trees) which is a sampling based motion planning algorithm.I wrote the code in MATLAB but now i am writing it in c++. I am trying to use sfml but I am having problems with it.
Basically this is what I am trying to do:
calculate the position of the robot and plot it.So when the program executes I would be seeing my robot traversing the space and avoiding the obstacles and finally reaching the goal position.This means that window needs to update dynamically retaining te previous state.
Q-1 how to check whether a point lies inside a polygon (this is for obstacle detection)?
Q-2  the default window only works in the first coordinate....how can i deal with negative coordinates? if i try to give position values which are negative then i can't see anything on the window.Does it have to do something with the views?
Q-3 is it even possible to do what i intend to do using sfml?
Thanks a lot  :)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: plotting path of a robot in an obstacle filled environment
« Reply #1 on: September 04, 2012, 01:11:44 pm »
Q-1 how to check whether a point lies inside a polygon (this is for obstacle detection)?
This is a puerly mathematical problem and there are many solutions floating around in the internet, just google for it. ;)

Q-2  the default window only works in the first coordinate....how can i deal with negative coordinates? if i try to give position values which are negative then i can't see anything on the window.Does it have to do something with the views?
If I understood you correctly, you want to follow the robot if he'd move out of the window (= negativ coordinates), right?
Then yes you'd just have to move the view of the window.

Q-3 is it even possible to do what i intend to do using sfml?
Everything is possible with C++ and SFML is just a library that will help you with drawing and input stuff and since SFML has a sf::VertexArray it can nearly draw anything you want. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

RagingBull

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: plotting path of a robot in an obstacle filled environment
« Reply #2 on: September 04, 2012, 04:48:39 pm »
Thanks for the reply...what i meant was how to check whether a point lies inside a polygon created using sfml
My polygon would be defined using polygon.addpoint().How should i go abt checking this?
in matlab you have a function inpolygon() that does this job...what abt sfml
i am aware of the methods to check for collision...for eg writing the eqns of lines forming the polygon and then checking the sign of the expression and so on.....the thing is ...isn't there a direct method or function available to do this job?If i have to do this by writing eqns and all then i may as well use a much simpler library like koolplot....there ought to be a better way of doing this

For the window limits part...i want to basically set x and y axes limits...for eg x limit:-100 to 100 and y limit:-150 to 200
i hope you get the point
 :)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: plotting path of a robot in an obstacle filled environment
« Reply #3 on: September 04, 2012, 05:01:44 pm »
I guess you're wrote the last message on your phone or table, but please try to write full English words and sentences, it's quite hard to read otherwise (abt = about, eqns = equations). ;)

Thanks for the reply...what i meant was how to check whether a point lies inside a polygon created using sfml
My polygon would be defined using polygon.addpoint(). How should i go abt checking this?
in matlab you have a function inpolygon() that does this job...what abt sfml
SFML is not a math library and is also not design for that. There doesn't exist a inpolygon() function or similar (afaik).
There are many ways to check it here and here are two possibilities.

For the window limits part...i want to basically set x and y axes limits...for eg x limit:-100 to 100 and y limit:-150 to 200
i hope you get the point
Not really... What should those limits do and what do you actually want to achive?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

RagingBull

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: plotting path of a robot in an obstacle filled environment
« Reply #4 on: September 04, 2012, 05:16:53 pm »
by setting the limits to the window i would be better able to monitor the motion of my robot...it can traverse anywhere....first quadrant or may be the third quadrant ...if the default mode only has the 1st quadrant to display then it's a problem....if the problem can be solved using views then i will try to look at it in greater depth...i was really tired searching for simple to use libraries all around...sfml seemed to be very user friendly.....and  i am currently going through the documentation...and i really like it

I have one more question though....as you know i need to see the robot traversing the space...that means the window has to update itself after every iteration....but from what i have seen we need to use App.clear() command everytime which means i have to store the previous states of my robot and every time display them again rather than just displaying the current position over the existing window..is there a way of retaining the current state of the window so i can just update it with a new position of the robot?
thnks

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: plotting path of a robot in an obstacle filled environment
« Reply #5 on: September 04, 2012, 05:25:43 pm »
if the problem can be solved using views then i will try to look at it in greater depth...
Maybe my tutorial on sf::View can help you understand it. ;)

I have one more question though....as you know i need to see the robot traversing the space...that means the window has to update itself after every iteration....but from what i have seen we need to use App.clear() command everytime which means i have to store the previous states of my robot and every time display them again rather than just displaying the current position over the existing window..is there a way of retaining the current state of the window so i can just update it with a new position of the robot?
Well it's adviced to always call window.clear(), but it's not forced so you can clear the window only when needed (e.g. before drawing the first position) and draw then each position over the other. But this method isn't really that good, because as soon, as you'd move another window over your window, the drawn information will be lost.
Also it's fairly easy to just push back a new position into a std::vector and then display a connected line with sf::VertexArray or similar.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

RagingBull

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: plotting path of a robot in an obstacle filled environment
« Reply #6 on: September 04, 2012, 05:38:44 pm »
i just realized that I actually went through your tutorial before this post..read it in a hurry though (i was very impatient at that time)  so couldn't understand it properly but i felt the answer lied somewhere there...i will go through it again...and yeah using a vector is a good solution but i was wondering why such a capability (of retaining the current state  of the window) isn't incorporated in this library...it would have been really good

Thanks a lot for your help...i am quite clear about  most of the stuff now  :)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: plotting path of a robot in an obstacle filled environment
« Reply #7 on: September 04, 2012, 05:46:48 pm »
i was wondering why such a capability (of retaining the current state  of the window) isn't incorporated in this library...it would have been really good
It's not such a trivial task and there are quite a few open questions, like would one only save what has been drawn visibly on the window, or also things that are drawn offscreen? What happens when you move the view around? etc...
And then again there isn't a very common need for such a functionality, since most games update anyways very often the whole screen and manage their objects & positions on their own.

If you really want that effect, then you can create an off screen buffer with sf::RenderTexture, to which you can draw everything you want and then extrat the texture and draw it with a sprite or shape to the window. But you'll have to figure out on your own what should happen if the view gets moved. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

RagingBull

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: plotting path of a robot in an obstacle filled environment
« Reply #8 on: September 04, 2012, 06:34:24 pm »
i will definitely give it a thought
thanks a lot for your help :)