Nav2 Navigation Stack - rolling  main
ROS 2 Navigation Stack
omni_motion_model.cpp
1 /*
2  * Player - One Hell of a Robot Server
3  * Copyright (C) 2000 Brian Gerkey & Kasper Stoy
4  * gerkey@usc.edu kaspers@robotics.usc.edu
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 #include <cmath>
23 
24 #include "nav2_amcl/angleutils.hpp"
25 #include "nav2_amcl/motion_model/omni_motion_model.hpp"
26 #include "nav2_amcl/pf/pf_pdf.hpp"
27 #include "nav2_amcl/pf/pf_vector.hpp"
28 
29 namespace nav2_amcl
30 {
31 
32 void
34  double alpha1, double alpha2, double alpha3, double alpha4,
35  double alpha5)
36 {
37  alpha1_ = alpha1;
38  alpha2_ = alpha2;
39  alpha3_ = alpha3;
40  alpha4_ = alpha4;
41  alpha5_ = alpha5;
42 }
43 
44 void
46  pf_t * pf, const pf_vector_t & pose,
47  const pf_vector_t & delta)
48 {
49  // Compute the new sample poses
50  pf_sample_set_t * set;
51 
52  set = pf->sets + pf->current_set;
53  pf_vector_t old_pose = pf_vector_sub(pose, delta);
54 
55  double delta_trans, delta_rot, delta_bearing;
56  double delta_trans_hat, delta_rot_hat, delta_strafe_hat;
57 
58  delta_trans = sqrt(
59  delta.v[0] * delta.v[0] +
60  delta.v[1] * delta.v[1]);
61  delta_rot = delta.v[2];
62 
63  // Precompute a couple of things
64  double trans_hat_stddev = sqrt(
65  alpha3_ * (delta_trans * delta_trans) +
66  alpha4_ * (delta_rot * delta_rot) );
67  double rot_hat_stddev = sqrt(
68  alpha1_ * (delta_rot * delta_rot) +
69  alpha2_ * (delta_trans * delta_trans) );
70  double strafe_hat_stddev = sqrt(
71  alpha4_ * (delta_rot * delta_rot) +
72  alpha5_ * (delta_trans * delta_trans) );
73 
74  for (int i = 0; i < set->sample_count; i++) {
75  pf_sample_t * sample = set->samples + i;
76 
77  delta_bearing = angleutils::angle_diff(
78  atan2(delta.v[1], delta.v[0]),
79  old_pose.v[2]) + sample->pose.v[2];
80  double cs_bearing = cos(delta_bearing);
81  double sn_bearing = sin(delta_bearing);
82 
83  // Sample pose differences
84  delta_trans_hat = delta_trans + pf_ran_gaussian(trans_hat_stddev);
85  delta_rot_hat = delta_rot + pf_ran_gaussian(rot_hat_stddev);
86  delta_strafe_hat = 0 + pf_ran_gaussian(strafe_hat_stddev);
87  // Apply sampled update to particle pose
88  sample->pose.v[0] += (delta_trans_hat * cs_bearing +
89  delta_strafe_hat * sn_bearing);
90  sample->pose.v[1] += (delta_trans_hat * sn_bearing -
91  delta_strafe_hat * cs_bearing);
92  sample->pose.v[2] += delta_rot_hat;
93  }
94 }
95 
96 } // namespace nav2_amcl
97 
98 #include <pluginlib/class_list_macros.hpp>
An abstract motion model class.
virtual void initialize(double alpha1, double alpha2, double alpha3, double alpha4, double alpha5)
An factory to create motion models.
virtual void odometryUpdate(pf_t *pf, const pf_vector_t &pose, const pf_vector_t &delta)
Update on new odometry data.
Definition: pf.hpp:112