55 #include <sensor_msgs/Joy.h> 56 #include <geometry_msgs/Twist.h> 85 deadman_no_publish_(deadman_no_publish),
91 cmd.linear.x = cmd.linear.y = cmd.angular.z = 0;
92 n_.
param(
"max_vx", max_vx, max_vx);
93 n_.
param(
"max_vy", max_vy, max_vy);
94 n_.
param(
"max_vw", max_vw, max_vw);
97 n_.
param(
"max_vx_run", max_vx_run, max_vx_run);
98 n_.
param(
"max_vy_run", max_vy_run, max_vy_run);
99 n_.
param(
"max_vw_run", max_vw_run, max_vw_run);
101 n_.
param(
"axis_vx", axis_vx, 3);
102 n_.
param(
"axis_vw", axis_vw, 0);
103 n_.
param(
"axis_vy", axis_vy, 2);
105 n_.
param(
"deadman_button", deadman_button, 0);
106 n_.
param(
"run_button", run_button, 0);
108 double joy_msg_timeout;
109 n_.
param(
"joy_msg_timeout", joy_msg_timeout, -1.0);
110 if (joy_msg_timeout <= 0)
113 ROS_DEBUG(
"joy_msg_timeout <= 0 -> no timeout");
117 joy_msg_timeout_.
fromSec(joy_msg_timeout);
122 ROS_DEBUG(
"max_vy: %.3f m/s\n", max_vy);
123 ROS_DEBUG(
"max_vw: %.3f deg/s\n", max_vw*180.0/M_PI);
125 ROS_DEBUG(
"max_vx_run: %.3f m/s\n", max_vx_run);
126 ROS_DEBUG(
"max_vy_run: %.3f m/s\n", max_vy_run);
127 ROS_DEBUG(
"max_vw_run: %.3f deg/s\n", max_vw_run*180.0/M_PI);
129 ROS_DEBUG(
"axis_vx: %d\n", axis_vx);
130 ROS_DEBUG(
"axis_vy: %d\n", axis_vy);
131 ROS_DEBUG(
"axis_vw: %d\n", axis_vw);
134 ROS_INFO(
"deadman_button: %d", deadman_button);
135 ROS_INFO(
"run_button: %d", run_button);
136 ROS_DEBUG(
"joy_msg_timeout: %f\n", joy_msg_timeout);
138 vel_pub_ = n_.
advertise<geometry_msgs::Twist>(
"cmd_vel", 1);
149 ROS_DEBUG(
"passthrough_cmd: [%f,%f]", passthrough_cmd.linear.x, passthrough_cmd.angular.z );
150 passthrough_cmd = *pass_msg;
153 void joy_cb(
const sensor_msgs::Joy::ConstPtr& joy_msg)
156 deadman_ = (((
unsigned int)deadman_button < joy_msg->buttons.size()) && joy_msg->buttons[deadman_button]);
165 running_ = (((
unsigned int)run_button < joy_msg->buttons.size()) && joy_msg->buttons[run_button]);
166 double vx = running_ ? max_vx_run :
max_vx;
167 double vy = running_ ? max_vy_run :
max_vy;
168 double vw = running_ ? max_vw_run :
max_vw;
170 if((axis_vx >= 0) && (((
unsigned int)axis_vx) < joy_msg->axes.size()))
171 req_vx = joy_msg->axes[
axis_vx] * vx;
174 if((axis_vy >= 0) && (((
unsigned int)axis_vy) < joy_msg->axes.size()))
175 req_vy = joy_msg->axes[
axis_vy] * vy;
178 if((axis_vw >= 0) && (((
unsigned int)axis_vw) < joy_msg->axes.size()))
179 req_vw = joy_msg->axes[
axis_vw] * vw;
187 if (deadman_ && last_recieved_joy_message_time_ + joy_msg_timeout_ >
ros::Time::now() && running_) {
193 fprintf(stdout,
"teleop_base:: %f, %f, %f\n",cmd.linear.x,cmd.linear.y,cmd.angular.z);
196 if (!deadman_no_publish_)
202 int main(
int argc,
char ** argv)
207 bool no_publish =
false;
208 for(
unsigned int x = 1;
x < argc; ++
x)
210 if(!strncmp(argv[
x],
"--deadman_no_publish", strlen(
"--deadman_no_publish")))
void joy_cb(const sensor_msgs::Joy::ConstPtr &joy_msg)
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ros::Time last_recieved_joy_message_time_
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ros::Subscriber passthrough_sub_
int main(int argc, char **argv)
ros::Duration joy_msg_timeout_
geometry_msgs::Twist passthrough_cmd
Duration & fromSec(double t)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
TFSIMD_FORCE_INLINE const tfScalar & x() const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void passthrough_cb(const geometry_msgs::TwistConstPtr &pass_msg)
ROSCPP_DECL void spinOnce()
TeleopBase(bool deadman_no_publish=false)