Go to the documentation of this file.00001 #include "tibi_dabo_pitch_estimator_sin_laser_vertical_alg_node.h"
00002 #include <stdio.h>
00003 #include <string.h>
00004 #include <cmath>
00005 TibiDaboPitchEstimatorSinLaserVerticalAlgNode::TibiDaboPitchEstimatorSinLaserVerticalAlgNode(void) :
00006 algorithm_base::IriBaseAlgorithm<TibiDaboPitchEstimatorSinLaserVerticalAlgorithm>(),
00007 a1_(0),
00008 b1_(0),
00009 front_security_distance_(0.7),
00010 rear_security_distance_(1.2)
00011 {
00012
00013
00014
00015
00016 this->MarkerArray_lines_publisher_ = this->public_node_handle_.advertise<visualization_msgs::MarkerArray>("MarkerArray_lines", 100);
00017 this->front_laser_filtrado_publisher_ = this->public_node_handle_.advertise<sensor_msgs::LaserScan>("front_laser_filtrado", 100);
00018 this->rear_laser_filtrado_publisher_ = this->public_node_handle_.advertise<sensor_msgs::LaserScan>("rear_laser_filtrado", 100);
00019
00020
00021 this->front_laser_subscriber_ = this->public_node_handle_.subscribe("front_laser", 100, &TibiDaboPitchEstimatorSinLaserVerticalAlgNode::front_laser_callback, this);
00022 this->rear_laser_subscriber_ = this->public_node_handle_.subscribe("rear_laser", 100, &TibiDaboPitchEstimatorSinLaserVerticalAlgNode::rear_laser_callback, this);
00023 this->pitch_subscriber_ = this->public_node_handle_.subscribe("pitch", 100, &TibiDaboPitchEstimatorSinLaserVerticalAlgNode::pitch_callback, this);
00024
00025
00026
00027
00028
00029
00030
00031
00032 }
00033
00034 TibiDaboPitchEstimatorSinLaserVerticalAlgNode::~TibiDaboPitchEstimatorSinLaserVerticalAlgNode(void)
00035 {
00036
00037 }
00038
00039 void TibiDaboPitchEstimatorSinLaserVerticalAlgNode::mainNodeThread(void)
00040 {
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 this->MarkerArray_lines_publisher_.publish(this->MarkerArray_msg_);
00055
00056
00057 }
00058
00059
00060 void TibiDaboPitchEstimatorSinLaserVerticalAlgNode::front_laser_callback(const sensor_msgs::LaserScan::ConstPtr& msg)
00061 {
00062
00063
00064
00065 this->front_laser_mutex_.enter();
00066
00067
00068 this->alg_.lock();
00069
00070 double distance_intersection_=60,distance_point_laser_=0;
00071
00072 LaserScan_front_msg_=*msg;
00073
00074 for( unsigned int i =0; i < msg->ranges.size()-1 ; ++i )
00075 {
00076
00077 double inicial_point_x = 0.28;
00078 double inicial_point_y =0.44;
00079
00080 double intersection_y = (0.44-b1_)/a1_+0.28 ;
00081 double intersection_x = b1_+0.44 ;
00082
00083 double angle = msg->angle_max;
00084
00085 if(a1_>0){
00086
00087 distance_intersection_=sqrt((inicial_point_x-intersection_x)*(inicial_point_x-intersection_x)+(inicial_point_y-intersection_y)*(inicial_point_y-intersection_y));
00088 distance_point_laser_=msg->ranges[i];
00089
00090 }
00091
00092 if(distance_intersection_< distance_point_laser_+front_security_distance_){
00093
00094 LaserScan_front_msg_.ranges[i]=0.0;
00095
00096 }
00097
00098 }
00099
00100 this->front_laser_filtrado_publisher_.publish(this->LaserScan_front_msg_);
00101
00102
00103
00104
00105 double angle = msg->angle_min;
00106
00107 for( unsigned int i =0 ; i < msg->ranges.size()-1 ; ++i )
00108 {
00109
00110 front_laser_point_x=msg->ranges[i] * cos(angle)-0.28;
00111 front_laser_point_y=0.44-msg->ranges[i] * sin(angle);
00112 marker_point_front_laser_node(front_laser_point_x,front_laser_point_y);
00113
00114
00115 angle += msg->angle_increment;
00116
00117 }
00118
00119
00120
00121
00122 this->alg_.unlock();
00123
00124
00125
00126 this->front_laser_mutex_.exit();
00127 }
00128
00129 void TibiDaboPitchEstimatorSinLaserVerticalAlgNode::rear_laser_callback(const sensor_msgs::LaserScan::ConstPtr& msg)
00130 {
00131
00132
00133
00134
00135 this->rear_laser_mutex_.enter();
00136
00137
00138 this->alg_.lock();
00139
00140 double distance_intersection_=60,distance_point_laser_=0;
00141
00142 LaserScan_rear_msg_=*msg;
00143
00144 for( unsigned int i =0; i < msg->ranges.size()-1 ; ++i )
00145 {
00146
00147 double inicial_point_x = 0.28;
00148 double inicial_point_y =0.44;
00149
00150 double angle = msg->angle_max;
00151
00152 if(a1_<0){
00153
00154 double intersection_y = (0.44-b1_)/(-a1_)+0.28 ;
00155 double intersection_x = b1_+0.44 ;
00156
00157 distance_intersection_=sqrt((inicial_point_x-intersection_x)*(inicial_point_x-intersection_x)+(inicial_point_y-intersection_y)*(inicial_point_y-intersection_y));
00158 distance_point_laser_=msg->ranges[i];
00159
00160 }
00161
00162 if(distance_intersection_< distance_point_laser_+rear_security_distance_){
00163
00164 LaserScan_rear_msg_.ranges[i]=0.0;
00165
00166 }
00167
00168 }
00169
00170 this->rear_laser_filtrado_publisher_.publish(this->LaserScan_rear_msg_);
00171
00172
00173
00174
00175 double angle = msg->angle_min;
00176
00177 for( unsigned int i =0 ; i < msg->ranges.size()-1 ; ++i )
00178 {
00179
00180 front_laser_point_x=msg->ranges[i] * cos(angle)-0.28;
00181 front_laser_point_y=0.44-msg->ranges[i] * sin(angle);
00182 marker_point_front_laser_node(front_laser_point_x,front_laser_point_y);
00183
00184 angle += msg->angle_increment;
00185
00186 }
00187
00188
00189
00190
00191
00192 this->alg_.unlock();
00193
00194
00195 this->rear_laser_mutex_.exit();
00196 }
00197
00198 void TibiDaboPitchEstimatorSinLaserVerticalAlgNode::pitch_callback(const iri_segway_rmp_msgs::SegwayRMP200Status::ConstPtr& msg)
00199 {
00200
00201
00202
00203
00204 this->alg_.lock();
00205 this->pitch_mutex_.enter();
00206
00207 pitch=msg->pitch_angle;
00208
00209 function_markers(pitch);
00210
00211
00212 this->alg_.unlock();
00213 this->pitch_mutex_.exit();
00214
00215
00216 }
00217
00218
00219
00220 void TibiDaboPitchEstimatorSinLaserVerticalAlgNode::function_markers(double pitch)
00221 {
00222
00223 pitch_arrow_marker_.points.clear();
00224 floor_line_marker_.points.clear();
00225 arrow_intersection_.points.clear();
00226
00227 geometry_msgs::Point ros_point;
00228 pitch_arrow_marker_.id=4;
00229 pitch_arrow_marker_.header.frame_id = "/dabo/base_link";
00230 pitch_arrow_marker_.header.stamp = ros::Time();
00231 pitch_arrow_marker_.ns = "pitch";
00232 pitch_arrow_marker_.type = visualization_msgs::Marker::ARROW;
00233 pitch_arrow_marker_.action = visualization_msgs::Marker::ADD;
00234 pitch_arrow_marker_.lifetime = ros::Duration(1.0f);
00235
00236
00237 if ( pitch_arrow_marker_.points.size() <2)
00238 {
00239 double x;
00240 ros_point.x = 0;
00241 ros_point.z =0;
00242 ros_point.y = 0;
00243 pitch_arrow_marker_.points.push_back(ros_point);
00244 if(tan(pitch)>0){
00245 x=-5.0;
00246 ros_point.x = -5/sqrt(5*5+((-1/tan(pitch))*(-5))*((-1/tan(pitch))*(-5)));
00247 }
00248 else{
00249 x=5.0;
00250 ros_point.x = 5/sqrt(5*5+((-1/tan(pitch))*5)*((-1/tan(pitch))*5));
00251 }
00252 ros_point.z= ((-1/tan(pitch))*x)/sqrt(x*x+((-1/tan(pitch))*x)*((-1/tan(pitch))*x));
00253 ros_point.y = 0.0;
00254 pitch_arrow_marker_.points.push_back(ros_point);
00255
00256 }
00257
00258 pitch_arrow_marker_.scale.x = 0.05;
00259 pitch_arrow_marker_.scale.y = 0.05;
00260 pitch_arrow_marker_.scale.z = 0.05;
00261
00262 pitch_arrow_marker_.color.a = 1.0;
00263 pitch_arrow_marker_.color.r = 0.7;
00264 pitch_arrow_marker_.color.g = 0.3;
00265 pitch_arrow_marker_.color.b = 0.0;
00266
00267
00268
00269 a1_=tan(pitch);
00270 b1_=0;
00271 geometry_msgs::Point ros_point2;
00272 floor_line_marker_.id=0;
00273 floor_line_marker_.header.frame_id = "/dabo/base_link";
00274 floor_line_marker_.header.stamp = ros::Time();
00275 floor_line_marker_.ns = "line floor";
00276 floor_line_marker_.type = visualization_msgs::Marker::LINE_STRIP;
00277 floor_line_marker_.action = visualization_msgs::Marker::ADD;
00278 floor_line_marker_.lifetime = ros::Duration(1.0f);
00279 floor_line_marker_.points.reserve(2);
00280
00281 if ( floor_line_marker_.points.size() <2)
00282 {
00283 ros_point2.x = -10;
00284 ros_point2.z =a1_*ros_point2.x+b1_;
00285 ros_point2.y = 0;
00286 floor_line_marker_.points.push_back(ros_point2);
00287 ros_point2.x = 10;
00288 ros_point2.z=a1_*ros_point2.x+b1_;
00289 ros_point2.y = 0;
00290 floor_line_marker_.points.push_back(ros_point2);
00291 }
00292
00293 floor_line_marker_.scale.x = 0.05;
00294 floor_line_marker_.color.a = 1.0;
00295 floor_line_marker_.color.r = 0.0;
00296 floor_line_marker_.color.g = 1.0;
00297 floor_line_marker_.color.b = 0.0;
00298
00299
00300 geometry_msgs::Point ros_point3;
00301 arrow_intersection_.id=5;
00302 arrow_intersection_.header.frame_id = "/dabo/base_link";
00303 arrow_intersection_.header.stamp = ros::Time();
00304 arrow_intersection_.ns = "intersection_point";
00305 arrow_intersection_.type = visualization_msgs::Marker::ARROW;
00306
00307 arrow_intersection_.action = visualization_msgs::Marker::ADD;
00308 arrow_intersection_.lifetime = ros::Duration(1.0f);
00309
00310
00311
00312
00313
00314
00315
00316 if ( arrow_intersection_.points.size() <2)
00317 {
00318 ros_point3.x = 0.28;
00319 ros_point3.z =0.44;
00320 ros_point3.y = 0;
00321 arrow_intersection_.points.push_back(ros_point3);
00322
00323 ros_point3.x = (0.44-b1_)/a1_+0.28;
00324 ros_point3.z=b1_+0.44;
00325 ros_point3.y = 0.0;
00326 arrow_intersection_.points.push_back(ros_point3);
00327
00328 }
00329
00330 arrow_intersection_.scale.x = 0.1;
00331 arrow_intersection_.scale.y = 0.1;
00332 arrow_intersection_.scale.z = 0.1;
00333
00334 arrow_intersection_.color.a = 1.0;
00335 arrow_intersection_.color.r = 0.5;
00336 arrow_intersection_.color.g = 0.0;
00337 arrow_intersection_.color.b = 0.5;
00338
00339
00340 MarkerArray_msg_.markers.push_back(pitch_arrow_marker_);
00341 MarkerArray_msg_.markers.push_back(floor_line_marker_);
00342 MarkerArray_msg_.markers.push_back(arrow_intersection_);
00343
00344 }
00345
00346
00347 void TibiDaboPitchEstimatorSinLaserVerticalAlgNode::marker_point_front_laser_node(double front_laser_point_x, double front_laser_point_y)
00348 {
00349
00350
00351 distance_front_laser_marker6_.points.clear();
00352 geometry_msgs::Point ros_point6;
00353 distance_front_laser_marker6_.id=6;
00354 distance_front_laser_marker6_.header.frame_id = "/dabo/base_link";
00355 distance_front_laser_marker6_.header.stamp = ros::Time();
00356 distance_front_laser_marker6_.ns = "puntos_front_laser";
00357
00358 distance_front_laser_marker6_.type = visualization_msgs::Marker::SPHERE;
00359 distance_front_laser_marker6_.action = visualization_msgs::Marker::ADD;
00360 distance_front_laser_marker6_.lifetime = ros::Duration(1.0f);
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376 distance_front_laser_marker6_.pose.position.x=front_laser_point_x;
00377 distance_front_laser_marker6_.pose.position.y=front_laser_point_y;
00378 distance_front_laser_marker6_.pose.position.z=0.44;
00379
00380 distance_front_laser_marker6_.scale.x = 0.2;
00381 distance_front_laser_marker6_.scale.y = 0.2;
00382 distance_front_laser_marker6_.scale.z = 0.2;
00383
00384 distance_front_laser_marker6_.color.a = 1.0;
00385 distance_front_laser_marker6_.color.r = 1.0;
00386 distance_front_laser_marker6_.color.g = 0.0;
00387 distance_front_laser_marker6_.color.b = 0.0;
00388 MarkerArray_msg_.markers.clear();
00389 MarkerArray_msg_.markers.push_back(distance_front_laser_marker6_);
00390 }
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402 void TibiDaboPitchEstimatorSinLaserVerticalAlgNode::node_config_update(Config &config, uint32_t level)
00403 {
00404 this->alg_.lock();
00405
00406 this->alg_.unlock();
00407 }
00408
00409 void TibiDaboPitchEstimatorSinLaserVerticalAlgNode::addNodeDiagnostics(void)
00410 {
00411 }
00412
00413
00414 int main(int argc,char *argv[])
00415 {
00416 return algorithm_base::main<TibiDaboPitchEstimatorSinLaserVerticalAlgNode>(argc, argv, "tibi_dabo_pitch_estimator_sin_laser_vertical_alg_node");
00417 }