HandJoystick.cpp
Go to the documentation of this file.
00001 /*
00002  * HandJoystick.cpp
00003  *
00004  *  Created on: Jan 5, 2012
00005  *      Author: mriedel
00006  */
00007 
00008 #include "HandJoystick.hpp"
00009 
00010 #include <telekyb_base/ROS.hpp>
00011 
00012 #define JOYMSG_BUTTONS 3 // all 0.
00013 #define JOYMSG_AXES 3 // At least 3
00014 
00015 namespace TELEKYB_NAMESPACE {
00016 
00017 HandJoystick::HandJoystick()
00018         : neutralPosSet(false), neutralPosSetRequest(false)
00019 {
00020         ros::NodeHandle mainNodeHandle(ROSModule::Instance().getMainNodeHandle());
00021         joySub = mainNodeHandle.subscribe(options.tJoystickTopic->getValue()
00022                         , 10, &HandJoystick::joystickCB, this);
00023         transformSub = mainNodeHandle.subscribe(options.tTransformStampedTopic->getValue()
00024                                 , 10, &HandJoystick::transformCB, this);
00025 
00026         pubJoy = mainNodeHandle.advertise<sensor_msgs::Joy>(options.tJoyPubName->getValue(), 10 );
00027         pubTransform = mainNodeHandle.advertise<geometry_msgs::TransformStamped>(options.tTransformPubName->getValue(),10);
00028 }
00029 
00030 HandJoystick::~HandJoystick()
00031 {
00032 
00033 }
00034 
00035 void HandJoystick::joystickCB(const sensor_msgs::Joy::ConstPtr& msg)
00036 {
00037         if (msg->buttons[9]) {
00038                 neutralPosSetRequest = true;
00039                 ROS_INFO("Setting Neutral Position");
00040         }
00041 }
00042 
00043 void HandJoystick::transformCB(const geometry_msgs::TransformStamped::ConstPtr& msg)
00044 {
00045         // BEWARE! I put in a const NED Transform here!!! Without matrix
00046 
00047         if (neutralPosSetRequest) {
00048                 neutralPosition(0) = msg->transform.translation.x;
00049                 neutralPosition(1) = msg->transform.translation.y;
00050                 neutralPosition(2) = msg->transform.translation.z;
00051 
00052                 neutralPosSetRequest = false;
00053                 neutralPosSet = true;
00054         }
00055 
00056         //ROS_INFO("Transform CB");
00057 
00058         if (neutralPosSet) {
00059                 sensor_msgs::Joy joyMsg;
00060                 joyMsg.axes.resize(JOYMSG_AXES, 0.0);
00061                 joyMsg.buttons.resize(JOYMSG_BUTTONS, 0);
00062 
00063                 joyMsg.axes[0] = options.tAxisValueScale->getValue() * (msg->transform.translation.x - neutralPosition(0));
00064                 joyMsg.axes[1] = -1.0 * options.tAxisValueScale->getValue() * (msg->transform.translation.y - neutralPosition(1));
00065                 joyMsg.axes[2] = -1.0 * options.tAxisValueScale->getValue() * (msg->transform.translation.z - neutralPosition(2));
00066 
00067                 for (unsigned int i = 0; i < joyMsg.axes.size(); ++i) {
00068                         if (fabs(joyMsg.axes[i]) > options.tMaxAxisValue->getValue()) {
00069                                 joyMsg.axes[i] = copysign(options.tMaxAxisValue->getValue(), joyMsg.axes[i]);
00070                         }
00071                 }
00072 
00073                 // Transform
00074                 geometry_msgs::TransformStamped transformMsg(*msg);
00075                 transformMsg.transform.translation.x = joyMsg.axes[0];
00076                 transformMsg.transform.translation.y = joyMsg.axes[1];
00077                 transformMsg.transform.translation.z = joyMsg.axes[2];
00078 
00079                 transformMsg.transform.rotation.y *= -1.0;
00080                 transformMsg.transform.rotation.z *= -1.0;
00081 
00082                 pubJoy.publish(joyMsg);
00083 
00084                 pubTransform.publish(transformMsg);
00085 
00086         }
00087 }
00088 
00089 } /* namespace telekyb_traj */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines


tk_handjoystick
Author(s): Martin Riedel
autogenerated on Mon Nov 11 2013 11:14:55