coordConversion.cpp
Go to the documentation of this file.
00001 
00010 #include <youbot_overhead_vision/coordConversion.h>
00011 
00012 coordConversion::coordConversion()
00013 {
00014   conversionService = n.advertiseService("coord_conversion", &coordConversion::convertCoordinates, this);
00015 
00016   n.getParam("/image_calibration/runFromSimulation", useSim);
00017 }
00018 
00019 bool coordConversion::convertCoordinates(youbot_overhead_vision::CoordConversion::Request &req,
00020                                          youbot_overhead_vision::CoordConversion::Response &res)
00021 {
00022   float x = req.x;
00023   float y = req.y;
00024   int type = req.type;
00025 
00026   if (type == PIXEL_TO_METER)
00027   {
00028     if (useSim)
00029     {
00030       res.xConverted = x * SIM_M + SIM_X_B;
00031       res.yConverted = y * SIM_M + SIM_Y_B;
00032     }
00033     else
00034     {
00035       res.xConverted = x * REAL_M + REAL_X_B;
00036       res.yConverted = y * REAL_M + REAL_Y_B;
00037     }
00038   }
00039   else if (type == METER_TO_PIXEL)
00040   {
00041     if (useSim)
00042     {
00043       res.xConverted = (x - SIM_X_B) / SIM_M;
00044       res.yConverted = (y - SIM_Y_B) / SIM_M;
00045     }
00046     else
00047     {
00048       res.xConverted = (x - REAL_X_B) / REAL_M;
00049       res.yConverted = (y - REAL_Y_B) / REAL_M;
00050     }
00051   }
00052   else if (type == OCC_GRID_TO_METER)
00053   {
00054     if (useSim)
00055     {
00056       res.xConverted = x / OCC_GRID_REDUCTION * SIM_M + SIM_X_B;
00057       res.yConverted = y / OCC_GRID_REDUCTION * SIM_M + SIM_Y_B;
00058     }
00059     else
00060     {
00061       res.xConverted = x / OCC_GRID_REDUCTION * REAL_M + REAL_X_B;
00062       res.yConverted = y / OCC_GRID_REDUCTION * REAL_M + REAL_Y_B;
00063     }
00064   }
00065   else //invalid conversion type
00066   {
00067     res.xConverted = req.x;
00068     res.yConverted = req.y;
00069   }
00070 
00071   return true;
00072 }
00073 
00077 int main(int argc, char **argv)
00078 {
00079   ros::init(argc, argv, "coordinate_converter");
00080 
00081   coordConversion converter;
00082 
00083   ros::spin();
00084 
00085   return 0;
00086 }
00087 


youbot_overhead_vision
Author(s): Fred Clinckemaillie, Maintained by David Kent
autogenerated on Thu Jan 2 2014 12:14:12