SetCanvasManually.cpp
Go to the documentation of this file.
00001 #include <ros/ros.h>
00002 #include <iostream>
00003 #include <sstream>
00004 #include <image_transport/image_transport.h>
00005 #include <ee_cart_imped_action/ee_cart_imped_arm.hh>
00006 #include <portrait_painter/SetCanvas.h>
00007 #include <portrait_robot_msgs/alubsc_node_instr.h>
00008 #include <portrait_robot_msgs/alubsc_status_msg.h>
00009 #include <portrait_painter/PainterUtils.h>
00010 #include <tf/tf.h>
00011 
00012 #define CANVAS_OFFSET 0.2
00013 
00014 using namespace portrait_painter;
00015 
00016 int callCounter;
00017 
00018 tf::Point leftUpper;
00019 tf::Point rightUpper;
00020 tf::Point leftLower;
00021 
00022 bool handleInstruction(portrait_robot_msgs::alubsc_node_instr::Request &req,
00023                 portrait_robot_msgs::alubsc_node_instr::Response &res);
00024 
00025 int main(int argc, char **argv) {
00026         ros::init(argc, argv, "PainterCanvasSetter");
00027         ros::NodeHandle n;
00028 
00029         callCounter = 0;
00030         // Initialize Canvas setting service
00031 
00032         ros::ServiceServer instructionServer = n.advertiseService(
00033                         "alubsc/node_instr/manual_canvas_setting", handleInstruction);
00034         ros::spin();
00035 
00036         return 0;
00037 }
00038 
00039 bool handleInstruction(portrait_robot_msgs::alubsc_node_instr::Request &req,
00040                 portrait_robot_msgs::alubsc_node_instr::Response &res) {
00041         ros::NodeHandle n;
00042         ros::ServiceClient msg_client = getMessageClient(n);
00043         ostringstream oss;
00044 
00045         if (req.abort) {
00046                 callCounter = 0;
00047                 return true;
00048         }
00049 
00050         switch (callCounter) {
00051         case 0: {
00052                 sendStatus(
00053                                 "Please move right Gripper to left upper corner of the canvas and click button!",
00054                                 msg_client);
00055 
00056                 moveGripperToInitialPos();
00057                 callCounter++;
00058                 break;
00059         }
00060         case 1:
00061 
00062                 leftUpper = getGripperPosition();
00063 
00064                 oss << setprecision(2) << "Left upper " << leftUpper.x() << ", "
00065                                 << leftUpper.y() << ", " << leftUpper.z();
00066                 sendStatus(oss.str(), msg_client);
00067                 sendStatus(
00068                                 "Please move right Gripper to right upper corner of the canvas and click button!",
00069                                 msg_client);
00070                 callCounter++;
00071                 break;
00072 
00073         case 2:
00074                 rightUpper = getGripperPosition();
00075 
00076                 oss << setprecision(2) << "Right upper " << rightUpper.x() << ", "
00077                                 << rightUpper.y() << ", " << rightUpper.z();
00078                 sendStatus(oss.str(), msg_client);
00079                 sendStatus(
00080                                 "Please move right Gripper to left lower corner of the canvas and click button!",
00081                                 msg_client);
00082                 callCounter++;
00083                 break;
00084         case 3: {
00085                 leftLower = getGripperPosition();
00086 
00087                 oss << setprecision(2) << "Left Lower " << leftLower.x() << ", "
00088                                 << leftLower.y() << ", " << leftLower.z();
00089                 sendStatus(oss.str(), msg_client);
00090                 callCounter++;
00091                 ros::ServiceClient client =
00092                                 n.serviceClient<portrait_painter::SetCanvas>("canvas_setting");
00093                 portrait_painter::SetCanvas req;
00094 
00095                 //Assure aspect ratio of 342x442
00096                 float width = (leftUpper - rightUpper).length();
00097                 float height = (leftUpper - leftLower).length();
00098                 //shorten the vector that is too long
00099                 float desired_ratio = 342.0 / 442.0;
00100                 if (width / height > desired_ratio) { //shorten width
00101                         tf::Point unit_right = (rightUpper - leftUpper);
00102                         unit_right.normalize();
00103                         rightUpper = leftUpper + unit_right * (height * desired_ratio);
00104                 } else if (width / height < desired_ratio) { //shorten height
00105                         tf::Point unit_down = (leftLower - leftUpper);
00106                         unit_down.normalize();
00107                         leftLower = leftUpper + unit_down * (width / desired_ratio);
00108                 }
00109 
00110                 tf::pointTFToMsg(leftUpper, req.request.leftUpper);
00111                 tf::pointTFToMsg(rightUpper, req.request.rightUpper);
00112                 tf::pointTFToMsg(leftLower, req.request.leftLower);
00113 
00114                 client.call(req);
00115 
00116                 callCounter = 0;
00117                 break;
00118         }
00119         default:
00120                 break;
00121         }
00122         return true;
00123 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


portrait_painter
Author(s): Niklas Meinzer, Ina Baumgarten
autogenerated on Wed Dec 26 2012 16:00:43