JoystickDemo.h
Go to the documentation of this file.
00001 /*********************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2018-2019, Dataspeed Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of Dataspeed Inc. nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *********************************************************************/
00034 
00035 #ifndef JOYSTICKDEMO_H_
00036 #define JOYSTICKDEMO_H_
00037 
00038 #include <ros/ros.h>
00039 #include <sensor_msgs/Joy.h>
00040 #include <std_msgs/Empty.h>
00041 
00042 #include <dbw_fca_msgs/ThrottleCmd.h>
00043 #include <dbw_fca_msgs/BrakeCmd.h>
00044 #include <dbw_fca_msgs/SteeringCmd.h>
00045 #include <dbw_fca_msgs/GearCmd.h>
00046 #include <dbw_fca_msgs/TurnSignalCmd.h>
00047 
00048 typedef struct {
00049   ros::Time stamp;
00050   float brake_joy;
00051   float throttle_joy;
00052   float steering_joy;
00053   bool steering_mult;
00054   int gear_cmd;
00055   int turn_signal_cmd;
00056   bool joy_throttle_valid;
00057   bool joy_brake_valid;
00058 } JoystickDataStruct;
00059 
00060 class JoystickDemo {
00061 public:
00062   JoystickDemo(ros::NodeHandle &node, ros::NodeHandle &priv_nh);
00063 private:
00064   void recvJoy(const sensor_msgs::Joy::ConstPtr& msg);
00065   void cmdCallback(const ros::TimerEvent& event);
00066 
00067   // Topics
00068   ros::Subscriber sub_joy_;
00069   ros::Publisher pub_brake_;
00070   ros::Publisher pub_throttle_;
00071   ros::Publisher pub_steering_;
00072   ros::Publisher pub_gear_;
00073   ros::Publisher pub_turn_signal_;
00074   ros::Publisher pub_enable_;
00075   ros::Publisher pub_disable_;
00076 
00077   // Parameters
00078   bool brake_; // Send brake commands
00079   bool throttle_; // Send throttle commands
00080   bool steer_; // Send steering commands
00081   bool shift_; // Send shift commands
00082   bool signal_; // Send turn signal commands
00083 
00084   // Parameters
00085   float brake_gain_; // Adjust brake value
00086   float throttle_gain_; // Adjust throttle value
00087 
00088   // Parameters
00089   bool ignore_; // Ignore driver overrides
00090   bool enable_; // Use enable and disable buttons
00091   bool count_; // Increment counter to enable watchdog
00092   bool strq_; // Steering torque command (otherwise angle)
00093   float svel_; // Steering command speed
00094 
00095   // Variables
00096   ros::Timer timer_;
00097   JoystickDataStruct data_;
00098   sensor_msgs::Joy joy_;
00099   uint8_t counter_;
00100   float last_steering_filt_output_;
00101 
00102   enum {
00103     BTN_PARK = 3,
00104     BTN_REVERSE = 1,
00105     BTN_NEUTRAL = 2,
00106     BTN_DRIVE = 0,
00107     BTN_ENABLE = 5,
00108     BTN_DISABLE = 4,
00109     BTN_STEER_MULT_1 = 6,
00110     BTN_STEER_MULT_2 = 7,
00111     BTN_COUNT_X = 11,
00112     BTN_COUNT_D = 12,
00113     AXIS_THROTTLE = 5,
00114     AXIS_BRAKE = 2,
00115     AXIS_STEER_1 = 0,
00116     AXIS_STEER_2 = 3,
00117     AXIS_TURN_SIG = 6,
00118     AXIS_COUNT_D = 6,
00119     AXIS_COUNT_X = 8,
00120   };
00121 };
00122 
00123 #endif /* JOYSTICKDEMO_H_ */
00124 


dbw_fca_joystick_demo
Author(s): Micho Radovnikovich
autogenerated on Sat May 4 2019 02:40:34