mecanum_controller.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2020 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
17 
18 // Maths from https://research.ijcaonline.org/volume113/number3/pxc3901586.pdf
19 
20 namespace cob_mecanum_controller
21 {
22 MecanumController::MecanumController(double lx, double ly, double r) : r_(r)
23 {
24  double lxy = lx + ly;
25  double lxy_inv = 1.0 / lxy;
26  inverse_matrix_ << 1, 1, 1, 1, -1, 1, 1, -1, -lxy_inv, lxy_inv, -lxy_inv, lxy_inv;
27  forward_matrix_ << 1, -1, -lxy, 1, 1, lxy, 1, 1, -lxy, 1, -1, lxy;
28 }
29 
30 Eigen::Vector3d MecanumController::wheelToTwist(Eigen::Vector4d wheel_velocity)
31 {
32  wheel_velocity(1) = wheel_velocity(1) * -1;
33  wheel_velocity(3) = wheel_velocity(3) * -1;
34  return r_ / 4 * inverse_matrix_ * wheel_velocity;
35 }
36 
37 Eigen::Vector4d MecanumController::twistToWheel(Eigen::Vector3d twist)
38 {
39  Eigen::Vector4d wheel_cmd = 1.0 / r_ * forward_matrix_ * twist;
40  wheel_cmd(1) = wheel_cmd(1) * -1;
41  wheel_cmd(3) = wheel_cmd(3) * -1;
42  return wheel_cmd;
43 }
44 
45 } // namespace cob_mecanum_controller
MecanumController(double lx, double ly, double r)
Eigen::Matrix< double, 3, 4 > inverse_matrix_
Eigen::Vector4d twistToWheel(Eigen::Vector3d twist)
Eigen::Matrix< double, 4, 3 > forward_matrix_
Eigen::Vector3d wheelToTwist(Eigen::Vector4d wheel_velocity)


cob_mecanum_controller
Author(s):
autogenerated on Thu Apr 8 2021 02:39:42