Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include "HandJoystick.hpp"
00009
00010 #include <telekyb_base/ROS.hpp>
00011
00012
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
00026
00027 if (msg->axes.size() < 3) {
00028 ROS_ERROR("We need at least 3 Axes!");
00029 return;
00030 }
00031
00032
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
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
00052
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
00068
00069 if (tHandJoystickUsePositionMode->getValue()) {
00070 posModeCurPosition = currentState.position;
00071 posModeCurYawAngle = currentState.getEulerRPY()(2);
00072 posModeLastInputTime = Time();
00073 }
00074
00075
00076
00077 return true;
00078 }
00079
00080 void HandJoystick::didBecomeActive(const TKState& currentState, const Behavior& previousBehavior)
00081 {
00082
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
00093 }
00094
00095
00096 void HandJoystick::trajectoryStepCreation(const TKState& currentState, TKTrajInput& generatedTrajInput)
00097 {
00098 trajectoryStepActive(currentState, generatedTrajInput);
00099 }
00100
00101
00102 void HandJoystick::trajectoryStepActive(const TKState& currentState, TKTrajInput& generatedTrajInput)
00103 {
00104 if (tHandJoystickUsePositionMode->getValue()) {
00105
00106 double timeDiffSec = (Time() - posModeLastInputTime).toDSec();
00107
00108 posModeLastInputTime = Time();
00109 posModeCurPosition += (lastVelocityInput * timeDiffSec);
00110
00111
00112
00113
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
00125 void HandJoystick::trajectoryStepTermination(const TKState& currentState, TKTrajInput& generatedTrajInput)
00126 {
00127 generatedTrajInput.setVelocity( Velocity3D::Zero() );
00128 generatedTrajInput.setYawRate( 0.0 );
00129 }
00130
00131
00132 bool HandJoystick::isValid(const TKState& currentState) const
00133 {
00134 return tHandJoystickMinHeight->getValue() > currentState.position(2);
00135 }
00136
00137 }