motion_controller_base.h
Go to the documentation of this file.
1 /******************************************************************************
2  STDR Simulator - Simple Two DImensional Robot Simulator
3  Copyright (C) 2013 STDR Simulator
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 3 of the License, or
7  (at your option) any later version.
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software Foundation,
14  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 
16  Authors :
17  * Manos Tsardoulias, etsardou@gmail.com
18  * Aris Thallas, aris.thallas@gmail.com
19  * Chris Zalidis, zalidis@gmail.com
20 ******************************************************************************/
21 
22 #ifndef MOTION_CONTROLLER_BASE_H
23 #define MOTION_CONTROLLER_BASE_H
24 
25 #include <ros/ros.h>
27 #include <geometry_msgs/Twist.h>
28 #include <geometry_msgs/Pose2D.h>
29 #include <stdr_msgs/KinematicMsg.h>
30 
31 #include <ctime>
32 
37 namespace stdr_robot {
38 
39 
45 
46  public:
47 
53  virtual void velocityCallback(const geometry_msgs::Twist& msg)
54  {
55  _currentTwist = msg;
57  }
58 
75  virtual void sampleVelocities(void)
76  {
77  float ux = _currentTwist.linear.x;
78  float uy = _currentTwist.linear.y;
79  float w = _currentTwist.angular.z;
80 
81  float sample_ux =
82  _motion_parameters.a_ux_ux * ux * ux +
83  _motion_parameters.a_ux_uy * uy * uy +
84  _motion_parameters.a_ux_w * w * w;
85  _currentTwist.linear.x += sampleNormal(sqrt(sample_ux));
86 
87  float sample_uy =
88  _motion_parameters.a_uy_ux * ux * ux +
89  _motion_parameters.a_uy_uy * uy * uy +
90  _motion_parameters.a_uy_w * w * w;
91  _currentTwist.linear.y += sampleNormal(sqrt(sample_uy));
92 
93  float sample_w =
94  _motion_parameters.a_w_ux * ux * ux +
95  _motion_parameters.a_w_uy * uy * uy +
96  _motion_parameters.a_w_w * w * w;
97  _currentTwist.angular.z += sampleNormal(sqrt(sample_w));
98 
99  float sample_g =
100  _motion_parameters.a_g_ux * ux * ux +
101  _motion_parameters.a_g_uy * uy * uy +
102  _motion_parameters.a_g_w * w * w;
103  _currentTwist.angular.z += sampleNormal(sqrt(sample_g));
104  }
105 
106 
111  virtual void stop(void)
112  {
113  _currentTwist.linear.x = 0;
114  _currentTwist.linear.y = 0;
115  _currentTwist.linear.z = 0;
116  _currentTwist.angular.x = 0;
117  _currentTwist.angular.y = 0;
118  _currentTwist.angular.z = 0;
119  }
120 
126  virtual void calculateMotion(const ros::TimerEvent& event) = 0;
127 
132  inline geometry_msgs::Pose2D getPose(void)
133  {
134  return _pose;
135  }
136 
142  inline void setPose(geometry_msgs::Pose2D new_pose)
143  {
144  _pose.x = new_pose.x;
145  _pose.y = new_pose.y;
146  _pose.theta = new_pose.theta;
147  }
148 
153  inline geometry_msgs::Twist getVelocity() {
154  return _currentTwist;
155  }
156 
161  virtual ~MotionController(void)
162  {
163  }
164 
170  float sampleNormal(float sigma)
171  {
172  float tmp = 0;
173  for (unsigned int i = 0 ; i < 12 ; i++)
174  {
175  float sample = (rand() % 100000) / 50000.0 - 1.0; // From -1.0 -> 1.0
176  tmp += sample * sigma;
177  }
178  return tmp / 2.0;
179  }
180 
181 
182  protected:
183 
192  const geometry_msgs::Pose2D& pose,
194  const std::string& name,
195  ros::NodeHandle& n,
196  const stdr_msgs::KinematicMsg params
197  )
198  : _tfBroadcaster(tf),
199  _freq(0.1),
200  _namespace(name),
201  _pose(pose),
202  _motion_parameters(params)
203  {
205  _namespace + "/cmd_vel",
206  1,
208  this);
209 
210  srand(time(NULL));
211  }
212 
213  protected:
214 
216  const std::string& _namespace;
226  geometry_msgs::Pose2D _pose;
228  geometry_msgs::Twist _currentTwist;
230  stdr_msgs::KinematicMsg _motion_parameters;
231  };
232 
234 
235 }
236 
237 
238 #endif
virtual void sampleVelocities(void)
Virtual function - Add noise to velocity commands.
ros::Duration _freq
ROS timer for generating motion calculation events.
ros::Timer _calcTimer
Broadcaster of the robot tf transform.
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
The main namespace for STDR Robot.
Definition: exceptions.h:27
boost::shared_ptr< MotionController > MotionControllerPtr
geometry_msgs::Pose2D _pose
Current motion command.
virtual void velocityCallback(const geometry_msgs::Twist &msg)
Virtual function - Callback for velocity commands.
ros::Subscriber _velocitySubscrider
Frequency of motion calculation.
float sampleNormal(float sigma)
Approaches a normal distribution sampling.
geometry_msgs::Pose2D getPose(void)
Returns the pose calculated by the motion controller.
virtual ~MotionController(void)
Default desctructor.
geometry_msgs::Twist getVelocity()
Get the current velocity of the motion controller.
geometry_msgs::Twist _currentTwist
The kinematic model parameters.
stdr_msgs::KinematicMsg _motion_parameters
virtual void stop(void)
Virtual function - Stops the robot.
Abstract class that provides motion controller abstraction.
TFSIMD_FORCE_INLINE const tfScalar & w() const
MotionController(const geometry_msgs::Pose2D &pose, tf::TransformBroadcaster &tf, const std::string &name, ros::NodeHandle &n, const stdr_msgs::KinematicMsg params)
Default constructor.
const std::string & _namespace
< The base of the frame_id
tf::TransformBroadcaster & _tfBroadcaster
Robot pose message.
void setPose(geometry_msgs::Pose2D new_pose)
Sets the initial pose of the motion controller.
virtual void calculateMotion(const ros::TimerEvent &event)=0
Pure virtual function - Calculates the motion - updates the robot pose.


stdr_robot
Author(s): Manos Tsardoulias, Chris Zalidis, Aris Thallas
autogenerated on Mon Jun 10 2019 15:15:10