mp_default_main.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  * Copyright (c) 2011, Southwest Research Institute
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions are met:
00009  *
00010  *      * Redistributions of source code must retain the above copyright
00011  *      notice, this list of conditions and the following disclaimer.
00012  *      * Redistributions in binary form must reproduce the above copyright
00013  *      notice, this list of conditions and the following disclaimer in the
00014  *      documentation and/or other materials provided with the distribution.
00015  *      * Neither the name of the Southwest Research Institute, nor the names
00016  *      of its contributors may be used to endorse or promote products derived
00017  *      from this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00020  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00021  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00022  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00023  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00024  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00025  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00026  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00027  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00028  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00029  * POSSIBILITY OF SUCH DAMAGE.
00030  */
00031 
00032 #include "controller.h"
00033 #include "mp_default_main.h"
00034 #include "log_wrapper.h"
00035 #include "tcp_server.h"
00036 #include "message_manager.h"
00037 #include "input_handler.h"
00038 #include "joint_motion_handler.h"
00039 #include "joint_data.h"
00040 #include "joint_message.h"
00041 #include "robot_status.h"
00042 #include "robot_status_message.h"
00043 #include "simple_message.h"
00044 #include "ros_conversion.h"
00045 
00046 #include "motoPlus.h"
00047 
00048 
00049 namespace motoman
00050 {
00051 namespace mp_default_main
00052 {
00053 
00054 void motionServer(void)
00055 // Persistent TCP server that receives motion messages from Motoros node (ROS interface) and relays to parseMotionMessage
00056 {
00057 
00058     using namespace industrial::simple_socket;
00059     using namespace industrial::tcp_server;
00060     using namespace industrial::message_manager;
00061     using namespace industrial::simple_message;
00062     using namespace motoman::joint_motion_handler;
00063   
00064     TcpServer connection;
00065     JointMotionHandler jmHandler;
00066     
00067     MessageManager manager;
00068     
00069     connection.init(StandardSocketPorts::MOTION);
00070     
00071 
00072     connection.makeConnect();
00073     
00074     manager.init(&connection);
00075     
00076     jmHandler.init(StandardMsgTypes::JOINT, &connection);
00077     manager.add(&jmHandler);
00078     manager.spin();
00079 
00080 
00081 }
00082 
00083 
00084 void systemServer(void)
00085 // Persistent TCP server that receives system messages from Motoros node (ROS interface) and relays to parseSystemMessage
00086 {
00087 
00088     using namespace industrial::simple_socket;
00089     using namespace industrial::tcp_server;
00090     using namespace industrial::message_manager;
00091     
00092     TcpServer connection;
00093     MessageManager manager;
00094     
00095     connection.init(StandardSocketPorts::SYSTEM);
00096     connection.makeConnect();
00097     
00098     manager.init(&connection);
00099     manager.spin();
00100 
00101 }
00102 
00103 
00104 
00105 void stateServer(void)
00106 {
00107     using motoman::controller::Controller;
00108     using namespace industrial::simple_socket;
00109     using namespace industrial::tcp_server;
00110     using namespace industrial::joint_message;
00111     using namespace industrial::joint_data;
00112     using namespace industrial::robot_status;
00113     using namespace industrial::robot_status_message;
00114     using namespace industrial::simple_message;
00115     using namespace motoman::ros_conversion;
00116     
00117     // Using TPC server for debugging (this should really be UDP)
00118     TcpServer connection;
00119     
00120     JointData rosJoints;
00121     JointMessage msg;
00122     
00123     RobotStatus status;
00124     RobotStatusMessage statusMsg;
00125     
00126     SimpleMessage simpMsg;
00127     Controller controller;
00128     float mpJoints[MAX_PULSE_AXES];
00129     
00130     const int period = 100; //ticks
00131     
00132     connection.init(StandardSocketPorts::STATE);
00133     
00134     FOREVER
00135     {
00136       connection.makeConnect();
00137       
00138       while(connection.isConnected())
00139       {
00140         controller.getActJointPos(mpJoints);
00141         toRosJoint(mpJoints, rosJoints);
00142         msg.init(0, rosJoints);
00143         msg.toTopic(simpMsg);
00144         connection.sendMsg(simpMsg);
00145         
00146         controller.getStatus(status);
00147         statusMsg.init(status);
00148         statusMsg.toTopic(simpMsg);
00149         connection.sendMsg(simpMsg);
00150         
00151         mpTaskDelay(period);
00152         
00153         
00154       }
00155       
00156 
00157     }
00158 
00159 }
00160 
00161 
00162 
00163 void ioServer(void)
00164 {
00165 /*
00166 
00167     using namespace industrial::simple_socket;
00168     using namespace industrial::tcp_server;
00169     using namespace industrial::message_manager;
00170     using namespace industrial::simple_message;
00171     using namespace motoman::input_handler;
00172     
00173     TcpServer connection;
00174     InputHandler iHandler;
00175     MessageManager manager;
00176     
00177     connection.init(StandardSocketPorts::IO);
00178     connection.makeConnect();
00179     
00180     manager.init(&connection);
00181     
00182     iHandler.init(StandardMsgTypes::WRITE_OUTPUT, &connection);
00183     manager.add(&iHandler);
00184     manager.spin();
00185  */
00186 
00187     
00188 }
00189 
00190 
00191 } //mp_wrapper
00192 } //motoman


dx100
Author(s): Shaun Edwards (Southwest Research Institute)
autogenerated on Mon Oct 6 2014 02:25:33