00001 /****************************************************************************** 00002 STDR Simulator - Simple Two DImensional Robot Simulator 00003 Copyright (C) 2013 STDR Simulator 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation; either version 3 of the License, or 00007 (at your option) any later version. 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 You should have received a copy of the GNU General Public License 00013 along with this program; if not, write to the Free Software Foundation, 00014 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00015 00016 Authors: 00017 00018 Oscar Lima Carrion, olima_84@yahoo.com 00019 Ashok Meenakshi, mashoksc@gmail.com 00020 Seguey Alexandrov, sergeyalexandrov@mail.com 00021 00022 Review / Edits: 00023 Manos Tsardoulias, etsardou@gmail.com 00024 00025 About this code: 00026 00027 This class represents a motion model for omnidirectional robot and could be 00028 used to sample the possible pose given the starting pose and the commanded 00029 robot's motion. 00030 T 00031 he motion is decomposed into two translations alond the x axis of the 00032 robot (forward), and along the y axis of the robot (lateral), and one 00033 rotation. 00034 ******************************************************************************/ 00035 00036 #include <stdr_robot/motion/omni_motion_controller.h> 00037 00038 namespace stdr_robot { 00039 00048 OmniMotionController::OmniMotionController( 00049 const geometry_msgs::Pose2D& pose, 00050 tf::TransformBroadcaster& tf, 00051 ros::NodeHandle& n, 00052 const std::string& name, 00053 const stdr_msgs::KinematicMsg params) 00054 : MotionController(pose, tf, name, n, params) 00055 { 00056 _calcTimer = n.createTimer( 00057 _freq, 00058 &OmniMotionController::calculateMotion, 00059 this); 00060 } 00061 00062 00068 void OmniMotionController::calculateMotion(const ros::TimerEvent& event) 00069 { 00071 00072 ros::Duration dt = ros::Time::now() - event.last_real; 00073 00074 // Simple omni model 00075 // TODO: Add kinematic model uncertainties 00076 if (_currentTwist.angular.z != 0 || _currentTwist.linear.x != 0 || 00077 _currentTwist.linear.y != 0) 00078 { 00079 // Dx and Dy takes under consideration both linear rotations, 00080 // independently of each other 00081 _pose.x += 00082 _currentTwist.linear.x * dt.toSec() * cosf(_pose.theta) + 00083 _currentTwist.linear.y * dt.toSec() * cosf(_pose.theta + M_PI/2.0); 00084 00085 _pose.y += 00086 _currentTwist.linear.y * dt.toSec() * sinf(_pose.theta + M_PI/2.0) + 00087 _currentTwist.linear.x * dt.toSec() * sinf(_pose.theta); 00088 00089 _pose.theta += _currentTwist.angular.z * dt.toSec(); 00090 } 00091 } 00092 00097 OmniMotionController::~OmniMotionController(void) 00098 { 00099 00100 } 00101 00102 }