ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

using ros::shutdown() in arduino code

asked 2015-06-25 13:00:10 -0500

Adi gravatar image

Hey there guys,

I am trying to write an arduino based code for my robot, that would allow me to use a button on the PS3 joystick as an emergency kill-switch. I thought using ros::shutdown() would work, but apparently the arduino ros library doesn't recognize it as a function. Here is the code.

#include <ArduinoHardware.h>
#include <ros.h>
#include <geometry_msgs/Twist.h>
#include <sensor_msgs/Joy.h>

ros::NodeHandle nh;

geometry_msgs::Twist msg;

void joyCall(const sensor_msgs::Joy& joy){
if (joy.buttons[14]==1)
  ros::shutdown();
}

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=0.1;
  pub.publish(&msg);
  nh.spinOnce();
}

Basically, I am publishing a constant velocity to the velocity node, but i want to kill the publisher as soon as a button on the joystick is pressed. However, I get this compiler error:

sketch_jun24a.ino: In function ‘void joyCall(const sensor_msgs::Joy&)’:
sketch_jun24a.ino:13:3: error: ‘shutdown’ is not a member of ‘ros’

Any help would be extremely useful. Thanks!

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

answered 2015-07-10 12:10:44 -0500

Adi gravatar image

Apparently ros::shutdown() is not a function in the arduino library, so that's that! In case anyone else evr has the same problem, remember this message!

edit flag offensive delete link more
1

answered 2015-07-11 14:52:02 -0500

jseal gravatar image

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();
}
edit flag offensive delete link more

Comments

This is an interesting solution. I decided to write a universal killswitch package. What commands could I use to do a system wide shutdown, or simply shutdown all ros activity from within a c++ code?

Adi gravatar image Adi  ( 2015-07-13 15:12:40 -0500 )edit

Create a node that shutdown and then in your launch file add required="true" to that node. Once the node shutdown the rest of the nodes will too.

jseal gravatar image jseal  ( 2015-07-13 16:54:45 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2015-06-25 13:00:10 -0500

Seen: 1,388 times

Last updated: Jul 11 '15