00001 //============================================================================ 00002 // Name : jaco_arm_driver.cpp 00003 // Author : WPI, Clearpath Robotics 00004 // Version : 0.5 00005 // Copyright : BSD 00006 // Description : A ROS driver for controlling the Kinova Jaco robotic manipulator arm 00007 //============================================================================ 00008 00009 00010 #include "jaco_driver/jaco_arm.h" 00011 #include "jaco_driver/jaco_pose_action.h" 00012 #include "jaco_driver/jaco_angles_action.h" 00013 #include "jaco_driver/jaco_fingers_action.h" 00014 00015 float get_xmlrpc_value(XmlRpc::XmlRpcValue &value) 00016 { 00017 if (value.getType() == XmlRpc::XmlRpcValue::TypeDouble) 00018 { 00019 return static_cast<double>(value); 00020 } 00021 else if (value.getType() == XmlRpc::XmlRpcValue::TypeInt) 00022 { 00023 return (float) static_cast<int>(value); 00024 } 00025 00026 throw std::string("Parameter 'home_position' must contain only numerical values"); 00027 return 0.0; 00028 } 00029 00030 jaco::JacoAngles get_home_position(ros::NodeHandle &nh) 00031 { 00032 std::string key; 00033 jaco::JacoAngles home; 00034 00035 //if (nh.searchParam("~home_position", key)) 00036 if (ros::param::has("~home_position")) 00037 { 00038 XmlRpc::XmlRpcValue joints_list; 00039 ros::param::get("~home_position", joints_list); 00040 ROS_ASSERT(joints_list.getType() == XmlRpc::XmlRpcValue::TypeArray); 00041 ROS_ASSERT(joints_list.size() == 6); 00042 00043 try 00044 { 00045 home.Actuator1 = get_xmlrpc_value(joints_list[0]); 00046 home.Actuator2 = get_xmlrpc_value(joints_list[1]); 00047 home.Actuator3 = get_xmlrpc_value(joints_list[2]); 00048 home.Actuator4 = get_xmlrpc_value(joints_list[3]); 00049 home.Actuator5 = get_xmlrpc_value(joints_list[4]); 00050 home.Actuator6 = get_xmlrpc_value(joints_list[5]); 00051 00052 return home; 00053 } 00054 catch (std::string msg) 00055 { 00056 ROS_ERROR("%s", msg.c_str()); 00057 // use default home from below 00058 } 00059 } 00060 00061 // typical home position for a "right-handed" arm 00062 home.Actuator1 = 282.8; 00063 home.Actuator2 = 154.4; 00064 home.Actuator3 = 43.1; 00065 home.Actuator4 = 230.7; 00066 home.Actuator5 = 83.0; 00067 home.Actuator6 = 78.1; 00068 00069 return home; 00070 } 00071 00072 int main(int argc, char **argv) 00073 { 00074 /* Set up ROS */ 00075 ros::init(argc, argv, "jaco_arm_driver"); 00076 ros::NodeHandle nh; 00077 00078 jaco::JacoComm comm(get_home_position(nh)); 00079 00080 ROS_INFO("Initializing the Arm"); 00081 00082 comm.HomeArm(); 00083 comm.InitializeFingers(); 00084 00085 //create the arm object 00086 jaco::JacoArm jaco(comm, nh); 00087 jaco::JacoPoseActionServer pose_server(comm, nh); 00088 jaco::JacoAnglesActionServer angles_server(comm, nh); 00089 jaco::JacoFingersActionServer fingers_server(comm, nh); 00090 00091 ros::spin(); 00092 } 00093