RoboJackets / rrt

C++ RRT (Rapidly-exploring Random Tree) Implementation
Other
253 stars 84 forks source link

Creating obstacles programatically #86

Closed Manick9 closed 5 years ago

Manick9 commented 6 years ago

Hey guys,

I need some help on how to tweak the RRTWidget.cpp and ObstacleGrid.cpp if I want to repeat the same obstacle setup a few times?

I managed to draw using this command - painter.fillRect(100,100,100,100,Qt::SolidPattern); on the RRTWidget.cpp but I am unsure how to define it as an obstacle.

Thanks in advance, Manickam

justbuchanan commented 6 years ago

The best place for this would probably be in the constructor for RRTWidget. The state space is initialized here, which is what's responsible for representing the obstacles. Right after the state space is setup, you can do something like this to add obstacles:

auto& grid = _stateSpace->obstacleGrid();
grid.obstacleAt({0,0}) = true;
grid.obstacleAt({1,1}) = true;
// ...
Manick9 commented 6 years ago

Thanks for your fast response.

1) Is there any keywords to draw rectangles or we can use a for loop to draw obstacles?

2) I would also like to know how to output the obstacle coordinates and waypoints to a text file?

justbuchanan commented 6 years ago
  1. I don't think there are any shortcuts for drawing rectangles, but a couple of for loops should work well. Maybe as a new "setRect" method on ObstacleGrid? Feel free to send a pull request adding that feature :)

  2. There's not currently anything setup to do that, but it shouldn't be too hard to add. You could add a new export method to RRTWidget that loops through all of the obstacles and the final path and saves them to a text file. If you'll be using it a lot, you could add a new button to the gui to trigger it.

Manick9 commented 6 years ago
  1. Understood.
  2. Can we just write to a text file like on normal C++ using fstream or we have to add a new export method?
justbuchanan commented 6 years ago

Yes, all the normal C++ stuff should work. No need to put the file-writing code in it's own method - I was just suggesting that so you could connect it to a button in the gui or something.

Manick9 commented 6 years ago

Sry, I am quite noob. I should write the extra code on RRTWidget.cpp? I tried to run a sample code to write but it didn't compile.

justbuchanan commented 6 years ago

Yes, RRTWidget.cpp should be a good place for it. I don't know what caused it to fail before, but be sure to read the error messages carefully - it usually does a decent job of pointing to where the problem is.

Manick9 commented 6 years ago

Hi Josh, I managed to do it and fix the issue. Is the waypoints code over at // draw cubic bezier interpolation of waypoints or under getPath()?

I do not fully understand how does the getPath() function work.

I was wondering how to output the waypoints as waypoint(x,y). Which variables do I need to output?

What does this terms state space mean?

joshhting commented 6 years ago

Sorry about not responding, I've been pretty heavily occupied the past month or so. Was Joe able to answer these questions?