pr2_odometry.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2008, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 #include <Eigen/Core>
36 #include <Eigen/SVD>
37 #include <nav_msgs/Odometry.h>
38 #include <pr2_mechanism_controllers/Odometer.h>
40 #include <tf/tfMessage.h>
41 #include <tf/tf.h>
43 #include <angles/angles.h>
44 
45 #include <boost/scoped_ptr.hpp>
46 
47 #include <std_msgs/Float64.h>
48 #include <pr2_mechanism_controllers/OdometryMatrix.h>
49 #include <pr2_mechanism_controllers/DebugInfo.h>
50 
51 #include <std_msgs/Bool.h>
52 #include <pr2_mechanism_controllers/BaseOdometryState.h>
53 
54 namespace controller
55 {
56 
57 typedef Eigen::Matrix<float, 3, 1> OdomMatrix3x1;
58 typedef Eigen::Matrix<float, 16, 1> OdomMatrix16x1;
59 typedef Eigen::Matrix<float, 16, 3> OdomMatrix16x3;
60 typedef Eigen::Matrix<float, 16, 16> OdomMatrix16x16;
61 
62 
66  class Pr2Odometry : public pr2_controller_interface::Controller
67  {
68  public:
69 
73  Pr2Odometry();
74 
78  ~Pr2Odometry();
79 
86  bool init(pr2_mechanism_model::RobotState *robot_state, ros::NodeHandle &node);
87 
88  /*
89  * \brief The starting method is called by the realtime thread just before
90  * the first call to update. Overrides Controller.staring().
91  * @return Successful start
92  */
93  void starting();
94 
99  void update();
100 
104  void publish();
105 
109  void publishTransform();
110 
114  void publishOdometer();
115 
119  void publishState();
120 
121 
122  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
123 
124  private:
125 
127 
132 
136  void updateOdometry();
137 
142  void getOdometryMessage(nav_msgs::Odometry &msg);
143 
153  void getOdometry(double &x, double &y, double &yaw, double &vx, double &vy, double &vw);
154 
160  void getOdometry(geometry_msgs::Point &odom, geometry_msgs::Twist &odom_vel);
161 
165  void computeBaseVelocity();
166 
171  double getCorrectedWheelSpeed(const int &index);
172 
176  OdomMatrix3x1 iterativeLeastSquares(const OdomMatrix16x3 &lhs, const OdomMatrix16x1 &rhs, const int &max_iter);
177 
182 
186  double odometer_distance_;
187 
191  double odometer_angle_;
192 
197 
201  geometry_msgs::Point odom_;
202 
206  geometry_msgs::Twist odom_vel_;
207 
212 
216  double odometry_residual_max_;
217 
221  std::string odom_frame_;
222 
226  std::string base_link_frame_;
227 
231  std::string base_footprint_frame_;
232 
237 
242 
247 
252 
256  double expected_publish_time_;
257 
262 
267 
271  boost::scoped_ptr<realtime_tools::RealtimePublisher <nav_msgs::Odometry> > odometry_publisher_ ;
272 
276  boost::scoped_ptr<realtime_tools::RealtimePublisher <pr2_mechanism_controllers::Odometer> > odometer_publisher_ ;
277 
281  boost::scoped_ptr<realtime_tools::RealtimePublisher <pr2_mechanism_controllers::BaseOdometryState> > state_publisher_ ;
282 
286  boost::scoped_ptr<realtime_tools::RealtimePublisher <tf::tfMessage> > transform_publisher_ ;
287 
289 
291 
294 
295 
299  void populateCovariance(const double &residual, nav_msgs::Odometry &msg);
300 
301  boost::scoped_ptr<realtime_tools::RealtimePublisher <pr2_mechanism_controllers::OdometryMatrix> > matrix_publisher_;
302  boost::scoped_ptr<realtime_tools::RealtimePublisher <pr2_mechanism_controllers::DebugInfo> > debug_publisher_;
303 
304  int sequence_;
305 
306  bool isInputValid();
307 
309 
310  double odom_publish_rate_;
311 
312  double odometer_publish_rate_;
313 
314  double state_publish_rate_;
315 
317 
323 
324  std::string tf_prefix_;
325 
326  };
327 }
controller::Pr2Odometry::publishTransform
void publishTransform()
Publishes the currently computed odometry information to tf.
Definition: pr2_odometry.cpp:544
controller::Pr2Odometry::cbv_lhs_
OdomMatrix16x3 cbv_lhs_
Definition: pr2_odometry.h:350
realtime_publisher.h
controller::Pr2Odometry::transform_publisher_
boost::scoped_ptr< realtime_tools::RealtimePublisher< tf::tfMessage > > transform_publisher_
Publishes the transform between the odometry frame and the base frame.
Definition: pr2_odometry.h:318
controller::OdomMatrix16x16
Eigen::Matrix< float, 16, 16 > OdomMatrix16x16
Definition: pr2_odometry.h:92
controller::Pr2Odometry::cov_x_theta_
double cov_x_theta_
Definition: pr2_odometry.h:320
controller::Pr2Odometry::Pr2Odometry
Pr2Odometry()
Constructor for the odometry.
Definition: pr2_odometry.cpp:81
controller::OdomMatrix3x1
Eigen::Matrix< float, 3, 1 > OdomMatrix3x1
Definition: pr2_odometry.h:89
controller::Pr2Odometry::node_
ros::NodeHandle node_
Definition: pr2_odometry.h:158
controller::Pr2Odometry::odometry_residual_max_
double odometry_residual_max_
Maximum residual from the iteritive least squares.
Definition: pr2_odometry.h:248
controller::Pr2Odometry::caster_calibration_multiplier_
double caster_calibration_multiplier_
Definition: pr2_odometry.h:348
controller::Pr2Odometry::odometer_publisher_
boost::scoped_ptr< realtime_tools::RealtimePublisher< pr2_mechanism_controllers::Odometer > > odometer_publisher_
The RealtimePublisher that does the realtime publishing of the odometry.
Definition: pr2_odometry.h:308
controller::Pr2Odometry::last_time_
ros::Time last_time_
Stores the last update time and the current update time.
Definition: pr2_odometry.h:228
controller::Pr2Odometry::tf_prefix_
std::string tf_prefix_
Definition: pr2_odometry.h:356
controller::Pr2Odometry::base_kin_
BaseKinematics base_kin_
class where the robot's information is computed and stored
Definition: pr2_odometry.h:163
controller::Pr2Odometry::ils_max_iterations_
int ils_max_iterations_
Number of iterations used during iterative least squares.
Definition: pr2_odometry.h:243
controller::Pr2Odometry::verbose_
bool verbose_
Definition: pr2_odometry.h:340
controller::Pr2Odometry::getCorrectedWheelSpeed
double getCorrectedWheelSpeed(const int &index)
Computes the wheel's speed adjusted for the attached caster's rotational velocity.
Definition: pr2_odometry.cpp:412
controller::Pr2Odometry::odometer_publish_rate_
double odometer_publish_rate_
Definition: pr2_odometry.h:344
controller::Pr2Odometry::~Pr2Odometry
~Pr2Odometry()
Destructor for the odometry.
Definition: pr2_odometry.cpp:86
controller::Pr2Odometry::update
void update()
(a) Updates positions of the caster and wheels. Called every timestep in realtime
Definition: pr2_odometry.cpp:221
controller::Pr2Odometry::last_state_publish_time_
ros::Time last_state_publish_time_
The last time the odometry information was published.
Definition: pr2_odometry.h:283
controller::Pr2Odometry::last_transform_publish_time_
ros::Time last_transform_publish_time_
The last time the odometry information was published.
Definition: pr2_odometry.h:273
controller::Pr2Odometry::state_publisher_
boost::scoped_ptr< realtime_tools::RealtimePublisher< pr2_mechanism_controllers::BaseOdometryState > > state_publisher_
The RealtimePublisher that does the realtime publishing of the odometry state.
Definition: pr2_odometry.h:313
controller::OdomMatrix16x3
Eigen::Matrix< float, 16, 3 > OdomMatrix16x3
Definition: pr2_odometry.h:91
controller::Pr2Odometry::odom_
geometry_msgs::Point odom_
Point that stores the current translational position (x,y) and angular position (z)
Definition: pr2_odometry.h:233
controller::Pr2Odometry::starting
void starting()
Definition: pr2_odometry.cpp:211
controller::Pr2Odometry::last_odometer_publish_time_
ros::Time last_odometer_publish_time_
The last time the odometry information was published.
Definition: pr2_odometry.h:278
controller::Pr2Odometry::publish_tf_
bool publish_tf_
enable or disable tf publishing
Definition: pr2_odometry.h:325
controller::Pr2Odometry::fit_residual_
OdomMatrix16x1 fit_residual_
Definition: pr2_odometry.h:351
controller::Pr2Odometry::odometer_distance_
double odometer_distance_
Total distance traveled by the base as computed by the odometer.
Definition: pr2_odometry.h:218
controller::Pr2Odometry::cov_x_y_
double cov_x_y_
Definition: pr2_odometry.h:320
controller::BaseKinematics
Definition: base_kinematics.h:261
controller::Pr2Odometry::cbv_soln_
OdomMatrix3x1 cbv_soln_
Definition: pr2_odometry.h:354
controller::Pr2Odometry::publish_state_
bool publish_state_
Definition: pr2_odometry.h:340
controller::Pr2Odometry::publish_odom_
bool publish_odom_
Definition: pr2_odometry.h:340
controller::Pr2Odometry::debug_publisher_
boost::scoped_ptr< realtime_tools::RealtimePublisher< pr2_mechanism_controllers::DebugInfo > > debug_publisher_
Definition: pr2_odometry.h:334
controller
controller::Pr2Odometry::odom_publish_rate_
double odom_publish_rate_
Definition: pr2_odometry.h:342
controller::Pr2Odometry::odom_vel_
geometry_msgs::Twist odom_vel_
Twist that remembers the current translational velocities (vel.vx, vel.vy) and angular position (ang_...
Definition: pr2_odometry.h:238
pr2_mechanism_model::RobotState
controller::Pr2Odometry::sequence_
int sequence_
Definition: pr2_odometry.h:336
controller::Pr2Odometry::current_time_
ros::Time current_time_
Definition: pr2_odometry.h:228
controller::Pr2Odometry::state_publish_rate_
double state_publish_rate_
Definition: pr2_odometry.h:346
controller::Pr2Odometry::w_fit
OdomMatrix16x16 w_fit
Definition: pr2_odometry.h:353
controller::Pr2Odometry::findWeightMatrix
OdomMatrix16x16 findWeightMatrix(const OdomMatrix16x1 &residual)
Finds the weight matrix from the iterative least squares residuals.
Definition: pr2_odometry.cpp:484
controller::Pr2Odometry::publishOdometer
void publishOdometer()
Publishes the currently computed odometer information.
Definition: pr2_odometry.cpp:496
controller::Pr2Odometry::publish_odometer_
bool publish_odometer_
Definition: pr2_odometry.h:340
controller::Pr2Odometry::base_footprint_frame_
std::string base_footprint_frame_
The topic name of the base footprint frame.
Definition: pr2_odometry.h:263
pr2_controller_interface::Controller
controller::Pr2Odometry::expected_odometer_publish_time_
double expected_odometer_publish_time_
The time that the odometry is expected to be published next.
Definition: pr2_odometry.h:293
controller::Pr2Odometry::odometry_publisher_
boost::scoped_ptr< realtime_tools::RealtimePublisher< nav_msgs::Odometry > > odometry_publisher_
The RealtimePublisher that does the realtime publishing of the odometry.
Definition: pr2_odometry.h:303
controller::Pr2Odometry::populateCovariance
void populateCovariance(const double &residual, nav_msgs::Odometry &msg)
populate the covariance part of the odometry message
Definition: pr2_odometry.cpp:316
controller::Pr2Odometry::cov_y_theta_
double cov_y_theta_
Definition: pr2_odometry.h:320
tf.h
controller::Pr2Odometry::odometry_residual_
OdomMatrix16x1 odometry_residual_
Definition: pr2_odometry.h:351
controller::Pr2Odometry::expected_state_publish_time_
double expected_state_publish_time_
The time that the odometry is expected to be published next.
Definition: pr2_odometry.h:298
controller::OdomMatrix16x1
Eigen::Matrix< float, 16, 1 > OdomMatrix16x1
Definition: pr2_odometry.h:90
ros::Time
controller::Pr2Odometry::computeBaseVelocity
void computeBaseVelocity()
Computes the base velocity from the caster positions and wheel speeds.
Definition: pr2_odometry.cpp:372
controller::Pr2Odometry::isInputValid
bool isInputValid()
Definition: pr2_odometry.cpp:194
controller::Pr2Odometry::base_link_floor_z_offset_
double base_link_floor_z_offset_
Definition: pr2_odometry.h:322
controller::Pr2Odometry::last_publish_time_
ros::Time last_publish_time_
The last time the odometry information was published.
Definition: pr2_odometry.h:268
controller::Pr2Odometry::weight_matrix_
OdomMatrix16x16 weight_matrix_
Definition: pr2_odometry.h:353
controller::Pr2Odometry::init
bool init(pr2_mechanism_model::RobotState *robot_state, ros::NodeHandle &node)
Initializes and loads odometry information from the param server.
Definition: pr2_odometry.cpp:90
controller::Pr2Odometry::expected_publish_time_
double expected_publish_time_
The time that the odometry is expected to be published next.
Definition: pr2_odometry.h:288
controller::Pr2Odometry::fit_soln_
OdomMatrix3x1 fit_soln_
Definition: pr2_odometry.h:354
controller::Pr2Odometry::fit_lhs_
OdomMatrix16x3 fit_lhs_
Definition: pr2_odometry.h:350
controller::Pr2Odometry::getOdometry
void getOdometry(double &x, double &y, double &yaw, double &vx, double &vy, double &vw)
Takes the current odometery information and stores it into the six double parameters.
Definition: pr2_odometry.cpp:361
controller::Pr2Odometry::publish
void publish()
Publishes the currently computed odometry information.
Definition: pr2_odometry.cpp:531
controller::Pr2Odometry::fit_rhs_
OdomMatrix16x1 fit_rhs_
Definition: pr2_odometry.h:352
controller::Pr2Odometry::base_link_frame_
std::string base_link_frame_
The topic name of the base link frame.
Definition: pr2_odometry.h:258
controller::Pr2Odometry::sigma_y_
double sigma_y_
Definition: pr2_odometry.h:320
base_kinematics.h
controller::Pr2Odometry::sigma_theta_
double sigma_theta_
Definition: pr2_odometry.h:320
controller::Pr2Odometry::matrix_publisher_
boost::scoped_ptr< realtime_tools::RealtimePublisher< pr2_mechanism_controllers::OdometryMatrix > > matrix_publisher_
Definition: pr2_odometry.h:333
controller::Pr2Odometry::cbv_rhs_
OdomMatrix16x1 cbv_rhs_
Definition: pr2_odometry.h:351
controller::Pr2Odometry::odometer_angle_
double odometer_angle_
Total angular distance traveled by the base as computed by the odometer.
Definition: pr2_odometry.h:223
ros::NodeHandle
controller::Pr2Odometry::getOdometryMessage
void getOdometryMessage(nav_msgs::Odometry &msg)
Builds the odometry message and prepares it for sending.
Definition: pr2_odometry.cpp:297
angles.h
controller::Pr2Odometry::publishState
void publishState()
Publishes the odometry state information.
Definition: pr2_odometry.cpp:509
controller::Pr2Odometry::iterativeLeastSquares
OdomMatrix3x1 iterativeLeastSquares(const OdomMatrix16x3 &lhs, const OdomMatrix16x1 &rhs, const int &max_iter)
Function used to compute the most likely solution to the odometry using iterative least squares.
Definition: pr2_odometry.cpp:424
controller::Pr2Odometry::updateOdometry
void updateOdometry()
Finds and stores the latest odometry information.
Definition: pr2_odometry.cpp:263
controller::Pr2Odometry::sigma_x_
double sigma_x_
Definition: pr2_odometry.h:320
controller::Pr2Odometry::odom_frame_
std::string odom_frame_
The topic name of the published odometry.
Definition: pr2_odometry.h:253


pr2_mechanism_controllers
Author(s): Sachin Chita, John Hsu, Melonee Wise
autogenerated on Sat Nov 12 2022 03:33:25