Robot Planning and its Applications Project
Functions | Variables
student Namespace Reference

Functions

void mouseCallback (int event, int x, int y, int, void *p)
 Function called after every mouse click. More...
 
std::vector< cv::Point2f > pickNPoints (int n0, const cv::Mat &img)
 Function to pick points from image. More...
 
bool extrinsicCalib (const cv::Mat &img_in, std::vector< cv::Point3f > object_points, const cv::Mat &camera_matrix, cv::Mat &rvec, cv::Mat &tvec, const std::string &config_folder)
 Function for extrinsic calibration. More...
 
void imageUndistort (const cv::Mat &img_in, cv::Mat &img_out, const cv::Mat &cam_matrix, const cv::Mat &dist_coeffs, const std::string &config_folder)
 Function undistort the given image. More...
 
void findPlaneTransform (const cv::Mat &cam_matrix, const cv::Mat &rvec, const cv::Mat &tvec, const std::vector< cv::Point3f > &object_points_plane, const std::vector< cv::Point2f > &dest_image_points_plane, cv::Mat &plane_transf, const std::string &config_folder)
 Perspective projection. More...
 
void unwarp (const cv::Mat &img_in, cv::Mat &img_out, const cv::Mat &transf, const std::string &config_folder)
 Image unwarping. More...
 
bool findRobot (const cv::Mat &img_in, const double scale, Polygon &triangle, double &x, double &y, double &theta, const std::string &config_folder)
 find Robot function in student interface More...
 
void loadImage (cv::Mat &img_out, const std::string &config_folder)
 load Image function in student interface More...
 
bool getCurvature (int step, Path &path)
 
bool sort_pair_mission2 (const std::pair< int, Polygon > &a, const std::pair< int, Polygon > &b)
 
std::vector< PolygonobstacleOffsetting (const std::vector< Polygon > ob, int offset_radius)
 Expand obstacles region to avoid collision. More...
 
Polygon resizeBorders (const Polygon &borders, int resize)
 Resize the border for avoiding collision with border. More...
 
Polygon sample_borders (Polygon &borders)
 Sample the borders with multiple points. More...
 
std::pair< double, double > get_center (const Polygon &poly)
 get centroid of any polygon More...
 
bool pointInsidePolygon (Polygon poly, Point pt)
 function to check if a given point is inside polygon More...
 
double compute_angle_gate (Polygon borders, double gateX, double gateY)
 function to compute the gate angle More...
 
double internal_angle (double angle1, double angle2)
 
double get_angle (Pose first, Pose second, Pose third)
 function to compute the approach angle between two nodes More...
 
bool check_collison_with_borders_and_obstacles (Path path, Polygon borders, Polygon sampled_borders, std::vector< Polygon > obstacle_list, std::vector< double > obs_radius, std::vector< Point > obs_center)
 function to check if the generated path is colliding with borders and obstacles More...
 
void RRT_Star (const float x, const float y, const float theta, Path &path, std::vector< Point > &localGoals, const Polygon &borders, Polygon &sampled_borders, const std::vector< Polygon > &obstacle_list, std::vector< double > obs_radius, std::vector< Point > obs_center, config_Params_planPath config_params)
 implmentation of RRT Star function More...
 
void RRT_Star_ompl (const float x, const float y, const float theta, Path &path, std::vector< Point > &localGoals, const Polygon &borders, Polygon &sampled_borders, const std::vector< Polygon > &obstacle_list, std::vector< double > obs_radius, std::vector< Point > obs_center, config_Params_planPath config_params)
 implmentation of RRT Star function using OMPL library More...
 
std::vector< Pointcompute_vicitim_mission2 (const float x, const float y, const float theta, const Polygon &borders, const std::vector< Polygon > &obstacle_list, std::pair< double, double > gateCenter, std::vector< std::pair< int, Polygon >> victim_list, config_Params_planPath config_params)
 implmentation of Mission targets for mision 2 More...
 
bool planPath (const Polygon &borders, const std::vector< Polygon > &obstacle_list, const std::vector< std::pair< int, Polygon >> &victim_list, const Polygon &gate, const float x, const float y, const float theta, Path &path, const std::string &config_folder)
 Plan a safe and fast path in the arena. More...
 
bool sort_pair (const std::pair< int, Polygon > &a, const std::pair< int, Polygon > &b)
 
bool processObstacles (const cv::Mat &hsv_img, const double scale, std::vector< Polygon > &obstacle_list, config_Params_ProcessMap config_params)
 Obstacle detection function. More...
 
bool processGate (const cv::Mat &hsv_img, const double scale, Polygon &gate, config_Params_ProcessMap config_params)
 gate detection function More...
 
int get_victim_id (cv::Rect boundingRect, cv::Mat img, config_Params_ProcessMap config_params)
 Function to get victim ID. More...
 
bool processVictims (const cv::Mat &hsv_img, const double scale, std::vector< std::pair< int, Polygon >> &victim_list, config_Params_ProcessMap config_params)
 Victim detection function along with digit recognition call. More...
 
bool processMap (const cv::Mat &img_in, const double scale, std::vector< Polygon > &obstacle_list, std::vector< std::pair< int, Polygon >> &victim_list, Polygon &gate, const std::string &config_folder)
 Main function to call processObstacles, processGate and processVictims. More...
 
void genericImageListener (const cv::Mat &img_in, std::string topic, const std::string &config_folder)
 Function to save images for intrinsic calibration. More...
 

Variables

cv::Mat dist_coeffs_for_ex
 
cv::Mat debug_image
 

Function Documentation

bool student::check_collison_with_borders_and_obstacles ( Path  path,
Polygon  borders,
Polygon  sampled_borders,
std::vector< Polygon obstacle_list,
std::vector< double >  obs_radius,
std::vector< Point obs_center 
)

function to check if the generated path is colliding with borders and obstacles

This is an additional function which checcks if the path generated by Clothoids/Dubins is colliding with the obstacles and borders. Here sampled borders are used to check the distance between path and borders

Parameters
pathThe path generated by Clothoids/Dubins
sampled_bordersthe borders points which are sampled
obstacle_listThe list of obstacle and their points
obs_radiusRadius of each obstacle
obs_centerCenter of each obstacle
Returns
true/false- Colliding/Not Colliding
double student::compute_angle_gate ( Polygon  borders,
double  gateX,
double  gateY 
)

function to compute the gate angle

gate angle is very important and cannot be same as other cases. Because the recatngle of gate can be different locations(Left,Right,Bottom,Top) and oriented(Horizontal, Vertical) in different way. A combination of the locations and orientation are possible.

Parameters
bordersthe border locations
gateXgate center X
gateYgate center Y
Returns
the approach angle of the final gate
std::vector<Point> student::compute_vicitim_mission2 ( const float  x,
const float  y,
const float  theta,
const Polygon borders,
const std::vector< Polygon > &  obstacle_list,
std::pair< double, double >  gateCenter,
std::vector< std::pair< int, Polygon >>  victim_list,
config_Params_planPath  config_params 
)

implmentation of Mission targets for mision 2

This is very simple logic, where RRT* path is generated from source and gate . And a threshold value is used to check the distance of victims from path. If the distance is high the cost is computed accordingly and that vicitm is rejected to be saved. Also the victim is then sorted based on their occurance in path direction. This helps save time for robot.

Parameters
xThe robot location x
yThe robot location y
thetaThe robot orientation theta
paththe output path variable
localGoalsthe local goals which includes the victims and gate
bordersoriginal borders
sampled_bordersthe borders points which are sampled
obstacle_listThe list of obstacle and their points
obs_radiusRadius of each obstacle
obs_centerCenter of each obstacle
config_paramsConfiguration parameters related to mission2 victim computation
bool student::extrinsicCalib ( const cv::Mat &  img_in,
std::vector< cv::Point3f >  object_points,
const cv::Mat &  camera_matrix,
cv::Mat &  rvec,
cv::Mat &  tvec,
const std::string &  config_folder 
)

Function for extrinsic calibration.

Extrinsic calibration to determine the Rotational and translational matrix. Four points will be chosen in the image plane and then these 4 points will be solved using the solvePnP interface from opencv to solve the extrinsic problem.

Parameters
img_ininput image
oject_points4 points that are chosen in image
camera_matrixThe obtained camera matrix from intrinsic calibration
rvecOutput rotational vector
tvecOutput translational vector
config_folderOutput folder (if file existing then function justs reads the file to get rvec and tvec)
void student::findPlaneTransform ( const cv::Mat &  cam_matrix,
const cv::Mat &  rvec,
const cv::Mat &  tvec,
const std::vector< cv::Point3f > &  object_points_plane,
const std::vector< cv::Point2f > &  dest_image_points_plane,
cv::Mat &  plane_transf,
const std::string &  config_folder 
)

Perspective projection.

Now to have a bird’s eye view of the image, where we need to project the 3D objects in a image plane, carry out Perspective Projection initially. This is again carried out with the opencv interfaces, projectPoints() and getPerspectiveTransform().

Parameters
cam_matrixcamera_matrix
rvecOutput rotational vector
tvecOutput translational vector
object_points_planeObject points
dest_image_points_planedestination image points plane
config_folderOutput folder (if file existing then function justs reads the file to get rvec and tvec)
bool student::findRobot ( const cv::Mat &  img_in,
const double  scale,
Polygon triangle,
double &  x,
double &  y,
double &  theta,
const std::string &  config_folder 
)

find Robot function in student interface

Directly utilized the function provided by the teaching assistant as I found that implementation was already in the best shape. RGB→HSV→blue mask→Contours→Approximate polynomial→find 3 points of polynomial→Find center of triangle→Find angle between top vertex and center(Orientation)→return state(x,y,ψ)

Parameters
img_inInput Image
scalescaling factor
triangleThe outpu triangle of robot
xrobot pose (center) x
yrobot pose (center) y
thetarobot pose (initial) theta
config_folderconfig folder if any configuration params to be loaded
Returns
true/false robot found or not
void student::genericImageListener ( const cv::Mat &  img_in,
std::string  topic,
const std::string &  config_folder 
)

Function to save images for intrinsic calibration.

Through this the images are saved from the simulator which contains checkerboard.

Parameters
img_inInput Image
topictopic in which the image arrives
config_folderconfig folder to store the saved images
Returns
true/false robot found or not
double student::get_angle ( Pose  first,
Pose  second,
Pose  third 
)

function to compute the approach angle between two nodes

The motion planning generates points betwwen source, victims and to gate. This points are then given to local planner(Clothoids/Dubins). This function will compute the approach angle between two points. Also a special logic to get the approach angle for victims. The logic is to use the line segment angle difference. Three points are taken, the angle between the first line segment(first and second points) and next line segments(second and third points) are used to compute thh approach angle of second point.

Parameters
firstFirst point
secondSecond point
thirdThird point
Returns
the approach angle of the second point
std::pair<double, double> student::get_center ( const Polygon poly)

get centroid of any polygon

sum_of_all_vertices/ size_of_vertices

Parameters
polyInpput polygon
Returns
center as a std::pair
int student::get_victim_id ( cv::Rect  boundingRect,
cv::Mat  img,
config_Params_ProcessMap  config_params 
)

Function to get victim ID.

This is mainly done to detect the number of Victims, so that the priority to save the victims can be known to the planning algorithm. This involves template matching majorly and the templates were provided in lecture. I have used majorly the opencv template matching methods. But I also implemented the tesseract-ocr method,although the results were not satisfying. Template rotation was performed ,Each template will be rotated by 5 degrees and then they are set to calculate the score and the maximum of all of that will be be finalized as digits. Steps followed: Detect Victims→get bounding rect→mask and filter image→change background→read templates→Resize and filter the ROI→change different orientation of ROI→match template→return Digit

Parameters
boundingRectThe bounding rectangle of the victim location
imghsv image of the input
config_paramsconfiguration parameters realted to obstacle detection, includes template location
Returns
vicitm id
bool student::getCurvature ( int  step,
Path path 
)
void student::imageUndistort ( const cv::Mat &  img_in,
cv::Mat &  img_out,
const cv::Mat &  cam_matrix,
const cv::Mat &  dist_coeffs,
const std::string &  config_folder 
)

Function undistort the given image.

Using the distortion coefficients obtained in the previous steps, remove the distorted effect on the image. This is done using the opencv undistort function

Parameters
img_ininput image
img_outoutput image
camera_matrixThe obtained camera matrix from intrinsic calibration
dist_coeffsdistortion coefficients
config_folderOutput folder (if file existing then function justs reads the file to get rvec and tvec)
double student::internal_angle ( double  angle1,
double  angle2 
)
void student::loadImage ( cv::Mat &  img_out,
const std::string &  config_folder 
)

load Image function in student interface

Function used directly given by Teaching assistant

Parameters
img_outOutput Image
config_folderlocation where load image is stored
void student::mouseCallback ( int  event,
int  x,
int  y,
int  ,
void *  p 
)

Function called after every mouse click.

Function obatined from Professor interface

Parameters
eventmouse event occured
xx-position of mouse event
yy-position of mouse event
std::vector<Polygon> student::obstacleOffsetting ( const std::vector< Polygon ob,
int  offset_radius 
)

Expand obstacles region to avoid collision.

Using clipper libray , the execution of enlarging the obstacles is easier with AddPath() and Execute () API's

Parameters
obAll Obstacles polygon to be expanded
offet_radiusThe radius by which the obstacle is to be expanded
Returns
Exapanded obstacles with the given radius
std::vector<cv::Point2f> student::pickNPoints ( int  n0,
const cv::Mat &  img 
)

Function to pick points from image.

Function obatined from Professor interface

Parameters
n0number of points to be picked
imgthe image from which the points are to be chosen
bool student::planPath ( const Polygon borders,
const std::vector< Polygon > &  obstacle_list,
const std::vector< std::pair< int, Polygon >> &  victim_list,
const Polygon gate,
const float  x,
const float  y,
const float  theta,
Path path,
const std::string &  config_folder 
)

Plan a safe and fast path in the arena.

Parameters
bordersborder of the arena [m]
obstacle_listlist of obstacle polygon [m]
victim_listlist of pair victim_id and polygon [m]
gatepolygon representing the gate [m]
xx position of the robot in the arena reference system
yy position of the robot in the arena reference system
thetayaw of the robot in the arena reference system
config_folderA custom string from config file.
bool student::pointInsidePolygon ( Polygon  poly,
Point  pt 
)

function to check if a given point is inside polygon

using boost::within library

Parameters
polyinput polygon
ptinput point to check if this is inside the poly
Returns
true/false - insidePolygon/NotInsidePolygon
bool student::processGate ( const cv::Mat &  hsv_img,
const double  scale,
Polygon gate,
config_Params_ProcessMap  config_params 
)

gate detection function

Steps followed: RGB→HSV→Apply Green mask→Contours→approximate Polynomial→detect 4 points→Return Gate

Parameters
hsv_imgHSV Image input
scalescaling factor
gateOutput gate polygon
config_paramsconfiguration parameters realted to gate detection
Returns
true/false Execution successful
bool student::processMap ( const cv::Mat &  img_in,
const double  scale,
std::vector< Polygon > &  obstacle_list,
std::vector< std::pair< int, Polygon >> &  victim_list,
Polygon gate,
const std::string &  config_folder 
)

Main function to call processObstacles, processGate and processVictims.

Parameters
boundingRectThe bounding rectangle of the victim location
img_inrgb image of the input
scalescaling factor
obstacle_listOutput obstacle list
victim_listOutput victim list pair
gateOutput gate polygon
config_folderconfig folder
Returns
true/false Execution successful
bool student::processObstacles ( const cv::Mat &  hsv_img,
const double  scale,
std::vector< Polygon > &  obstacle_list,
config_Params_ProcessMap  config_params 
)

Obstacle detection function.

Steps followed RGB→HSV→Apply red mask→Contours→approximate Polynomial→Return Obstacles

Parameters
hsv_imgHSV Image input
scaleScaling factor
obstacle_listOutput obstacle list
config_paramsconfiguration parameters realted to obstacle detection
Returns
true/false Execution successful

Steps involved in process Obstacles one by one

First range of red region in HSV

Second range of red region in HSV

add the regions of red space in HSV format

find all contours in the image

approximate the contours

create a obstacle list

debug plot in seperate debug image

bool student::processVictims ( const cv::Mat &  hsv_img,
const double  scale,
std::vector< std::pair< int, Polygon >> &  victim_list,
config_Params_ProcessMap  config_params 
)

Victim detection function along with digit recognition call.

Steps followed: RGB→HSV→Apply Green mask→Contours→approximate Polynomial→detect more than 6 points(check circle)→ get id of victim → return Victims

Parameters
hsv_imgHSV Image input
scalescaling factor
victim_listOutput victim list pair
config_paramsconfiguration parameters realted to gate detection
Returns
true/false Execution successful
Polygon student::resizeBorders ( const Polygon borders,
int  resize 
)

Resize the border for avoiding collision with border.

manual computation of resizing borders

Parameters
bordersborder which is given as polygon
resizethe resizing factor
Returns
resized border
void student::RRT_Star ( const float  x,
const float  y,
const float  theta,
Path path,
std::vector< Point > &  localGoals,
const Polygon borders,
Polygon sampled_borders,
const std::vector< Polygon > &  obstacle_list,
std::vector< double >  obs_radius,
std::vector< Point obs_center,
config_Params_planPath  config_params 
)

implmentation of RRT Star function

This is an own implementation of RRT Star with few references.

Parameters
xThe robot location x
yThe robot location y
thetaThe robot orientation theta
paththe output path variable
localGoalsthe local goals which includes the victims and gate
bordersoriginal borders
sampled_bordersthe borders points which are sampled
obstacle_listThe list of obstacle and their points
obs_radiusRadius of each obstacle
obs_centerCenter of each obstacle
config_paramsConfiguration parameters related to mission2 victim computation
void student::RRT_Star_ompl ( const float  x,
const float  y,
const float  theta,
Path path,
std::vector< Point > &  localGoals,
const Polygon borders,
Polygon sampled_borders,
const std::vector< Polygon > &  obstacle_list,
std::vector< double >  obs_radius,
std::vector< Point obs_center,
config_Params_planPath  config_params 
)

implmentation of RRT Star function using OMPL library

This is an RRT Star using OMPL API's.

Parameters
xThe robot location x
yThe robot location y
thetaThe robot orientation theta
paththe output path variable
localGoalsthe local goals which includes the victims and gate
bordersoriginal borders
sampled_bordersthe borders points which are sampled
obstacle_listThe list of obstacle and their points
obs_radiusRadius of each obstacle
obs_centerCenter of each obstacle
config_paramsConfiguration parameters related to mission2 victim computation
Polygon student::sample_borders ( Polygon borders)

Sample the borders with multiple points.

interpolate the border points, to check if generated path is closer to sampled borders

Parameters
bordersborder which is given as polygon
Returns
interpolated border points
bool student::sort_pair ( const std::pair< int, Polygon > &  a,
const std::pair< int, Polygon > &  b 
)
bool student::sort_pair_mission2 ( const std::pair< int, Polygon > &  a,
const std::pair< int, Polygon > &  b 
)
void student::unwarp ( const cv::Mat &  img_in,
cv::Mat &  img_out,
const cv::Mat &  transf,
const std::string &  config_folder 
)

Image unwarping.

Image unwarping using opencv API warpPerspective()

Parameters
img_ininput image
img_outoutput image
transftranformation matrix
config_folderOutput folder (if file existing then function justs reads the file to get rvec and tvec)

Variable Documentation

cv::Mat student::debug_image
cv::Mat student::dist_coeffs_for_ex