2 #include <ros/subscriber.h>
3 #include <ros/publisher.h>
4 #include <igvc_msgs/velocity_pair.h>
5 #include <sensor_msgs/Joy.h>
15 double absoluteMaxVel, maxVel, maxVelIncr;
16 nhp->param(
string(
"absoluteMaxVel"), absoluteMaxVel, 1.0);
17 nhp->param(
string(
"maxVel"), maxVel, 1.0);
18 nhp->param(
string(
"maxVelIncr"), maxVelIncr, 0.1);
22 else if(msg->buttons[3])
24 maxVel = min(maxVel, absoluteMaxVel);
25 maxVel = max(maxVel, 0.0);
27 nhp->setParam(
"maxVel", maxVel);
29 int leftJoyAxis, rightJoyAxis;
30 bool leftInverted, rightInverted;
31 nhp->param(
string(
"leftAxis"), leftJoyAxis, 1);
32 nhp->param(
string(
"rightAxis"), rightJoyAxis, 3);
33 nhp->param(
string(
"leftInverted"), leftInverted,
false);
34 nhp->param(
string(
"rightInverted"), rightInverted,
false);
36 igvc_msgs::velocity_pair cmd;
37 cmd.left_velocity = msg->axes[leftJoyAxis]*maxVel * (leftInverted ? -1.0 : 1.0);
38 cmd.right_velocity = msg->axes[rightJoyAxis]*maxVel * (rightInverted ? -1.0 : 1.0);
43 int main(
int argc,
char** argv)
45 ros::init(argc, argv,
"joystick_driver");
47 nhp =
new ros::NodeHandle(
"~");
49 cmd_pub = nh.advertise<igvc_msgs::velocity_pair>(
"/motors", 1);
51 ros::Subscriber joy_sub = nh.subscribe(
"/joy", 1,
joyCallback);
void joyCallback(const sensor_msgs::Joy::ConstPtr &msg)
int main(int argc, char **argv)