|
| 1 | +/********************************************************************* |
| 2 | + * Software License Agreement (BSD License) |
| 3 | + * |
| 4 | + * Copyright (c) 2016, Clearpath Robotics, 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 PAL Robotics 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 | +/* |
| 36 | + * Author: Enrique Fernández |
| 37 | + */ |
| 38 | + |
| 39 | +#ifndef RIGID_BODY_MOTION_H_ |
| 40 | +#define RIGID_BODY_MOTION_H_ |
| 41 | + |
| 42 | +#include <Eigen/Dense> |
| 43 | + |
| 44 | +#include <limits> |
| 45 | + |
| 46 | +namespace diff_drive_controller |
| 47 | +{ |
| 48 | + |
| 49 | +/** |
| 50 | + * \brief Compute rigid body motion in SE(2) using element-wise equations. |
| 51 | + * \param[in, out] x Pose x component |
| 52 | + * \param[in, out] y Pose y component |
| 53 | + * \param[in, out] yaw Pose yaw component |
| 54 | + * \param[in] v_x Velocity/Twist x component |
| 55 | + * \param[in] v_y Velocity/Twist y component |
| 56 | + * \param[in] v_yaw Velocity/Twist yaw component |
| 57 | + * \param[in] dt Time step |
| 58 | + */ |
| 59 | +static void integrate_motion(double& x, double &y, double &yaw, |
| 60 | + const double v_x, const double v_y, const double v_yaw, |
| 61 | + const double dt) |
| 62 | +{ |
| 63 | + const double cos_yaw = std::cos(yaw); |
| 64 | + const double sin_yaw = std::sin(yaw); |
| 65 | + |
| 66 | + x += (v_x * cos_yaw - v_y * sin_yaw) * dt; |
| 67 | + y += (v_x * sin_yaw + v_y * cos_yaw) * dt; |
| 68 | + yaw += v_yaw * dt; |
| 69 | +} |
| 70 | + |
| 71 | +/** |
| 72 | + * \brief Compute rigid body motion in SE(2) using element-wise equations. |
| 73 | + * Also computes the Jacobians wrt the pose and the velocity/twist. |
| 74 | + * \param[in, out] x Pose x component |
| 75 | + * \param[in, out] y Pose y component |
| 76 | + * \param[in, out] yaw Pose yaw component |
| 77 | + * \param[in] v_x Velocity/Twist x component |
| 78 | + * \param[in] v_y Velocity/Twist y component |
| 79 | + * \param[in] v_yaw Velocity/Twist yaw component |
| 80 | + * \param[in] dt Time step |
| 81 | + */ |
| 82 | +static void integrate_motion(double& x, double &y, double &yaw, |
| 83 | + const double v_x, const double v_y, const double v_yaw, |
| 84 | + const double dt, |
| 85 | + Eigen::Matrix3d& J_pose, Eigen::Matrix3d& J_twist) |
| 86 | +{ |
| 87 | + const double cos_yaw = std::cos(yaw); |
| 88 | + const double sin_yaw = std::sin(yaw); |
| 89 | + |
| 90 | + x += (v_x * cos_yaw - v_y * sin_yaw) * dt; |
| 91 | + y += (v_x * sin_yaw + v_y * cos_yaw) * dt; |
| 92 | + yaw += v_yaw * dt; |
| 93 | + |
| 94 | + J_pose << 1.0, 0.0, (-v_x * sin_yaw - v_y * cos_yaw) * dt, |
| 95 | + 0.0, 1.0, ( v_x * cos_yaw - v_y * sin_yaw) * dt, |
| 96 | + 0.0, 0.0, 1.0; |
| 97 | + |
| 98 | + J_twist << cos_yaw * dt, -sin_yaw * dt, 0.0, |
| 99 | + sin_yaw * dt, cos_yaw * dt, 0.0, |
| 100 | + 0.0, 0.0, dt; |
| 101 | +} |
| 102 | + |
| 103 | +} |
| 104 | + |
| 105 | +#endif /* RIGID_BODY_MOTION_H_ */ |
0 commit comments