LLJoystick.cpp
Go to the documentation of this file.
00001 /*
00002  * LLJoystick.cpp
00003  *
00004  *  Created on: Oct 29, 2011
00005  *      Author: mriedel
00006  */
00007 
00008 #include "LLJoystick.hpp"
00009 
00010 #include <telekyb_base/TeleKyb.hpp>
00011 #include <telekyb_base/ROS.hpp>
00012 
00013 
00014 // I hope this get's removed soon
00015 #define PITCH_ROLL_CMD_DEG_SCALE 4.0
00016 
00017 #define ZERO_STICK_VALUE 66.0
00018 #define MIN_THRUST_CMD 28 // 8 + 20 (delta_trust in SaturateMotors())
00019 #define MAX_THRUST_CMD 210 // 230 - 20 (delta_trust in SaturateMotors())
00020 
00021 
00022 // main
00023 int main(int argc, char **argv) {
00024 
00025         telekyb::TeleKyb::init(argc, argv, "LLCommands");
00026 
00027         telekyb::LLJoystick j;
00028         j.run();
00029 
00030         telekyb::TeleKyb::shutdown();
00031 
00032         return 0;
00033 }
00034 
00035 
00036 namespace TELEKYB_NAMESPACE {
00037 
00038 
00039 LLJoystick::LLJoystick()
00040         : rollCmd(0), pitchCmd(0), yawCmd(0), thrustCmd(0)
00041 {
00042         nodeHandle = ROSModule::Instance().getMainNodeHandle();
00043         joystick = nodeHandle.subscribe(options.tJoystickTopic->getValue()
00044                                 , 1, &LLJoystick::joystickCB, this);
00045         llCommand = nodeHandle.advertise<telekyb_msgs::TKTTCommands>(options.tLLCommandsTopic->getValue(),1);
00046 
00047 }
00048 
00049 LLJoystick::~LLJoystick()
00050 {
00051 
00052 }
00053 
00054 
00055 void LLJoystick::joystickCB(const sensor_msgs::Joy::ConstPtr& msg)
00056 {
00057         // we use the first three axes.
00058         if (msg->axes.size() < 4) {
00059                 ROS_ERROR_STREAM("Discarding Joystick Input from " << options.tJoystickTopic->getValue()
00060                                 << ". At least 4 Axes are needed. Received: " << msg->axes.size());
00061                 return;
00062         }
00063 
00064 
00065 //      decThrust = fmax( (Decimal)MIN_THRUST_CMD , fmin((Decimal)MAX_THRUST_CMD ,106.0 + 300.0*pos.z() ) );
00066 //      decRoll  = PITCH_ROLL_CMD_DEG_SCALE*100.0*pos.x();
00067 //      decPitch = PITCH_ROLL_CMD_DEG_SCALE*100.0*pos.y();
00068 //      decYawRate   = 100.0*oriVel.z();
00069 
00070         thrustCmd = std::max( MIN_THRUST_CMD , std::min(MAX_THRUST_CMD , (int)(ZERO_STICK_VALUE + 10.0*msg->axes[3]) ) );
00071         rollCmd  = PITCH_ROLL_CMD_DEG_SCALE*25.0*msg->axes[0];
00072         pitchCmd = PITCH_ROLL_CMD_DEG_SCALE*25.0*msg->axes[1];
00073         yawCmd   = 100.0*msg->axes[2];
00074 
00075 }
00076 
00077 void LLJoystick::run()
00078 {
00079         ros::Rate rate(options.tCommandRate->getValue());
00080 
00081         while(ros::ok()) {
00082                 // read joystick translate into command
00083                 telekyb_msgs::TKTTCommands msg;
00084                 msg.header.stamp = ros::Time::now();
00085                 msg.roll_torque = rollCmd;
00086                 msg.pitch_torque = pitchCmd;
00087                 msg.yaw_torque = yawCmd;
00088                 msg.thrust = thrustCmd;
00089 
00090                 llCommand.publish(msg);
00091 
00092                 rate.sleep();
00093         }
00094 }
00095 
00096 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines


telekyb_core
Author(s): Dr. Antonio Franchi and Martin Riedel
autogenerated on Mon Nov 11 2013 11:13:47