00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2013, TU Delft Robotics 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 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of the TU Delft Robotics Institute nor the names 00018 * of its contributors may be used to endorse or promote products 00019 * derived from this software without specific prior written 00020 * permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00023 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00024 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00025 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00026 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00027 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00028 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00029 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00030 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00032 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00033 * POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 * 00036 * Author: G.A. vd. Hoorn - TU Delft Robotics Institute 00037 */ 00038 00039 #include <fanuc_driver/fanuc_utils.h> 00040 00041 #include <industrial_robot_client/robot_state_interface.h> 00042 #include <industrial_utils/param_utils.h> 00043 00044 00045 using industrial_robot_client::robot_state_interface::RobotStateInterface; 00046 using industrial_robot_client::joint_relay_handler::JointRelayHandler; 00047 using industrial_utils::param::getJointNames; 00048 00049 00050 class Fanuc_JointRelayHandler : public JointRelayHandler 00051 { 00052 int J23_factor_; 00053 00054 00055 public: 00056 Fanuc_JointRelayHandler() : JointRelayHandler(), J23_factor_(0) 00057 { 00058 if (ros::param::has("J23_factor")) 00059 { 00060 ros::param::get("J23_factor", this->J23_factor_); 00061 } 00062 else 00063 { 00064 // TODO: abort on missing parameter 00065 ROS_ERROR("Joint 2-3 linkage factor parameter not supplied."); 00066 } 00067 } 00068 00069 00070 virtual ~Fanuc_JointRelayHandler() {} 00071 00072 00073 bool transform(const std::vector<double>& pos_in, std::vector<double>* pos_out) 00074 { 00075 // compensate for J2-J3 coupling in Fanuc manipulator, if required 00076 fanuc::utils::linkage_transform(pos_in, pos_out, J23_factor_); 00077 return true; 00078 } 00079 }; 00080 00081 00082 int main(int argc, char** argv) 00083 { 00084 // initialize node 00085 ros::init(argc, argv, "state_interface"); 00086 00087 // launch the default Robot State Interface connection/handlers 00088 RobotStateInterface rsi; 00089 rsi.init(); 00090 00091 // replace the generic JointRelayHandler with our Fanuc specific one as 00092 // we need to correct the reported joint angles 00093 Fanuc_JointRelayHandler jointHandler; 00094 std::vector<std::string> joint_names; 00095 getJointNames("controller_joint_names", joint_names); 00096 jointHandler.init(rsi.get_connection(), joint_names); 00097 rsi.add_handler(&jointHandler); 00098 00099 // run the node 00100 rsi.run(); 00101 00102 return 0; 00103 }