FourSwedishWheelOmniBaseKinematic.cpp
Go to the documentation of this file.
1 /****************************************************************
2  *
3  * Copyright (c) 2011
4  * All rights reserved.
5  *
6  * Hochschule Bonn-Rhein-Sieg
7  * University of Applied Sciences
8  * Computer Science Department
9  *
10  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11  *
12  * Author:
13  * Jan Paulus, Nico Hochgeschwender, Michael Reckhaus, Azamat Shakhimardanov
14  * Supervised by:
15  * Gerhard K. Kraetzschmar
16  *
17  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
18  *
19  * This sofware is published under a dual-license: GNU Lesser General Public
20  * License LGPL 2.1 and BSD license. The dual-license implies that users of this
21  * code may choose which terms they prefer.
22  *
23  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24  *
25  * Redistribution and use in source and binary forms, with or without
26  * modification, are permitted provided that the following conditions are met:
27  *
28  * * Redistributions of source code must retain the above copyright
29  * notice, this list of conditions and the following disclaimer.
30  * * Redistributions in binary form must reproduce the above copyright
31  * notice, this list of conditions and the following disclaimer in the
32  * documentation and/or other materials provided with the distribution.
33  * * Neither the name of the Hochschule Bonn-Rhein-Sieg nor the names of its
34  * contributors may be used to endorse or promote products derived from
35  * this software without specific prior written permission.
36  *
37  * This program is free software: you can redistribute it and/or modify
38  * it under the terms of the GNU Lesser General Public License LGPL as
39  * published by the Free Software Foundation, either version 2.1 of the
40  * License, or (at your option) any later version or the BSD license.
41  *
42  * This program is distributed in the hope that it will be useful,
43  * but WITHOUT ANY WARRANTY; without even the implied warranty of
44  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45  * GNU Lesser General Public License LGPL and the BSD license for more details.
46  *
47  * You should have received a copy of the GNU Lesser General Public
48  * License LGPL and BSD license along with this program.
49  *
50  ****************************************************************/
52 namespace youbot {
53 
55  // Bouml preserved body begin 000513F1
56  this->lastWheelPositionInitialized = false;
57  // Bouml preserved body end 000513F1
58 }
59 
61  // Bouml preserved body begin 00051471
62  // Bouml preserved body end 00051471
63 }
64 
70 void FourSwedishWheelOmniBaseKinematic::cartesianVelocityToWheelVelocities(const quantity<si::velocity>& longitudinalVelocity, const quantity<si::velocity>& transversalVelocity, const quantity<si::angular_velocity>& angularVelocity, std::vector<quantity<angular_velocity> >& wheelVelocities) {
71  // Bouml preserved body begin 0004C071
72  quantity<angular_velocity> RadPerSec_FromX;
73  quantity<angular_velocity> RadPerSec_FromY;
74  quantity<angular_velocity> RadPerSec_FromTheta;
75  wheelVelocities.assign(4, RadPerSec_FromX);
76 
77  if (config.wheelRadius.value() == 0 || config.rotationRatio == 0 || config.slideRatio == 0) {
78  throw std::out_of_range("The wheelRadius, RotationRatio or the SlideRatio are not allowed to be zero");
79  }
80 
81  // RadPerSec_FromX = longitudinalVelocity / config.wheelRadius;
82  RadPerSec_FromX = longitudinalVelocity.value() / config.wheelRadius.value() * radian_per_second;
83  RadPerSec_FromY = transversalVelocity.value() / (config.wheelRadius.value() * config.slideRatio) * radian_per_second;
84 
85  // Calculate Rotation Component
86  RadPerSec_FromTheta = ((config.lengthBetweenFrontAndRearWheels + config.lengthBetweenFrontWheels) / (2.0 * config.wheelRadius)) * angularVelocity;
87 
88  wheelVelocities[0] = -RadPerSec_FromX + RadPerSec_FromY + RadPerSec_FromTheta;
89  wheelVelocities[1] = RadPerSec_FromX + RadPerSec_FromY + RadPerSec_FromTheta;
90  wheelVelocities[2] = -RadPerSec_FromX - RadPerSec_FromY + RadPerSec_FromTheta;
91  wheelVelocities[3] = RadPerSec_FromX - RadPerSec_FromY + RadPerSec_FromTheta;
92 
93  return;
94 
95  // Bouml preserved body end 0004C071
96 }
97 
103 void FourSwedishWheelOmniBaseKinematic::wheelVelocitiesToCartesianVelocity(const std::vector<quantity<angular_velocity> >& wheelVelocities, quantity<si::velocity>& longitudinalVelocity, quantity<si::velocity>& transversalVelocity, quantity<angular_velocity>& angularVelocity) {
104  // Bouml preserved body begin 0004C0F1
105 
106  if (wheelVelocities.size() < 4)
107  throw std::out_of_range("To less wheel velocities");
108 
109  if (config.lengthBetweenFrontAndRearWheels.value() == 0 || config.lengthBetweenFrontWheels.value() == 0) {
110  throw std::out_of_range("The lengthBetweenFrontAndRearWheels or the lengthBetweenFrontWheels are not allowed to be zero");
111  }
112 
113  quantity<si::length> wheel_radius_per4 = config.wheelRadius / 4.0;
114 
115  quantity<si::length> geom_factor = (config.lengthBetweenFrontAndRearWheels / 2.0) + (config.lengthBetweenFrontWheels / 2.0);
116  //now convert this to a vx,vy,vtheta
117  longitudinalVelocity = (-wheelVelocities[0] + wheelVelocities[1] - wheelVelocities[2] + wheelVelocities[3]).value() * wheel_radius_per4.value() * meter_per_second;
118  transversalVelocity = (wheelVelocities[0] + wheelVelocities[1] - wheelVelocities[2] - wheelVelocities[3]).value() * wheel_radius_per4.value() * meter_per_second;
119  angularVelocity = (wheelVelocities[0] + wheelVelocities[1] + wheelVelocities[2] + wheelVelocities[3]) * (wheel_radius_per4 / geom_factor).value();
120 
121  return;
122  // Bouml preserved body end 0004C0F1
123 }
124 
130 void FourSwedishWheelOmniBaseKinematic::wheelPositionsToCartesianPosition(const std::vector<quantity<plane_angle> >& wheelPositions, quantity<si::length>& longitudinalPosition, quantity<si::length>& transversalPosition, quantity<plane_angle>& orientation) {
131  // Bouml preserved body begin 00051371
132 
133  if (wheelPositions.size() < 4)
134  throw std::out_of_range("To less wheel positions");
135 
136  if (config.lengthBetweenFrontAndRearWheels.value() == 0 || config.lengthBetweenFrontWheels.value() == 0) {
137  throw std::out_of_range("The lengthBetweenFrontAndRearWheels or the lengthBetweenFrontWheels are not allowed to be zero");
138  }
139 
140  if (this->lastWheelPositionInitialized == false) {
141  lastWheelPositions = wheelPositions;
142  longitudinalPos = 0 * meter;
143  transversalPos = 0 * meter;
144  angle = 0 * radian;
145  this->lastWheelPositionInitialized = true;
146  }
147 
148  quantity<si::length> deltaLongitudinalPos;
149  quantity<si::length> deltaTransversalPos;
150 
151  quantity<si::length> wheel_radius_per4 = config.wheelRadius / 4.0;
152 
153  quantity<si::length> geom_factor = (config.lengthBetweenFrontAndRearWheels / 2.0) + (config.lengthBetweenFrontWheels / 2.0);
154 
155  quantity<plane_angle> deltaPositionW1 = (wheelPositions[0] - lastWheelPositions[0]);
156  quantity<plane_angle> deltaPositionW2 = (wheelPositions[1] - lastWheelPositions[1]);
157  quantity<plane_angle> deltaPositionW3 = (wheelPositions[2] - lastWheelPositions[2]);
158  quantity<plane_angle> deltaPositionW4 = (wheelPositions[3] - lastWheelPositions[3]);
159  lastWheelPositions[0] = wheelPositions[0];
160  lastWheelPositions[1] = wheelPositions[1];
161  lastWheelPositions[2] = wheelPositions[2];
162  lastWheelPositions[3] = wheelPositions[3];
163 
164  deltaLongitudinalPos = (-deltaPositionW1 + deltaPositionW2 - deltaPositionW3 + deltaPositionW4).value() * wheel_radius_per4.value() * meter;
165  deltaTransversalPos = (deltaPositionW1 + deltaPositionW2 - deltaPositionW3 - deltaPositionW4).value() * wheel_radius_per4.value() * meter;
166  angle += (deltaPositionW1 + deltaPositionW2 + deltaPositionW3 + deltaPositionW4) * (wheel_radius_per4 / geom_factor).value();
167 
168  longitudinalPos += deltaLongitudinalPos * cos(angle) - deltaTransversalPos * sin(angle);
169  transversalPos += deltaLongitudinalPos * sin(angle) + deltaTransversalPos * cos(angle);
170 
171  longitudinalPosition = longitudinalPos;
172  transversalPosition = transversalPos;
173  orientation = angle;
174 
175  return;
176  // Bouml preserved body end 00051371
177 }
178 
184 void FourSwedishWheelOmniBaseKinematic::cartesianPositionToWheelPositions(const quantity<si::length>& longitudinalPosition, const quantity<si::length>& transversalPosition, const quantity<plane_angle>& orientation, std::vector<quantity<plane_angle> >& wheelPositions) {
185  // Bouml preserved body begin 000C08F1
186 
187  quantity<plane_angle> Rad_FromX;
188  quantity<plane_angle> Rad_FromY;
189  quantity<plane_angle> Rad_FromTheta;
190  wheelPositions.assign(4, Rad_FromX);
191 
192  if (config.wheelRadius.value() == 0 || config.rotationRatio == 0 || config.slideRatio == 0) {
193  throw std::out_of_range("The wheelRadius, RotationRatio or the SlideRatio are not allowed to be zero");
194  }
195 
196  // RadPerSec_FromX = longitudinalVelocity / config.wheelRadius;
197  Rad_FromX = longitudinalPosition.value() / config.wheelRadius.value() * radian;
198  Rad_FromY = transversalPosition.value() / (config.wheelRadius.value() * config.slideRatio) * radian;
199 
200  // Calculate Rotation Component
201  Rad_FromTheta = ((config.lengthBetweenFrontAndRearWheels + config.lengthBetweenFrontWheels) / (2.0 * config.wheelRadius)) * orientation;
202 
203  wheelPositions[0] = -Rad_FromX + Rad_FromY + Rad_FromTheta;
204  wheelPositions[1] = Rad_FromX + Rad_FromY + Rad_FromTheta;
205  wheelPositions[2] = -Rad_FromX - Rad_FromY + Rad_FromTheta;
206  wheelPositions[3] = Rad_FromX - Rad_FromY + Rad_FromTheta;
207 
208  return;
209 
210  // Bouml preserved body end 000C08F1
211 }
212 
214  // Bouml preserved body begin 0004C171
215  this->config = configuration;
216  // Bouml preserved body end 0004C171
217 }
218 
220  // Bouml preserved body begin 0004C1F1
221  configuration = this->config;
222  // Bouml preserved body end 0004C1F1
223 }
224 
225 
226 } // namespace youbot
virtual void wheelVelocitiesToCartesianVelocity(const std::vector< quantity< angular_velocity > > &wheelVelocities, quantity< si::velocity > &longitudinalVelocity, quantity< si::velocity > &transversalVelocity, quantity< angular_velocity > &angularVelocity)
void setConfiguration(const FourSwedishWheelOmniBaseKinematicConfiguration &configuration)
void getConfiguration(FourSwedishWheelOmniBaseKinematicConfiguration &configuration) const
std::vector< quantity< plane_angle > > lastWheelPositions
virtual void cartesianPositionToWheelPositions(const quantity< si::length > &longitudinalPosition, const quantity< si::length > &transversalPosition, const quantity< plane_angle > &orientation, std::vector< quantity< plane_angle > > &wheelPositions)
FourSwedishWheelOmniBaseKinematicConfiguration config
Configuration for the base kinematic with four swedish wheels.
virtual void cartesianVelocityToWheelVelocities(const quantity< si::velocity > &longitudinalVelocity, const quantity< si::velocity > &transversalVelocity, const quantity< si::angular_velocity > &angularVelocity, std::vector< quantity< angular_velocity > > &wheelVelocities)
virtual void wheelPositionsToCartesianPosition(const std::vector< quantity< plane_angle > > &wheelPositions, quantity< si::length > &longitudinalPosition, quantity< si::length > &transversalPosition, quantity< plane_angle > &orientation)


youbot_driver
Author(s): Jan Paulus
autogenerated on Mon Jun 10 2019 15:46:24