HandJoystick.cpp
Go to the documentation of this file.
00001 /*
00002  * HandJoystick.cpp
00003  *
00004  *  Created on: Nov 12, 2011
00005  *      Author: mriedel
00006  */
00007 
00008 #include "HandJoystick.hpp"
00009 
00010 #include <telekyb_base/ROS.hpp>
00011 
00012 // Declare
00013 PLUGINLIB_DECLARE_CLASS(tk_vrqc2011, HandJoystick, telekyb_behavior::HandJoystick, TELEKYB_NAMESPACE::Behavior);
00014 
00015 namespace telekyb_behavior {
00016 
00017 HandJoystick::HandJoystick()
00018         : Behavior("tk_be_common/HandJoystick", BehaviorType::Air)
00019 {
00020 
00021 }
00022 
00023 void HandJoystick::joystickCB(const sensor_msgs::Joy::ConstPtr& msg)
00024 {
00025 //      ROS_INFO("Received HandJoystick CB");
00026 
00027         if (msg->axes.size() < 3) {
00028                 ROS_ERROR("We need at least 3 Axes!");
00029                 return;
00030         }
00031 
00032         // INPUT is already correctly in NED!
00033         lastVelocityInput = Velocity3D(msg->axes[0],msg->axes[1], msg->axes[2]) * tHandJoystickScale->getValue();
00034 }
00035 
00036 void HandJoystick::initialize()
00037 {
00038         tHandJoystickTopic = addOption<std::string>("tHandJoystickTopic",
00039                         "HandJoystickTopic that published sensor_msgs::Joy",
00040                         "/TeleKyb/tJoy/joy", false, false);
00041 
00042         tHandJoystickUsePositionMode = addOption("tHandJoystickUsePositionMode",
00043                         "Integrates Position from Velocity input.", false, false, false);
00044         //tHandJoystickYawRateScale = addOption("tHandJoystickYawRateScale","Commanded Yaw Rate is scaled to this value", 1.0, false ,false);
00045         tHandJoystickMinHeight = addOption<double>("tHandJoystickMinHeight",
00046                         "minimal valid height (z inverse!)", -0.5, false, false);
00047         tHandJoystickScale = addOption<double>("tHandJoystickScale",
00048                         "Scale Input by Value", 0.5, false, false);
00049         nodeHandle = ROSModule::Instance().getMainNodeHandle();
00050 
00051         // no Parameters
00052         //parameterInitialized = true;
00053 }
00054 
00055 void HandJoystick::destroy()
00056 {
00057 
00058 }
00059 
00060 
00061 bool HandJoystick::willBecomeActive(const TKState& currentState, const Behavior& previousBehavior)
00062 {
00063         joySub = nodeHandle.subscribe(tHandJoystickTopic->getValue()
00064                         , 10, &HandJoystick::joystickCB, this);
00065 
00066         lastVelocityInput = Velocity3D::Zero();
00067         //lastYawRateInput = 0.0;
00068 
00069         if (tHandJoystickUsePositionMode->getValue()) {
00070                 posModeCurPosition = currentState.position;
00071                 posModeCurYawAngle = currentState.getEulerRPY()(2);
00072                 posModeLastInputTime = Time();
00073         }
00074 
00075         //isValid = true;
00076 
00077         return true;
00078 }
00079 
00080 void HandJoystick::didBecomeActive(const TKState& currentState, const Behavior& previousBehavior)
00081 {
00082         // not used
00083 }
00084 
00085 void HandJoystick::willBecomeInActive(const TKState& currentState, const Behavior& nextBehavior)
00086 {
00087         joySub.shutdown();
00088 }
00089 
00090 void HandJoystick::didBecomeInActive(const TKState& currentState, const Behavior& nextBehavior)
00091 {
00092         // not used
00093 }
00094 
00095 // called everytime a new TKState is available AND it is the NEW Behavior of an active Switch
00096 void HandJoystick::trajectoryStepCreation(const TKState& currentState, TKTrajInput& generatedTrajInput)
00097 {
00098         trajectoryStepActive(currentState, generatedTrajInput);
00099 }
00100 
00101 // called everytime a new TKState is available. Should return false if invalid (swtich to next behavior, or Hover if undef).
00102 void HandJoystick::trajectoryStepActive(const TKState& currentState, TKTrajInput& generatedTrajInput)
00103 {
00104         if (tHandJoystickUsePositionMode->getValue()) {
00105                 // integrate Position
00106                 double timeDiffSec = (Time() - posModeLastInputTime).toDSec();
00107 //              ROS_INFO("timeDiffSec: %f", timeDiffSec);
00108                 posModeLastInputTime = Time();
00109                 posModeCurPosition += (lastVelocityInput * timeDiffSec);
00110                 //posModeCurYawAngle += (0.0 * timeDiffSec);
00111 
00112 //              ROS_INFO_STREAM("Position: " << std::endl << posModeCurPosition);
00113 //              ROS_INFO_STREAM("YawAngle: " << posModeCurYawAngle.dCast());
00114 
00115                 generatedTrajInput.setPosition(posModeCurPosition, lastVelocityInput);
00116                 generatedTrajInput.setYawAngle(posModeCurYawAngle.dCastPi(0), 0.0);
00117 
00118         } else {
00119                 generatedTrajInput.setVelocity(lastVelocityInput);
00120                 generatedTrajInput.setYawRate(0.0);
00121         }
00122 }
00123 
00124 // called everytime a new TKState is available AND it is the OLD Behavior of an active Switch
00125 void HandJoystick::trajectoryStepTermination(const TKState& currentState, TKTrajInput& generatedTrajInput)
00126 {
00127         generatedTrajInput.setVelocity( Velocity3D::Zero() );
00128         generatedTrajInput.setYawRate( 0.0 );
00129 }
00130 
00131 // Return true if the active Behavior is (still) valid. Initiate Switch otherwise
00132 bool HandJoystick::isValid(const TKState& currentState) const
00133 {
00134         return tHandJoystickMinHeight->getValue() > currentState.position(2);
00135 }
00136 
00137 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


tk_vrqc2011
Author(s): Martin Riedel
autogenerated on Wed Apr 24 2013 11:26:17