FourSwedishWheelOmniBaseKinematic.cpp
Go to the documentation of this file.
00001 /****************************************************************
00002  *
00003  * Copyright (c) 2011
00004  * All rights reserved.
00005  *
00006  * Hochschule Bonn-Rhein-Sieg
00007  * University of Applied Sciences
00008  * Computer Science Department
00009  *
00010  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00011  *
00012  * Author:
00013  * Jan Paulus, Nico Hochgeschwender, Michael Reckhaus, Azamat Shakhimardanov
00014  * Supervised by:
00015  * Gerhard K. Kraetzschmar
00016  *
00017  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00018  *
00019  * This sofware is published under a dual-license: GNU Lesser General Public 
00020  * License LGPL 2.1 and BSD license. The dual-license implies that users of this
00021  * code may choose which terms they prefer.
00022  *
00023  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00024  *
00025  * Redistribution and use in source and binary forms, with or without
00026  * modification, are permitted provided that the following conditions are met:
00027  *
00028  *     * Redistributions of source code must retain the above copyright
00029  *       notice, this list of conditions and the following disclaimer.
00030  *     * Redistributions in binary form must reproduce the above copyright
00031  *       notice, this list of conditions and the following disclaimer in the
00032  *       documentation and/or other materials provided with the distribution.
00033  *     * Neither the name of the Hochschule Bonn-Rhein-Sieg nor the names of its
00034  *       contributors may be used to endorse or promote products derived from
00035  *       this software without specific prior written permission.
00036  *
00037  * This program is free software: you can redistribute it and/or modify
00038  * it under the terms of the GNU Lesser General Public License LGPL as
00039  * published by the Free Software Foundation, either version 2.1 of the
00040  * License, or (at your option) any later version or the BSD license.
00041  *
00042  * This program is distributed in the hope that it will be useful,
00043  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00044  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00045  * GNU Lesser General Public License LGPL and the BSD license for more details.
00046  *
00047  * You should have received a copy of the GNU Lesser General Public
00048  * License LGPL and BSD license along with this program.
00049  *
00050  ****************************************************************/
00051 #include <youbot_driver/base-kinematic/FourSwedishWheelOmniBaseKinematic.hpp>
00052 namespace youbot
00053 {
00054 
00055 FourSwedishWheelOmniBaseKinematic::FourSwedishWheelOmniBaseKinematic()
00056 {
00057   // Bouml preserved body begin 000513F1
00058   this->lastWheelPositionInitialized = false;
00059   // Bouml preserved body end 000513F1
00060 }
00061 
00062 FourSwedishWheelOmniBaseKinematic::~FourSwedishWheelOmniBaseKinematic()
00063 {
00064   // Bouml preserved body begin 00051471
00065   // Bouml preserved body end 00051471
00066 }
00067 
00073 void FourSwedishWheelOmniBaseKinematic::cartesianVelocityToWheelVelocities(
00074     const quantity<si::velocity>& longitudinalVelocity, const quantity<si::velocity>& transversalVelocity,
00075     const quantity<si::angular_velocity>& angularVelocity, std::vector<quantity<angular_velocity> >& wheelVelocities)
00076 {
00077   // Bouml preserved body begin 0004C071
00078   quantity<angular_velocity> RadPerSec_FromX;
00079   quantity<angular_velocity> RadPerSec_FromY;
00080   quantity<angular_velocity> RadPerSec_FromTheta;
00081   wheelVelocities.assign(4, RadPerSec_FromX);
00082 
00083   if (config.wheelRadius.value() == 0 || config.rotationRatio == 0 || config.slideRatio == 0)
00084   {
00085     throw std::out_of_range("The wheelRadius, RotationRatio or the SlideRatio are not allowed to be zero");
00086   }
00087 
00088   // RadPerSec_FromX = longitudinalVelocity / config.wheelRadius;
00089   RadPerSec_FromX = longitudinalVelocity.value() / config.wheelRadius.value() * radian_per_second;
00090   RadPerSec_FromY = transversalVelocity.value() / (config.wheelRadius.value() * config.slideRatio) * radian_per_second;
00091 
00092   // Calculate Rotation Component
00093   RadPerSec_FromTheta = ((config.lengthBetweenFrontAndRearWheels + config.lengthBetweenFrontWheels)
00094       / (2.0 * config.wheelRadius)) * angularVelocity;
00095 
00096   wheelVelocities[0] = -RadPerSec_FromX + RadPerSec_FromY + RadPerSec_FromTheta;
00097   wheelVelocities[1] = RadPerSec_FromX + RadPerSec_FromY + RadPerSec_FromTheta;
00098   wheelVelocities[2] = -RadPerSec_FromX - RadPerSec_FromY + RadPerSec_FromTheta;
00099   wheelVelocities[3] = RadPerSec_FromX - RadPerSec_FromY + RadPerSec_FromTheta;
00100 
00101   return;
00102 
00103   // Bouml preserved body end 0004C071
00104 }
00105 
00111 void FourSwedishWheelOmniBaseKinematic::wheelVelocitiesToCartesianVelocity(
00112     const std::vector<quantity<angular_velocity> >& wheelVelocities, quantity<si::velocity>& longitudinalVelocity,
00113     quantity<si::velocity>& transversalVelocity, quantity<angular_velocity>& angularVelocity)
00114 {
00115   // Bouml preserved body begin 0004C0F1
00116 
00117   if (wheelVelocities.size() < 4)
00118     throw std::out_of_range("To less wheel velocities");
00119 
00120   if (config.lengthBetweenFrontAndRearWheels.value() == 0 || config.lengthBetweenFrontWheels.value() == 0)
00121   {
00122     throw std::out_of_range(
00123         "The lengthBetweenFrontAndRearWheels or the lengthBetweenFrontWheels are not allowed to be zero");
00124   }
00125 
00126   quantity<si::length> wheel_radius_per4 = config.wheelRadius / 4.0;
00127 
00128   quantity<si::length> geom_factor = (config.lengthBetweenFrontAndRearWheels / 2.0)
00129       + (config.lengthBetweenFrontWheels / 2.0);
00130   //now convert this to a vx,vy,vtheta
00131   longitudinalVelocity = (-wheelVelocities[0] + wheelVelocities[1] - wheelVelocities[2] + wheelVelocities[3]).value()
00132       * wheel_radius_per4.value() * meter_per_second;
00133   transversalVelocity = (wheelVelocities[0] + wheelVelocities[1] - wheelVelocities[2] - wheelVelocities[3]).value()
00134       * wheel_radius_per4.value() * meter_per_second;
00135   angularVelocity = (wheelVelocities[0] + wheelVelocities[1] + wheelVelocities[2] + wheelVelocities[3])
00136       * (wheel_radius_per4 / geom_factor).value();
00137 
00138   return;
00139   // Bouml preserved body end 0004C0F1
00140 }
00141 
00147 void FourSwedishWheelOmniBaseKinematic::wheelPositionsToCartesianPosition(
00148     const std::vector<quantity<plane_angle> >& wheelPositions, quantity<si::length>& longitudinalPosition,
00149     quantity<si::length>& transversalPosition, quantity<plane_angle>& orientation)
00150 {
00151   // Bouml preserved body begin 00051371
00152 
00153   if (wheelPositions.size() < 4)
00154     throw std::out_of_range("To less wheel positions");
00155 
00156   if (config.lengthBetweenFrontAndRearWheels.value() == 0 || config.lengthBetweenFrontWheels.value() == 0)
00157   {
00158     throw std::out_of_range(
00159         "The lengthBetweenFrontAndRearWheels or the lengthBetweenFrontWheels are not allowed to be zero");
00160   }
00161 
00162   if (this->lastWheelPositionInitialized == false)
00163   {
00164     lastWheelPositions = wheelPositions;
00165     longitudinalPos = 0 * meter;
00166     transversalPos = 0 * meter;
00167     angle = 0 * radian;
00168     this->lastWheelPositionInitialized = true;
00169   }
00170 
00171   quantity<si::length> deltaLongitudinalPos;
00172   quantity<si::length> deltaTransversalPos;
00173 
00174   quantity<si::length> wheel_radius_per4 = config.wheelRadius / 4.0;
00175 
00176   quantity<si::length> geom_factor = (config.lengthBetweenFrontAndRearWheels / 2.0)
00177       + (config.lengthBetweenFrontWheels / 2.0);
00178 
00179   quantity<plane_angle> deltaPositionW1 = (wheelPositions[0] - lastWheelPositions[0]);
00180   quantity<plane_angle> deltaPositionW2 = (wheelPositions[1] - lastWheelPositions[1]);
00181   quantity<plane_angle> deltaPositionW3 = (wheelPositions[2] - lastWheelPositions[2]);
00182   quantity<plane_angle> deltaPositionW4 = (wheelPositions[3] - lastWheelPositions[3]);
00183   lastWheelPositions[0] = wheelPositions[0];
00184   lastWheelPositions[1] = wheelPositions[1];
00185   lastWheelPositions[2] = wheelPositions[2];
00186   lastWheelPositions[3] = wheelPositions[3];
00187 
00188   deltaLongitudinalPos = (-deltaPositionW1 + deltaPositionW2 - deltaPositionW3 + deltaPositionW4).value()
00189       * wheel_radius_per4.value() * meter;
00190   deltaTransversalPos = (deltaPositionW1 + deltaPositionW2 - deltaPositionW3 - deltaPositionW4).value()
00191       * wheel_radius_per4.value() * meter;
00192   angle += (deltaPositionW1 + deltaPositionW2 + deltaPositionW3 + deltaPositionW4)
00193       * (wheel_radius_per4 / geom_factor).value();
00194 
00195   longitudinalPos += deltaLongitudinalPos * cos(angle) - deltaTransversalPos * sin(angle);
00196   transversalPos += deltaLongitudinalPos * sin(angle) + deltaTransversalPos * cos(angle);
00197 
00198   longitudinalPosition = longitudinalPos;
00199   transversalPosition = transversalPos;
00200   orientation = angle;
00201 
00202   return;
00203   // Bouml preserved body end 00051371
00204 }
00205 
00211 void FourSwedishWheelOmniBaseKinematic::cartesianPositionToWheelPositions(
00212     const quantity<si::length>& longitudinalPosition, const quantity<si::length>& transversalPosition,
00213     const quantity<plane_angle>& orientation, std::vector<quantity<plane_angle> >& wheelPositions)
00214 {
00215   // Bouml preserved body begin 000C08F1
00216 
00217   quantity<plane_angle> Rad_FromX;
00218   quantity<plane_angle> Rad_FromY;
00219   quantity<plane_angle> Rad_FromTheta;
00220   wheelPositions.assign(4, Rad_FromX);
00221 
00222   if (config.wheelRadius.value() == 0 || config.rotationRatio == 0 || config.slideRatio == 0)
00223   {
00224     throw std::out_of_range("The wheelRadius, RotationRatio or the SlideRatio are not allowed to be zero");
00225   }
00226 
00227   // RadPerSec_FromX = longitudinalVelocity / config.wheelRadius;
00228   Rad_FromX = longitudinalPosition.value() / config.wheelRadius.value() * radian;
00229   Rad_FromY = transversalPosition.value() / (config.wheelRadius.value() * config.slideRatio) * radian;
00230 
00231   // Calculate Rotation Component
00232   Rad_FromTheta = ((config.lengthBetweenFrontAndRearWheels + config.lengthBetweenFrontWheels)
00233       / (2.0 * config.wheelRadius)) * orientation;
00234 
00235   wheelPositions[0] = -Rad_FromX + Rad_FromY + Rad_FromTheta;
00236   wheelPositions[1] = Rad_FromX + Rad_FromY + Rad_FromTheta;
00237   wheelPositions[2] = -Rad_FromX - Rad_FromY + Rad_FromTheta;
00238   wheelPositions[3] = Rad_FromX - Rad_FromY + Rad_FromTheta;
00239 
00240   return;
00241 
00242   // Bouml preserved body end 000C08F1
00243 }
00244 
00245 void FourSwedishWheelOmniBaseKinematic::setConfiguration(
00246     const FourSwedishWheelOmniBaseKinematicConfiguration& configuration)
00247 {
00248   // Bouml preserved body begin 0004C171
00249   this->config = configuration;
00250   // Bouml preserved body end 0004C171
00251 }
00252 
00253 void FourSwedishWheelOmniBaseKinematic::getConfiguration(
00254     FourSwedishWheelOmniBaseKinematicConfiguration& configuration) const
00255 {
00256   // Bouml preserved body begin 0004C1F1
00257   configuration = this->config;
00258   // Bouml preserved body end 0004C1F1
00259 }
00260 
00261 } // namespace youbot


youbot_driver
Author(s): Jan Paulus
autogenerated on Mon Oct 6 2014 09:08:01