35 #include <sensor_msgs/Joy.h> 36 #include <geometry_msgs/Twist.h> 37 #include <std_msgs/Int32.h> 40 #include <robotnik_msgs/enable_disable.h> 41 #include <robotnik_msgs/set_digital_output.h> 42 #include "diagnostic_msgs/DiagnosticStatus.h" 47 #include "ackermann_msgs/AckermannDriveStamped.h" 48 #include <std_srvs/Empty.h> 49 #include "robotnik_msgs/set_mode.h" 50 #include "robotnik_msgs/get_mode.h" 52 #define DEFAULT_MAX_LINEAR_SPEED 3.0 // m/s 53 #define DEFAULT_MAX_ANGULAR_POSITION 0.5 // rads/s 55 #define MAX_NUM_OF_BUTTONS 16 56 #define MAX_NUM_OF_AXES 8 57 #define MAX_NUM_OF_BUTTONS_PS3 19 58 #define MAX_NUM_OF_AXES_PS3 20 60 #define DEFAULT_NUM_OF_BUTTONS 16 61 #define DEFAULT_NUM_OF_AXES 8 63 #define DEFAULT_AXIS_LINEAR_X 1 64 #define DEFAULT_AXIS_ANGULAR 2 65 #define DEFAULT_SCALE_LINEAR 1.0 66 #define DEFAULT_SCALE_ANGULAR 1.0 68 #define DEFAULT_JOY "/joy" 69 #define DEFAULT_HZ 50.0 86 if (iPressed and !value)
90 else if (bReleased and value)
115 int SetStateMode(
int state,
int arm_mode,
int platform_mode);
118 void joyCallback(
const sensor_msgs::Joy::ConstPtr& joy);
120 char* StateToString(
int state);
121 int SwitchToState(
int new_state);
125 bool EnableDisable(robotnik_msgs::enable_disable::Request& req, robotnik_msgs::enable_disable::Response& res);
261 fAxes.push_back(0.0);
328 ROS_INFO(
"RbcarPad::EnablaDisable: Setting to %d", req.value);
336 for (
int i = 0; i < joy->axes.size(); i++)
338 this->
fAxes[i] = joy->axes[i];
340 for (
int i = 0; i < joy->buttons.size(); i++)
342 this->
vButtons[i].Press(joy->buttons[i]);
352 double desired_linear_speed = 0.0, desired_angular_position = 0.0;
353 ackermann_msgs::AckermannDriveStamped ref_msg;
354 geometry_msgs::Twist vel_msg;
356 vel_msg.angular.x = 0.0;
357 vel_msg.angular.y = 0.0;
358 vel_msg.angular.z = 0.0;
359 vel_msg.linear.x = 0.0;
360 vel_msg.linear.y = 0.0;
361 vel_msg.linear.z = 0.0;
374 ref_msg.drive.jerk = 0.0;
375 ref_msg.drive.acceleration = 0.0;
376 ref_msg.drive.steering_angle_velocity = 0.0;
386 vel_msg.linear.x = desired_linear_speed;
387 vel_msg.angular.z = desired_angular_position;
408 ref_msg.drive.jerk = 0.0;
409 ref_msg.drive.acceleration = 0.0;
410 ref_msg.drive.steering_angle_velocity = 0.0;
412 ref_msg.drive.steering_angle = 0.0;
413 ref_msg.drive.speed = 0.0;
414 vel_msg.linear.x = 0.0;
415 vel_msg.angular.z = 0.0;
427 int main(
int argc,
char** argv)
#define DEFAULT_NUM_OF_AXES
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
diagnostic_updater::HeaderlessTopicDiagnostic * sus_joy_freq
Diagnostic to control the reception frequency of the subscribed joy topic.
#define DEFAULT_MAX_ANGULAR_POSITION
std::string cmd_topic_vel
Name of the topic where it will be publishing the velocity.
void publish(const boost::shared_ptr< M > &message) const
std::string joy_topic_
// Name of the joystick's topic
int ptz_tilt_up_
buttons to the pan-tilt camera
void ControlLoop()
Controls the actions and states.
int kinematic_mode_
kinematic mode
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
std::string topic_state_
topic name for the state
ros::Publisher state_pub_
Topic to publish the state.
void setHardwareID(const std::string &hwid)
ros::ServiceClient setKinematicMode
Service to modify the kinematic mode.
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ros::Subscriber joy_sub_
they will be suscribed to the joysticks
std::vector< Button > vButtons
Vector to save and control the axis values.
#define DEFAULT_NUM_OF_BUTTONS
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
std::string cmd_set_mode_
Name of the service to change the mode.
diagnostic_updater::Updater updater_pad
General status diagnostic updater.
bool bEnable
Flag to enable/disable the communication with the publishers topics.
double max_linear_speed_
Set the max speed sent to the robot.
int num_of_buttons_
Current number of buttons of the joystick.
int button_speed_up_
Number of the button for increase or decrease the speed max of the joystick.
ros::Publisher vel_pub_
It will publish into command velocity (for the robot)
double max_angular_position_
double max_freq_command
Diagnostics max freq.
int axis_angular_position_
double min_freq_command
Diagnostics min freq.
int button_dead_man_
Number of the DEADMAN button.
int button_kinematic_mode_
button to change kinematic mode
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
#define MAX_NUM_OF_AXES_PS3
#define DEFAULT_MAX_LINEAR_SPEED
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
int main(int argc, char **argv)
std::string cmd_service_io_
Name of the service where it will be modifying the digital outputs.
ros::ServiceClient set_digital_outputs_client_
#define MAX_NUM_OF_BUTTONS
std::string cmd_service_ptz_
Name of the service to move ptz.
#define DEFAULT_AXIS_ANGULAR
double desired_freq_
Desired component's freq.
#define DEFAULT_AXIS_LINEAR_X
#define MAX_NUM_OF_BUTTONS_PS3
ros::ServiceServer enable_disable_srv_
Service clients.
ROSCPP_DECL void spinOnce()
bool EnableDisable(robotnik_msgs::enable_disable::Request &req, robotnik_msgs::enable_disable::Response &res)
Enables/Disables the joystick.
void joyCallback(const sensor_msgs::Joy::ConstPtr &joy)
std::vector< float > fAxes
Vector to save the axis values.
diagnostic_updater::HeaderlessTopicDiagnostic * pub_command_freq
Diagnostic to control the frequency of the published command velocity topic.