VMSaturation.cpp
Go to the documentation of this file.
00001 /*
00002  * VMSaturation.cpp
00003  *
00004  *  Created on: Dec 14, 2011
00005  *      Author: mriedel
00006  */
00007 
00008 #include <trajmodules/VMSaturation.hpp>
00009 
00010 // Declare
00011 PLUGINLIB_DECLARE_CLASS(tk_trajprocessor, VMSaturation, telekyb_traj::VMSaturation, TELEKYB_NAMESPACE::TrajectoryModule);
00012 
00013 namespace telekyb_traj {
00014 
00015 VMSaturationOptions::VMSaturationOptions()
00016         : OptionContainer("VMSaturation")
00017 {
00018         tMaxVel = addOption<double>( "tMaxVel", "Maximum velocity in velocity mode", 100.0, false, true);
00019         tMaxVelRate = addOption<double>( "tMaxVelRate", "Maximum velocity rate in velocity mode", 10.0, false, true);
00020 }
00021 
00022 VMSaturation::VMSaturation()
00023         : TrajectoryModule("tk_trajprocessor/VMSaturation", TrajModulePosType::Velocity, -100)
00024 {
00025 
00026 }
00027 
00028 void VMSaturation::initialize()
00029 {
00030 
00031 }
00032 
00033 void VMSaturation::destroy()
00034 {
00035 
00036 }
00037 
00038 // set back to intial conditions
00039 void VMSaturation::willTurnActive()
00040 {
00041         lastVelocity = Velocity3D::Zero();
00042         lastVelocityTimer.reset();
00043 }
00044 
00045 // called after turning inactive
00046 void VMSaturation::didTurnInactive()
00047 {
00048 }
00049 
00050 bool VMSaturation::trajectoryStep(const TKState& currentState, TKTrajectory& trajInput)
00051 {
00052         //ROS_INFO("Called VMSaturation");
00053 
00054         // Velocity Saturation
00055         if(trajInput.velocity.norm() > options.tMaxVel->getValue()) {
00056                 //ROS_WARN("Saturating commanded Velocity to %f", options.tMaxVel->getValue());
00057                 trajInput.velocity.normalize();
00058                 trajInput.velocity *= fabs(options.tMaxVel->getValue());
00059                 trajInput.acceleration = Acceleration3D(0.0,0.0,0.0);
00060         }
00061 
00062         // Velocity Rate Saturation
00063         Velocity3D velDiff = trajInput.velocity - lastVelocity;
00064         double elapsedSec = lastVelocityTimer.getElapsed().toDSec();
00065         lastVelocityTimer.reset();
00066 
00067         //ROS_INFO("VelRate: %f", velDiff.norm() / elapsedSec);
00068 
00069         if(velDiff.norm() / elapsedSec < options.tMaxVelRate->getValue()) {
00070                 lastVelocity = trajInput.velocity;
00071         }else{
00072                 //ROS_INFO("Saturating Velocity Rate.");
00073                 lastVelocity += velDiff.normalized() * options.tMaxVelRate->getValue() * elapsedSec;
00074         }
00075 
00076         trajInput.velocity = lastVelocity;
00077 
00078         return true;
00079 }
00080 
00081 } /* namespace telekyb_traj */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines


tk_trajprocessor
Author(s): Martin Riedel
autogenerated on Mon Nov 11 2013 11:13:30