darwin_simple_nav_alg.cpp
Go to the documentation of this file.
00001 #include "darwin_simple_nav_alg.h"
00002 
00003 #include <math.h>
00004 
00005 DarwinSimpleNavAlgorithm::DarwinSimpleNavAlgorithm(void)
00006 {
00007   this->max_linear_vel=0.05;
00008   this->max_angular_vel=0.5;
00009 }
00010 
00011 DarwinSimpleNavAlgorithm::~DarwinSimpleNavAlgorithm(void)
00012 {
00013 }
00014 
00015 void DarwinSimpleNavAlgorithm::config_update(Config& new_cfg, uint32_t level)
00016 {
00017   this->lock();
00018 
00019   // save the current configuration
00020   this->config_=new_cfg;
00021   this->max_linear_vel=new_cfg.max_linear_velocity;
00022   this->max_angular_vel=new_cfg.max_angular_velocity;
00023   this->max_linear_accel=new_cfg.max_linear_acceleration;
00024   
00025   this->unlock();
00026 }
00027 
00028 // DarwinSimpleNavAlgorithm Public API
00029 bool DarwinSimpleNavAlgorithm::compute_robot_speed(T2DPose &target_pose,double &vt, double &vr)
00030 {
00031   double linear_dist=0.0;
00032   double angle=0.0;
00033 
00034   vr=0;
00035   vt=0;
00036   // compute linear spped
00037   linear_dist=sqrt((target_pose.x)*(target_pose.x)+(target_pose.y)*(target_pose.y));
00038   angle=target_pose.theta;
00039   ROS_INFO("Distance to target: %f, angle to target: %f",linear_dist,angle);
00040   if(linear_dist>0.05 && fabs(angle)>0.05)
00041   { 
00042     if(linear_dist>this->max_linear_vel) 
00043       vt=this->max_linear_vel;
00044     else
00045       vt=linear_dist;
00046     if(fabs(angle)>this->max_angular_vel)
00047     {
00048       if(angle>0)
00049         vr=this->max_angular_vel;
00050       else
00051         vr=-this->max_angular_vel;
00052     }
00053     else
00054       vr=angle;
00055     return false;
00056   }
00057   else if(fabs(angle)>0.05)
00058   {
00059     if(fabs(angle)>this->max_angular_vel)
00060     {
00061       if(angle>0)
00062         vr=this->max_angular_vel;
00063       else
00064         vr=this->max_angular_vel;
00065     }
00066     else
00067       vr=angle;
00068     vt=0;
00069     return false;
00070   }
00071   else if(linear_dist>0.05)
00072   {
00073     if(linear_dist>this->max_linear_vel) 
00074       vt=this->max_linear_vel;
00075     else
00076       vt=linear_dist;
00077     vr=0;
00078     return false;
00079   }
00080   else
00081   {
00082     vt=0;
00083     vr=0;
00084     return true;
00085   }
00086 }
00087 


darwin_simple_nav
Author(s): Sergi Hernandez Juan
autogenerated on Fri Dec 6 2013 23:08:48