cob_obstacle_distance.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
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 #include <ctime>
19 #include <vector>
20 #include <ros/ros.h>
21 #include <fcl/shape/geometric_shapes.h>
22 #include <fstream>
23 #include <thread>
24 
28 
29 
31 
32 
33 int main(int argc, char** argv)
34 {
35  ros::init(argc, argv, "cob_obstacle_distance");
36  ros::NodeHandle nh;
37  DistanceManager sm(nh);
38 
39  if (0 != sm.init())
40  {
41  ROS_ERROR("Failed to initialize DistanceManager.");
42  return -4;
43  }
44 
45  // addTestObstacles(sm); // Comment in to see what happens
46 
47  std::thread t(&DistanceManager::transform, std::ref(sm));
48  ros::Duration(1.0).sleep(); // Give some time for threads to run
49  ROS_INFO_STREAM("Started transform thread.");
50 
51  ros::Subscriber jointstate_sub = nh.subscribe("joint_states", 1, &DistanceManager::jointstateCb, &sm);
52  ros::Subscriber obstacle_sub = nh.subscribe("obstacle_distance/registerObstacle", 1, &DistanceManager::registerObstacle, &sm);
53  ros::ServiceServer registration_srv = nh.advertiseService("obstacle_distance/registerLinkOfInterest" , &DistanceManager::registerLinkOfInterest, &sm);
54 
55  ros::Rate loop_rate(20);
56  while (ros::ok())
57  {
58  sm.calculate();
59  ros::spinOnce();
60  loop_rate.sleep();
61  }
62 
63  return 0;
64 }
65 
66 
72 {
73  fcl::Sphere s(0.1);
74  fcl::Box b(0.1, 0.1, 0.1); // Take care the nearest point for collision is one of the eight corners!!! This might lead to jittering
75 
77  "package://cob_gazebo_objects/Media/models/milk.dae",
78  -0.35,
79  -0.35,
80  0.8));
81 
82  PtrIMarkerShape_t sptr_Sphere(new MarkerShape<fcl::Sphere>(dm.getRootFrame(), s, 0.35, -0.35, 0.8));
83 
84  dm.addObstacle("Funny Sphere", sptr_Sphere);
85  dm.addObstacle("Funny Mesh", sptr_Bvh);
86 
87  ROS_INFO_ONCE("Subscriber to the marker has been created");
88  dm.drawObstacles();
89 }
void addObstacle(const std::string &id, PtrIMarkerShape_t s)
int main(int argc, char **argv)
std::shared_ptr< IMarkerShape > PtrIMarkerShape_t
const std::string getRootFrame() const
#define ROS_INFO_ONCE(...)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
XmlRpcServer s
bool sleep() const
void jointstateCb(const sensor_msgs::JointState::ConstPtr &msg)
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)
Template class implementation for box, sphere and cylinder fcl::shapes. Creates visualization marker...
geometry_msgs::TransformStamped t
bool registerLinkOfInterest(cob_srvs::SetString::Request &request, cob_srvs::SetString::Response &response)
ROSCPP_DECL bool ok()
bool sleep()
#define ROS_INFO_STREAM(args)
void addTestObstacles(DistanceManager &dm)
void registerObstacle(const moveit_msgs::CollisionObject::ConstPtr &msg)
ROSCPP_DECL void spinOnce()
#define ROS_ERROR(...)


cob_obstacle_distance
Author(s): Marco Bezzon
autogenerated on Thu Apr 8 2021 02:39:47