trajectory_executive.cpp
Go to the documentation of this file.
1 /**************************************************************************************************
2  Software License Agreement (BSD License)
3 
4  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted
8  provided that the following conditions are met:
9 
10  *Redistributions of source code must retain the above copyright notice, this list of
11  conditions and the following disclaimer.
12  *Redistributions in binary form must reproduce the above copyright notice, this list of
13  conditions and the following disclaimer in the documentation and/or other materials provided
14  with the distribution.
15  *Neither the name of the University of Aveiro nor the names of its contributors may be used to
16  endorse or promote products derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***************************************************************************************************/
27 #ifndef _traj_executor_CPP_
28 #define _traj_executor_CPP_
29 
38 //Includes
39 #include <ros/ros.h>
42 #include <atlasmv_base/AtlasmvStatus.h>
43 #include <atlasmv_base/AtlasmvMotionCommand.h>
44 #include <pcl/conversions.h>
45 #include <pcl/point_cloud.h>
46 #include <pcl/point_types.h>
47 #include <math.h>
48 #include <boost/lexical_cast.hpp>
49 #include <boost/format.hpp>
50 #include <trajectory_planner/traj_info.h>
51 
52 // Global vars
53 ros::Publisher commandPublisher;
54 trajectory_planner::traj_info info;
55 atlasmv_base::AtlasmvMotionCommand command;
56 ros::NodeHandle* p_n;
57 double dist_init;
58 atlasmv_base::AtlasmvStatus base_status;
59 
60 
67 void send_command_message(int current_node)
68 {
69  if(current_node != -1 && static_cast<int>(info.alpha.size())>current_node)
70  {
71  command.dir=info.alpha[current_node];
72  command.speed= info.speed[current_node];
73  command.lifetime=INFINITY;
74  command.priority=2;
75  std::cout<<"DIR -> "<<command.dir<<std::endl;
76  std::cout<<"SPEED -> "<<command.speed<<std::endl;
77  }
78  else
79  {
80  command.dir=0.0;
81  command.speed=0.0;
82  command.lifetime=INFINITY;
83  command.priority=2;
84  }
85  command.header.stamp=ros::Time::now();
86  commandPublisher.publish(command);
87  struct timeval tv;
88  struct timezone tz;
89  struct tm *tm;
90  gettimeofday(&tv, &tz);
91  tm=localtime(&tv.tv_sec);
92  printf("Tempooexec %d:%02d:%02d %d \n", tm->tm_hour, tm->tm_min,
93  tm->tm_sec, tv.tv_usec);
94 }
95 
96 
104 bool jump_node(double dist_init,int node)
105 {
106  if(node!=-1 && static_cast<int>(info.arc.size())>node)
107  {
108  if(info.arc[node]>0)
109  {
110  if(info.total_arc[node] <= (base_status.distance_traveled-dist_init))
111  {
112  return true;
113  }
114  }
115  else
116  {
117  if(info.total_arc[node] >= (base_status.distance_traveled-dist_init))
118  {
119  return true;
120  }
121  }
122  }
123  return false;
124 }
125 
126 
132 void StatusMessageHandler(const atlasmv_base::AtlasmvStatus& msg)
133 {
134  base_status=msg;
135 }
136 
137 
143 void Info_handler(const trajectory_planner::traj_info& msg)
144 {
145  info=msg;
146  dist_init= base_status.distance_traveled;
147 // cout<<"DISTANCE TRAVELED "<< dist_init<<endl;
148 }
149 
150 
158 int main(int argc, char **argv)
159 {
160  ros::init(argc, argv, "trajectory_executor_nodelet");
161  ros::NodeHandle n("~");
162  p_n=&n;
163 
164  //Define the publishers and subscribers
165  ros::Subscriber subscribe_traj_info = n.subscribe ("/trajectory_information", 1, Info_handler);
166  ros::Subscriber subscribeStatusMessages = n.subscribe ("/atlasmv/base/status", 1, StatusMessageHandler);
167  ros::Rate loop_rate(10);
168 
169  // Follow chosen trajectory
170  commandPublisher = n.advertise<atlasmv_base::AtlasmvMotionCommand>("/atlasmv/base/motion", 1);
171  int node=0;
172 
173  while(ros::ok())
174  {
175  loop_rate.sleep();
176  ros::spinOnce();
177 
178  if(info.arc.size()==0)
179  continue;
180 
181  // ___________________________________
182  // | |
183  // | Trajectory execution |
184  // |_________________________________|
185 
186  bool jump_to_next_node = jump_node(dist_init,node);
187  if(jump_to_next_node)
188  {
189  if(node==static_cast<int>((info.arc.size()-1)))
190  {
191  node=-1;
192  }
193  else
194  {
195  node++;
196  }
197  }
198 // cout<<"NODE "<<node<<" distance "<<base_status.distance_traveled<<endl;
199 
200  send_command_message(node);
201 
202  }
203 }
204 #endif
bool jump_node(double dist_init, int node)
Determines if the robot is already on the following node.
ros::Publisher commandPublisher
ros::NodeHandle * p_n
class which evaluates the trajectories planned
class which generates a few number of trajectories from an input file
double dist_init
trajectory_planner::traj_info info
void Info_handler(const trajectory_planner::traj_info &msg)
void send_command_message(int current_node)
Callback of published message.
int main(int argc, char **argv)
Main code of the nodelet.
atlasmv_base::AtlasmvMotionCommand command
void StatusMessageHandler(const atlasmv_base::AtlasmvStatus &msg)
Define message status.
atlasmv_base::AtlasmvStatus base_status


trajectory_planner
Author(s): Joel Pereira
autogenerated on Mon Mar 2 2015 01:32:54