se2ez
|
Helper class to compute and draw C-Space images from arbitrary robots. More...
#include <cspace.h>
Classes | |
struct | Chunk |
Container class for image chunk information to worker threads. More... | |
struct | GridCoords |
Grid coordinates. More... | |
struct | GridLine |
Line on the grid. More... | |
struct | RobotCoords |
Coordinates for the robot. More... | |
Public Types | |
enum | Mode { COLLISION, COLOR, DISTANCE, DISTANCE_COLOR } |
Drawing mode for the grid. More... | |
using | GridCallback = std::function< void(ompl::PPM::Color &, const StatePtr &, bool)> |
Function to callback for grid computation. Gives a pixel to color, the state, and whether the state is in collision. More... | |
Public Member Functions | |
CSpaceGrid (const RobotPtr &robot, unsigned int jointA, unsigned int jointB, unsigned int width=500, unsigned int height=500, Mode mode=COLLISION) | |
Constructor. More... | |
CSpaceGrid (const RobotPtr &robot, const std::string &jointA, const std::string &jointB, unsigned int width=500, unsigned int height=500, Mode mode=COLLISION) | |
Constructor. More... | |
~CSpaceGrid () | |
Destructor. More... | |
void | compute (bool block=true, const StatePtr &base=nullptr, const GridCallback &callback={}) |
Compute a PPM image of the configuration space of two joints, jointA and jointB. More... | |
void | waitToComplete () |
Wait for all grid computation to complete. More... | |
bool | isComputing () const |
Checks if any computation is happening. More... | |
void | cancel () |
Cancels any remaining computation. More... | |
ompl::PPM::Color & | getPixel (const StatePtr &state) |
Get the pixel coordinate for a configuration. More... | |
ompl::PPM::Color & | getPixel (double i, double j) |
Get the pixel coordinate for a configuration of i for jointA and j for jointB. More... | |
GridCoords | getCoords (const StatePtr &state) |
Get the pixel coordinate for a configuration. More... | |
GridCoords | getCoords (double i, double j) |
Get the pixel coordinate for a configuration. More... | |
RobotCoords | getCoords (unsigned int i, unsigned int j) |
Get the associated robot configuration from image coordinates. More... | |
std::vector< GridLine > | getLines (const StatePtr &a, const StatePtr &b) |
Get the line segments between two points on the grid. Can have two due to wrapping. More... | |
std::shared_ptr< ompl::PPM > | getImage () const |
Get the current computed PPM image. More... | |
double | distanceToSlice (const StatePtr &state) |
Returns the distance along the dimensions of the robot not captured by the current C-Space slice. More... | |
double | progress () const |
Returns a value in [0, 1] of the progress of the current computation. More... | |
unsigned int | getWidth () const |
Return width of grid. More... | |
unsigned int | getHeight () const |
Return height of grid. More... | |
Private Member Functions | |
void | initialize () |
Initialize all internal constructs. More... | |
void | emplaceChunks () |
Emplaces all images chunks into work queue. More... | |
Eigen::Vector4d | getFrameColor (const std::string &frame) const |
Gets the average color of a frame. More... | |
Private Attributes | |
const RobotPtr | robot_ |
Robot to use. More... | |
const unsigned int | xChunk_ {25} |
Size of X chunk for threading. More... | |
const unsigned int | yChunk_ {25} |
Size of Y chunk for threading. More... | |
const double | minDepth_ {-1.} |
Minimum value for signed distance color map. More... | |
const double | maxDepth_ {1.} |
Maximum value for signed distance color map. More... | |
const unsigned int | indexA_ |
Joint index for X-axis. More... | |
const unsigned int | indexB_ |
Joint index for Y-axis. More... | |
const Eigen::Vector2d | limitA_ |
Joint limits for first joint (1-DoF) More... | |
const Eigen::Vector2d | limitB_ |
Joint limits for second joint (1-DoF) More... | |
const bool | contA_ |
Is joint A continuous? More... | |
const bool | contB_ |
Is joint B continuous? More... | |
const unsigned int | width_ |
Width of image. More... | |
const unsigned int | height_ |
Height of image. More... | |
const Mode | mode_ |
Render mode. More... | |
std::shared_ptr< ompl::PPM > | image_ {nullptr} |
Image itself. More... | |
unsigned int | maxChunks_ {0} |
Maximum number of chunks in queue. More... | |
StatePtr | state_ {nullptr} |
State provided through compute(). More... | |
StatePtr | temp_ {nullptr} |
Temporary state. More... | |
GridCallback | callback_ {} |
Callback function to use for extra drawing. More... | |
bool | done_ {false} |
Notify threads object is to be destroyed. More... | |
std::mutex | lock_ |
Mutex. More... | |
std::mutex | statelock_ |
Mutex for state. More... | |
std::condition_variable | work_ |
Condition variable that there is work to do. More... | |
std::condition_variable | complete_ |
Condition variable to notify when complete. More... | |
std::queue< Chunk > | chunks_ |
Queue of chunks. More... | |
std::vector< bool > | newState_ |
Has each thread updated to new base state for computation? More... | |
std::vector< bool > | working_ |
Which threads are currently working? More... | |
std::vector< std::thread * > | threads_ |
Threads. More... | |
Static Private Attributes | |
static const unsigned int | cores_ {std::thread::hardware_concurrency()} |
Number of cores on the machine. More... | |
Helper class to compute and draw C-Space images from arbitrary robots.
using se2ez::CSpaceGrid::GridCallback = std::function<void(ompl::PPM::Color &, const StatePtr &, bool)> |
CSpaceGrid::CSpaceGrid | ( | const RobotPtr & | robot, |
unsigned int | jointA, | ||
unsigned int | jointB, | ||
unsigned int | width = 500 , |
||
unsigned int | height = 500 , |
||
Mode | mode = COLLISION |
||
) |
Constructor.
[in] | robot | Robot to compute grid for. |
[in] | jointA | index of configuration to vary. |
[in] | jointB | other index of configuration to vary. |
[in] | width | Width of image to compute. |
[in] | height | Height of image to compute. |
[in] | mode | What mode to use for rendering. |
Definition at line 21 of file cspace.cpp.
CSpaceGrid::CSpaceGrid | ( | const RobotPtr & | robot, |
const std::string & | jointA, | ||
const std::string & | jointB, | ||
unsigned int | width = 500 , |
||
unsigned int | height = 500 , |
||
Mode | mode = COLLISION |
||
) |
Constructor.
[in] | robot | Robot to compute grid for. |
[in] | jointA | 1-DoF joint to vary. |
[in] | jointB | other 1-DoF joint to vary. |
[in] | width | Width of image to compute. |
[in] | height | Height of image to compute. |
[in] | mode | What mode to use for rendering. |
Definition at line 43 of file cspace.cpp.
CSpaceGrid::~CSpaceGrid | ( | ) |
Destructor.
Definition at line 196 of file cspace.cpp.
void CSpaceGrid::cancel | ( | ) |
Cancels any remaining computation.
Definition at line 394 of file cspace.cpp.
void CSpaceGrid::compute | ( | bool | block = true , |
const StatePtr & | base = nullptr , |
||
const GridCallback & | callback = {} |
||
) |
Compute a PPM image of the configuration space of two joints, jointA and jointB.
[in] | block | Wait for computation to finish. If false, returns immediately. |
[in] | base | For robots with more than 2 DoF, set other DoF to this state. |
[in] | callback | Extra callback function to draw extra information. |
Definition at line 231 of file cspace.cpp.
double CSpaceGrid::distanceToSlice | ( | const StatePtr & | state | ) |
Returns the distance along the dimensions of the robot not captured by the current C-Space slice.
[in] | state | State to measure distance to. |
Definition at line 403 of file cspace.cpp.
|
private |
Emplaces all images chunks into work queue.
Definition at line 209 of file cspace.cpp.
CSpaceGrid::GridCoords CSpaceGrid::getCoords | ( | const StatePtr & | state | ) |
Get the pixel coordinate for a configuration.
[in] | state | State to use for configuration values. |
Definition at line 272 of file cspace.cpp.
CSpaceGrid::GridCoords CSpaceGrid::getCoords | ( | double | i, |
double | j | ||
) |
Get the pixel coordinate for a configuration.
[in] | i | Configuration for first joint. |
[in] | j | Configuration for second joint. |
Definition at line 283 of file cspace.cpp.
CSpaceGrid::RobotCoords CSpaceGrid::getCoords | ( | unsigned int | i, |
unsigned int | j | ||
) |
Get the associated robot configuration from image coordinates.
[in] | i | X-coordinate |
[in] | j | Y-coordinate |
Definition at line 291 of file cspace.cpp.
|
private |
Gets the average color of a frame.
[in] | frame | Frame to get color of. |
Definition at line 420 of file cspace.cpp.
unsigned int CSpaceGrid::getHeight | ( | ) | const |
std::shared_ptr< ompl::PPM > CSpaceGrid::getImage | ( | ) | const |
Get the current computed PPM image.
Definition at line 381 of file cspace.cpp.
std::vector< CSpaceGrid::GridLine > CSpaceGrid::getLines | ( | const StatePtr & | a, |
const StatePtr & | b | ||
) |
Get the line segments between two points on the grid. Can have two due to wrapping.
[in] | a | Endpoint a |
[in] | b | Endpoint b |
Definition at line 299 of file cspace.cpp.
ompl::PPM::Color & CSpaceGrid::getPixel | ( | const StatePtr & | state | ) |
Get the pixel coordinate for a configuration.
[in] | state | State to use for configuration values. |
Definition at line 267 of file cspace.cpp.
ompl::PPM::Color & CSpaceGrid::getPixel | ( | double | i, |
double | j | ||
) |
Get the pixel coordinate for a configuration of i for jointA and j for jointB.
[in] | i | Value for jointA. |
[in] | j | Value for jointB. |
Definition at line 277 of file cspace.cpp.
unsigned int CSpaceGrid::getWidth | ( | ) | const |
|
private |
Initialize all internal constructs.
Definition at line 50 of file cspace.cpp.
bool CSpaceGrid::isComputing | ( | ) | const |
Checks if any computation is happening.
Definition at line 386 of file cspace.cpp.
double CSpaceGrid::progress | ( | ) | const |
Returns a value in [0, 1] of the progress of the current computation.
Definition at line 412 of file cspace.cpp.
void CSpaceGrid::waitToComplete | ( | ) |
Wait for all grid computation to complete.
Definition at line 255 of file cspace.cpp.
|
private |
|
private |
|
private |
|
private |
|
private |
|
staticprivate |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |