RmpXboxConverter.cpp
Go to the documentation of this file.
00001 /*
00002   COPYRIGHT (c) 2014 SEGWAY Inc.
00003 
00004   Software License Agreement:
00005 
00006   The software supplied herewith by Segway Inc. (the "Company") for its 
00007   RMP Robotic Platforms is intended and supplied to you, the Company's 
00008   customer, for use solely and exclusively with Segway products. The 
00009   software is owned by the Company and/or its supplier, and is protected 
00010   under applicable copyright laws.  All rights are reserved. Any use in 
00011   violation of the foregoing restrictions may subject the user to criminal
00012   sanctions under applicable laws, as well as to civil liability for the 
00013   breach of the terms and conditions of this license. The Company may 
00014   immediately terminate this Agreement upon your use of the software with 
00015   any products that are not Segway products.
00016 
00017   You shall indemnify, defend and hold the Company harmless from any claims, 
00018   demands, liabilities or expenses, including reasonable attorneys fees, incurred 
00019   by the Company as a result of any claim or proceeding against the Company 
00020   arising out of or based upon: 
00021 
00022   (i) The combination, operation or use of the software by you with any hardware, 
00023       products, programs or data not supplied or approved in writing by the Company, 
00024       if such claim or proceeding would have been avoided but for such combination, 
00025       operation or use.
00026 
00027   (ii) The modification of the software by or on behalf of you.
00028 
00029   (iii) Your use of the software.
00030 
00031   THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES,
00032   WHETHER EXPRESS, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED
00033   TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00034   PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
00035   IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
00036   CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
00037 */
00038 
00039 #include <RmpXboxConverter.h>
00040 
00041 #include <stdint.h>
00042 #include <sstream>
00043 #include <exception>
00044 
00045 #include <rmp_msgs/AudioCommand.h>
00046 
00047 static const uint32_t WIRELESS_AXES_SIZE = 6;
00048 static const uint32_t WIRELESS_BUTTONS_SIZE = 15;
00049 static const uint32_t WIRELESS_TRANSLATIONAL_VELOCITY_IDX = 4;
00050 static const uint32_t WIRELESS_ROTATIONAL_VELOCITY_IDX = 3;
00051 static const uint32_t WIRELESS_DEADMAN_IDX = 5;
00052 static const uint32_t WIRELESS_BOOST_IDX = 1;
00053 static const uint32_t WIRELESS_AUDIO_SWEEP_IDX = 0;
00054 
00055 XboxWirelessConverter::XboxWirelessConverter()
00056   : JoystickConverter()
00057 {}
00058 
00059 XboxWirelessConverter::~XboxWirelessConverter()
00060 {}
00061 
00062 double XboxWirelessConverter::GetTranslationalVelocity(const sensor_msgs::Joy& rJoyMessage)
00063 {
00064   IsValid(rJoyMessage);
00065   
00066   return rJoyMessage.axes[WIRELESS_TRANSLATIONAL_VELOCITY_IDX];
00067 }
00068 
00069 double XboxWirelessConverter::GetRotationalVelocity(const sensor_msgs::Joy& rJoyMessage)
00070 {
00071   IsValid(rJoyMessage);
00072 
00073   return rJoyMessage.axes[WIRELESS_ROTATIONAL_VELOCITY_IDX];
00074 }
00075 
00076 bool XboxWirelessConverter::GetDeadman(const sensor_msgs::Joy& rJoyMessage)
00077 {
00078   IsValid(rJoyMessage);
00079   
00080   return (rJoyMessage.axes[WIRELESS_DEADMAN_IDX] < 0.0);
00081 }
00082 
00083 bool XboxWirelessConverter::GetBoost(const sensor_msgs::Joy& rJoyMessage)
00084 {
00085   IsValid(rJoyMessage);
00086   
00087   return (rJoyMessage.axes[WIRELESS_BOOST_IDX] > 0.8);
00088 }
00089 
00090 int XboxWirelessConverter::GetAudioCommand(const sensor_msgs::Joy& rJoyMessage)
00091 {
00092   IsValid(rJoyMessage);
00093 
00094   if (rJoyMessage.buttons[WIRELESS_AUDIO_SWEEP_IDX])
00095   {
00096     return rmp_msgs::AudioCommand::TEST_SWEEP;
00097   }
00098 
00099   return -1;
00100 }
00101 
00102 void  XboxWirelessConverter::IsValid(const sensor_msgs::Joy& rJoyMessage)
00103 {
00104   if ( (rJoyMessage.axes.size() != WIRELESS_AXES_SIZE) ||
00105        (rJoyMessage.buttons.size() != WIRELESS_BUTTONS_SIZE) )
00106   {
00107     std::stringstream stringStream;
00108     stringStream << "Invalid joystick message. Expecting " << WIRELESS_AXES_SIZE << " axes and "
00109                  << WIRELESS_BUTTONS_SIZE << " buttons but got a meesage with " << rJoyMessage.axes.size()
00110                  << " axes and " << rJoyMessage.buttons.size() << " buttons.";
00111 
00112     throw std::logic_error(stringStream.str());
00113   }
00114 }


rmp_teleop
Author(s):
autogenerated on Wed Aug 26 2015 16:24:37