thormang3_rviz_pub.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 /*
18  * thormang3_rviz_pub.cpp
19  *
20  * Created on: Jul 11, 2015
21  * Author: SCH
22  */
23 
24 #include <ros/ros.h>
25 #include <sensor_msgs/JointState.h>
26 
29 
30 void presentJointStatesCallback(const sensor_msgs::JointState::ConstPtr& msg)
31 {
32  sensor_msgs::JointState present_msg;
33 
34  for (int index = 0; index < msg->name.size(); index++)
35  {
36  present_msg.name.push_back(msg->name[index]);
37  present_msg.position.push_back(msg->position[index]);
38 
39  if (present_msg.name[index] == "l_arm_grip")
40  {
41  present_msg.name.push_back("l_arm_grip_1");
42  present_msg.position.push_back(present_msg.position[index]);
43  }
44 
45  if (present_msg.name[index] == "r_arm_grip")
46  {
47  present_msg.name.push_back("r_arm_grip_1");
48  present_msg.position.push_back(present_msg.position[index]);
49  }
50  }
51  g_present_joint_states_pub.publish(present_msg);
52 }
53 
54 void goalJointStatesCallback(const sensor_msgs::JointState::ConstPtr& msg)
55 {
56  sensor_msgs::JointState goal_msg;
57 
58  for (int index = 0; index < msg->name.size(); index++)
59  {
60  goal_msg.name.push_back(msg->name[index]);
61  goal_msg.position.push_back(msg->position[index]);
62 
63  if (goal_msg.name[index] == "l_arm_grip")
64  {
65  goal_msg.name.push_back("l_arm_grip_1");
66  goal_msg.position.push_back(goal_msg.position[index]);
67  }
68 
69  if (goal_msg.name[index] == "r_arm_grip")
70  {
71  goal_msg.name.push_back("r_arm_grip_1");
72  goal_msg.position.push_back(goal_msg.position[index]);
73  }
74  }
75  g_goal_joint_states_pub.publish(goal_msg);
76 }
77 
78 int main(int argc, char **argv)
79 {
80  ros::init(argc, argv, "thormang3_rviz_publisher");
81  ros::NodeHandle nh("~");
82 
83  g_present_joint_states_pub = nh.advertise<sensor_msgs::JointState>("/robotis/thormang3/present_joint_states", 0);
84  g_goal_joint_states_pub = nh.advertise<sensor_msgs::JointState>("/robotis/thormang3/goal_joint_states", 0);
85 
86  ros::Subscriber present_joint_states_sub = nh.subscribe("/robotis/present_joint_states", 5, presentJointStatesCallback);
87  ros::Subscriber goal_joint_states_sub = nh.subscribe("/robotis/goal_joint_states", 5, goalJointStatesCallback);
88 
89  ros::spin();
90 
91  return 0;
92 }
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void presentJointStatesCallback(const sensor_msgs::JointState::ConstPtr &msg)
void goalJointStatesCallback(const sensor_msgs::JointState::ConstPtr &msg)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ROSCPP_DECL void spin(Spinner &spinner)
ros::Publisher g_goal_joint_states_pub
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
int main(int argc, char **argv)
ros::Publisher g_present_joint_states_pub


thormang3_description
Author(s): SCH , Kayman
autogenerated on Mon Jun 10 2019 15:35:01