ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Since there is not a ros::shutdown something like this might be an alternative.
#include <ArduinoHardware.h>
#include <ros.h>
#include <geometry_msgs/Twist.h>
#include <sensor_msgs/Joy.h>
ros::NodeHandle nh;
geometry_msgs::Twist msg;
//Use a variable to store the speed
float speed = 0.1;
void joyCall(const sensor_msgs::Joy& joy){
if (joy.buttons[14]==1)
speed = 0.0;
}
ros::Subscriber<sensor_msgs::Joy> sub("bluetooth_teleop/joy", &joyCall);
ros::Publisher pub("/cmd_vel", &msg);
void setup()
{
nh.initNode();
nh.advertise(pub);
nh.subscribe(sub);
}
void loop(){
msg.linear.x=speed;
pub.publish(&msg);
nh.spinOnce();
}
or if you want the publisher to quit, this could be an option.
#include <ArduinoHardware.h>
#include <ros.h>
#include <geometry_msgs/Twist.h>
#include <sensor_msgs/Joy.h>
ros::NodeHandle nh;
geometry_msgs::Twist msg;
ros::Subscriber<sensor_msgs::Joy> sub("bluetooth_teleop/joy", &joyCall);
ros::Publisher pub("/cmd_vel", &msg);
bool flag;
void joyCall(const sensor_msgs::Joy& joy){
if (joy.buttons[14]==1)
{ //Set to zero and set flag so it quits publishing
msg.linear.x = 0.0;
pub.publish(&msg);
flag = false;
}
}
void setup()
{
flag = true;
nh.initNode();
nh.advertise(pub);
nh.subscribe(sub);
}
void loop()
{
if(flag)
{
msg.linear.x=0.1;
pub.publish(&msg);
}
nh.spinOnce();
}