R2RosGripper.cpp
Go to the documentation of this file.
00001 /**************************************************************************
00002 ** Copyright (c) 2015 United States Government as represented by the
00003 ** National Aeronotics and Space Administration.  All Rights Reserved
00004 **
00005 ** Author: Allison Thackston
00006 ** Created: 20 Feb 2015
00007 **
00008 ** Developed jointly by NASA/JSC and Oceaneering Space Systems
00009 **
00010 ** Licensed under the NASA Open Source Agreement v1.3 (the "License");
00011 ** you may not use this file except in compliance with the License.
00012 ** You may obtain a copy of the License at
00013 **
00014 **     http://opensource.org/licenses/NASA-1.3
00015 **
00016 ** Unless required by applicable law or agreed to in writing, software
00017 ** distributed under the License is distributed on an "AS IS" BASIS,
00018 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00019 ** See the License for the specific language governing permissions and
00020 ** limitations under the License.
00021 **************************************************************************/
00022 
00023 #include "robodyn_ros/R2RosGripper.hpp"
00024 
00025 R2RosGripper::R2RosGripper(ros::NodeHandle& nh)
00026 {
00027     this->nh = nh;
00028 
00029     gripperCmdIn = nh.subscribe("gripper_cmd", 10, &R2RosGripper::gripperCmdCallback, this);
00030 
00031     gripperCmdOut = nh.advertise<r2_msgs::JointTrajectoryReplan>("joint_refs", 1);
00032     gripperSettingsOut = nh.advertise<r2_msgs::ControllerJointSettings>("joint_ref_settings", 1, true);
00033 }
00034 
00035 void R2RosGripper::configure(std::vector<std::string> names, double velocity, double acceleration)
00036 {
00037     r2_msgs::ControllerJointSettings settings;
00038     settings.joint_names = names;
00039     settings.jointVelocityLimits.resize(names.size());
00040     settings.jointAccelerationLimits.resize(names.size());
00041 
00042     for (unsigned int i = 0; i < names.size(); ++i)
00043     {
00044         settings.jointVelocityLimits[i] = velocity;
00045         settings.jointAccelerationLimits[i] = acceleration;
00046     }
00047 
00048     gripperSettingsOut.publish(settings);
00049 }
00050 
00051 void R2RosGripper::gripperCmdCallback(const r2_msgs::GripperPositionCommand& msg)
00052 {
00053     ROS_INFO("in gripper_cmd callback");
00054     r2_msgs::JointTrajectoryReplan gripperCmd;
00055     trajectory_msgs::JointTrajectory gripperTraj;
00056     gripperTraj.joint_names = msg.name;
00057     gripperTraj.header = msg.header;
00058 
00059     trajectory_msgs::JointTrajectoryPoint point;
00060     point.positions.resize(msg.name.size());
00061     point.velocities.resize(msg.name.size());
00062     point.accelerations.resize(msg.name.size());
00063     point.time_from_start = ros::Duration(0.1);
00064 
00065     for (unsigned int i = 0; i < msg.name.size(); ++i)
00066     {
00067         ROS_INFO("name: %s", msg.name[i].c_str());
00068         ROS_INFO("command: %s", msg.command[i].c_str());
00069         ROS_INFO("setpoint: %s", msg.setpoint[i].c_str());
00070 
00071         if (msg.command[i] == "set")
00072         {
00073             if (msg.setpoint[i] == "closed")
00074             {
00075                 ROS_INFO("setting position closed");
00076                 point.positions[i] = 0;
00077             }
00078             else if (msg.setpoint[i] == "seattrack")
00079             {
00080                 ROS_INFO("setting position seattrack");
00081                 point.positions[i] = 0.15;
00082             }
00083 
00084         }
00085         else if (msg.command[i] == "lock")
00086         {
00087             ROS_INFO("setting lock");
00088             point.positions[i] = -0.1;
00089         }
00090         else if (msg.command[i] == "release")
00091         {
00092             ROS_INFO("setting release");
00093             point.positions[i] = 0.5;
00094         }
00095         else
00096         {
00097             return;
00098         }
00099     }
00100 
00101     gripperTraj.points.push_back(point);
00102     gripperTraj.header.frame_id = "gripper_cmd";
00103     gripperCmd.trajectory = gripperTraj;
00104     gripperCmd.header = gripperTraj.header;
00105     gripperCmdOut.publish(gripperCmd);
00106 }


robodyn_ros
Author(s):
autogenerated on Thu Jun 6 2019 18:14:39