Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include <trajmodules/VMSaturation.hpp>
00009
00010
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
00039 void VMSaturation::willTurnActive()
00040 {
00041 lastVelocity = Velocity3D::Zero();
00042 lastVelocityTimer.reset();
00043 }
00044
00045
00046 void VMSaturation::didTurnInactive()
00047 {
00048 }
00049
00050 bool VMSaturation::trajectoryStep(const TKState& currentState, TKTrajectory& trajInput)
00051 {
00052
00053
00054
00055 if(trajInput.velocity.norm() > options.tMaxVel->getValue()) {
00056
00057 trajInput.velocity.normalize();
00058 trajInput.velocity *= fabs(options.tMaxVel->getValue());
00059 trajInput.acceleration = Acceleration3D(0.0,0.0,0.0);
00060 }
00061
00062
00063 Velocity3D velDiff = trajInput.velocity - lastVelocity;
00064 double elapsedSec = lastVelocityTimer.getElapsed().toDSec();
00065 lastVelocityTimer.reset();
00066
00067
00068
00069 if(velDiff.norm() / elapsedSec < options.tMaxVelRate->getValue()) {
00070 lastVelocity = trajInput.velocity;
00071 }else{
00072
00073 lastVelocity += velDiff.normalized() * options.tMaxVelRate->getValue() * elapsedSec;
00074 }
00075
00076 trajInput.velocity = lastVelocity;
00077
00078 return true;
00079 }
00080
00081 }