gripper_server.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright 2018 ROBOTIS CO., LTD.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *******************************************************************************/
16 
17 /* Authors: Darby Lim */
18 
19 #include <ros/ros.h>
20 #include <open_manipulator_msgs/SetJointPosition.h>
21 #include <std_msgs/Float64.h>
22 #include <std_msgs/Float64MultiArray.h>
23 
26 
27 bool gripperCallback(open_manipulator_msgs::SetJointPosition::Request &req,
28  open_manipulator_msgs::SetJointPosition::Response &res)
29 {
30  std_msgs::Float64 position;
31  position.data = req.joint_position.position.at(0);
32 
33  std_msgs::Float64MultiArray position_array;
34  position_array.data.push_back(position.data);
35 
36  gazebo_gripper_pub_.publish(position);
37  platform_gripper_pub_.publish(position_array);
38 
39  res.is_planned = true;
40 
41  return true;
42 }
43 
45 {
46  platform_gripper_pub_ = nh.advertise<std_msgs::Float64MultiArray>("gripper_position", 10);
47  gazebo_gripper_pub_ = nh.advertise<std_msgs::Float64>("gripper_position/command", 10);
48 }
49 
51 {
52  gripper_server_ = nh.advertiseService("gripper", gripperCallback);
53 }
54 
55 int main(int argc, char **argv)
56 {
57  ros::init(argc, argv, "gripper_server");
58  ros::NodeHandle node_handle("");
59 
60  initPublisher(node_handle);
61  initServer(node_handle);
62 
63  ros::spin();
64  return 0;
65 }
void publish(const boost::shared_ptr< M > &message) const
int main(int argc, char **argv)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
void initPublisher(ros::NodeHandle nh)
ROSCPP_DECL void spin(Spinner &spinner)
bool gripperCallback(open_manipulator_msgs::SetJointPosition::Request &req, open_manipulator_msgs::SetJointPosition::Response &res)
ros::ServiceServer gripper_server_
ros::Publisher platform_gripper_pub_
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void initServer(ros::NodeHandle nh)
ros::Publisher gazebo_gripper_pub_


open_manipulator_with_tb3_tools
Author(s): Darby Lim
autogenerated on Thu Sep 10 2020 03:52:23