cob_obstacle_distance.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *   http://www.apache.org/licenses/LICENSE-2.0
00009 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 
00018 #include <ctime>
00019 #include <vector>
00020 #include <ros/ros.h>
00021 #include <fcl/shape/geometric_shapes.h>
00022 #include <fstream>
00023 #include <thread>
00024 
00025 #include "cob_obstacle_distance/obstacle_distance_data_types.hpp"
00026 #include "cob_obstacle_distance/distance_manager.hpp"
00027 #include "cob_obstacle_distance/marker_shapes/marker_shapes.hpp"
00028 
00029 
00030 void addTestObstacles(DistanceManager& dm);
00031 
00032 
00033 int main(int argc, char** argv)
00034 {
00035     ros::init(argc, argv, "cob_obstacle_distance");
00036     ros::NodeHandle nh;
00037     DistanceManager sm(nh);
00038 
00039     if (0 != sm.init())
00040     {
00041         ROS_ERROR("Failed to initialize DistanceManager.");
00042         return -4;
00043     }
00044 
00045     // addTestObstacles(sm);  // Comment in to see what happens
00046 
00047     std::thread t(&DistanceManager::transform, std::ref(sm));
00048     ros::Duration(1.0).sleep();  // Give some time for threads to run
00049     ROS_INFO_STREAM("Started transform thread.");
00050 
00051     ros::Subscriber jointstate_sub = nh.subscribe("joint_states", 1, &DistanceManager::jointstateCb, &sm);
00052     ros::Subscriber obstacle_sub = nh.subscribe("obstacle_distance/registerObstacle", 1, &DistanceManager::registerObstacle, &sm);
00053     ros::ServiceServer registration_srv = nh.advertiseService("obstacle_distance/registerLinkOfInterest" , &DistanceManager::registerLinkOfInterest, &sm);
00054 
00055     ros::Rate loop_rate(20);
00056     while (ros::ok())
00057     {
00058         sm.calculate();
00059         ros::spinOnce();
00060         loop_rate.sleep();
00061     }
00062 
00063     return 0;
00064 }
00065 
00066 
00071 void addTestObstacles(DistanceManager& dm)
00072 {
00073     fcl::Sphere s(0.1);
00074     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
00075 
00076     PtrIMarkerShape_t sptr_Bvh(new MarkerShape<BVH_RSS_t>(dm.getRootFrame(),
00077                                                           "package://cob_gazebo_objects/Media/models/milk.dae",
00078                                                            -0.35,
00079                                                            -0.35,
00080                                                             0.8));
00081 
00082     PtrIMarkerShape_t sptr_Sphere(new MarkerShape<fcl::Sphere>(dm.getRootFrame(), s, 0.35, -0.35, 0.8));
00083 
00084     dm.addObstacle("Funny Sphere", sptr_Sphere);
00085     dm.addObstacle("Funny Mesh", sptr_Bvh);
00086 
00087     ROS_INFO_ONCE("Subscriber to the marker has been created");
00088     dm.drawObstacles();
00089 }


cob_obstacle_distance
Author(s): Marco Bezzon
autogenerated on Thu Jun 6 2019 21:19:14