grasp_test_utility.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2013 Southwest Research Institute
00003 
00004    Licensed under the Apache License, Version 2.0 (the "License");
00005    you may not use this file except in compliance with the License.
00006    You may obtain a copy of the License at
00007 
00008      http://www.apache.org/licenses/LICENSE-2.0
00009 
00010    Unless required by applicable law or agreed to in writing, software
00011    distributed under the License is distributed on an "AS IS" BASIS,
00012    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013    See the License for the specific language governing permissions and
00014    limitations under the License.
00015  */
00016 
00017 
00018 #include <simple_message/smpl_msg_connection.h>
00019 #include <simple_message/simple_message.h>
00020 #include <simple_message/socket/tcp_client.h>
00021 #include <mtconnect_grasp_action/gripper_message.h>
00022 #include <iostream>
00023 #include <sstream>
00024 using namespace std;
00025 using namespace industrial::smpl_msg_connection;
00026 using namespace industrial::simple_message;
00027 using namespace mtconnect_cnc_robot_example::gripper_message;
00028 
00029 
00030 int main(int argc, char** argv)
00031 {
00032         std::string ip_address;
00033         int port_number;
00034         std::stringstream ss;
00035         
00036         if(argc == 3)  // expects ip_address and port_number
00037         {
00038 
00039                 // parsing arguments
00040                 ip_address = std::string(argv[1]);
00041                 ss<<argv[2];
00042                 if(!(ss >> port_number))
00043                 {
00044                         ROS_ERROR("Could not read port number, usage: grasp_utility <robot ip address> <port number>");
00045                 }
00046                 else
00047                 {
00048                         ROS_INFO("Grasp action connecting to IP address: %s and port: %i", ip_address.c_str(),port_number);
00049                         industrial::tcp_client::TcpClient robot;
00050                         robot.init(const_cast<char*>(ip_address.c_str()), port_number);
00051                         if(!robot.makeConnect())
00052                         {
00053                                 ROS_ERROR_STREAM("Failed to connect, exiting");
00054                                 return 0;
00055                         }
00056 
00057                         cout << "Grasp client connected" << endl;;
00058 
00059                         int i = 0;
00060                         while (true)
00061                         {
00062                           cout << "Grasp Utility" << endl
00063                                  << "1. INIT" << endl
00064                                  << "2. CLOSE" << endl
00065                                  << "3. OPEN" << endl;
00066                           cin >> i;
00067 
00068                           GripperMessage gMsg;
00069                           SimpleMessage request;
00070                           SimpleMessage reply;
00071 
00072                           switch(i)
00073                           {
00074                           case 1:
00075                                   gMsg.init(GripperOperationTypes::INIT);
00076                                   gMsg.toRequest(request);
00077                                   robot.sendAndReceiveMsg(request, reply);
00078                                   cout << "Gripper initialized" << endl;
00079                             break;
00080 
00081                           case 2:
00082                             gMsg.init(GripperOperationTypes::CLOSE);
00083                             gMsg.toRequest(request);
00084                             cout << "Message length: " << request.getMsgLength() << endl;
00085                             robot.sendAndReceiveMsg(request, reply);
00086                             cout << "Gripper closed" << endl;
00087                             break;
00088 
00089                           case 3:
00090                             gMsg.init(GripperOperationTypes::OPEN);
00091                             gMsg.toRequest(request);
00092                             robot.sendAndReceiveMsg(request, reply);
00093                             cout << "Gripper opened" << endl;
00094                             break;
00095 
00096                           default:
00097                             return 0;
00098                           }
00099                         }
00100                 }
00101         }
00102         else
00103         {
00104                 ROS_ERROR("Missing command line arguments, usage: grasp_utility <robot ip address>< port number>");
00105         }
00106 
00107   return 0;
00108 }
00109 
00110 
00111 
00112 


mtconnect_grasp_action
Author(s): Shaun M. Edwards
autogenerated on Mon Jan 6 2014 11:31:10