turtlebot3_manipulation_bringup.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright 2020 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: Ryan Shim */
18 
20 
21 
23 : nh_(""),
24  arm_action_server_(nh_,
25  "arm_controller/follow_joint_trajectory",
26  boost::bind(&Turtlebot3ManipulationBringup::armActionCallback, this, _1),
27  false),
28  gripper_action_server_(nh_,
29  "gripper_controller/follow_joint_trajectory",
30  boost::bind(&Turtlebot3ManipulationBringup::gripperActionCallback, this, _1),
31  false)
32 {
33  // Init Publisher
34  joint_trajectory_point_pub_ = nh_.advertise<std_msgs::Float64MultiArray>("joint_trajectory_point", 10);
35  gripper_pub_ = nh_.advertise<std_msgs::Float64MultiArray>("gripper_position", 10);
36 
37  // Start Server
40 }
41 
43 
44 void Turtlebot3ManipulationBringup::armActionCallback(const control_msgs::FollowJointTrajectoryGoalConstPtr &goal)
45 {
46  trajectory_msgs::JointTrajectory jnt_tra = goal->trajectory;
47  std_msgs::Float64MultiArray jnt_tra_pts;
48 
49  uint32_t jnt_tra_pts_size = jnt_tra.points.size();
50  const uint8_t POINTS_STEP_SIZE = 10;
51  uint32_t steps = floor((double)jnt_tra_pts_size/(double)POINTS_STEP_SIZE);
52 
53  for (uint32_t i = 0; i < jnt_tra_pts_size; i = i + steps)
54  {
55  jnt_tra_pts.data.push_back(jnt_tra.points[i].time_from_start.toSec());
56  for (std::vector<uint32_t>::size_type j = 0; j < jnt_tra.points[i].positions.size(); j++)
57  {
58  jnt_tra_pts.data.push_back(jnt_tra.points[i].positions[j]);
59  }
60  }
62 
64 }
65 
66 void Turtlebot3ManipulationBringup::gripperActionCallback(const control_msgs::FollowJointTrajectoryGoalConstPtr &goal)
67 {
68  trajectory_msgs::JointTrajectory jnt_tra = goal->trajectory;
69  std_msgs::Float64MultiArray jnt_tra_pts;
70 
71  uint32_t jnt_tra_pts_size = jnt_tra.points.size();
72  jnt_tra_pts.data.push_back(jnt_tra.points[jnt_tra_pts_size-1].positions[0]);
73  gripper_pub_.publish(jnt_tra_pts);
74 
76 }
77 
78 int main(int argc, char **argv)
79 {
80  ros::init(argc, argv, "turtlebot3_manipulation_bringup");
81  Turtlebot3ManipulationBringup turtlebot3_manipulation_bringup;
82  ros::spin();
83  return 0;
84 }
void publish(const boost::shared_ptr< M > &message) const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void setSucceeded(const Result &result=Result(), const std::string &text=std::string(""))
actionlib::SimpleActionServer< control_msgs::FollowJointTrajectoryAction > gripper_action_server_
void gripperActionCallback(const control_msgs::FollowJointTrajectoryGoalConstPtr &msg)
int main(int argc, char **argv)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ROSCPP_DECL void spin()
actionlib::SimpleActionServer< control_msgs::FollowJointTrajectoryAction > arm_action_server_
void armActionCallback(const control_msgs::FollowJointTrajectoryGoalConstPtr &msg)


turtlebot3_manipulation_bringup
Author(s): Darby Lim , Ryan Shim
autogenerated on Sun May 10 2020 03:49:14