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

Revision history [back]

click to hide/show revision 1
initial version

You can do it like that :

//You libraries here
#include <boost/bind.hpp>
#include <tile_planner/reach_goals.h>

//Create a thread only for ros spin
void spinthread()
{
    ros::spin();
}

//Deifne a global variable
std_msgs::Bool override_status;

//Construcor
Override::Override()
{
//Define sub and publishers and start the thread
  boost::thread t = boost::thread(boost::bind(&spinthread));
}

//Callback
void Override::joyCallback(const sensor_msgs::Joy::ConstPtr& joy)
{ 
//Your callback routine here where you set override_status 
}

int main(int argc, char** argv)
{
  ros::init(argc, argv, "override_node");
  Override override;
  while(ros::ok())
  {
    override_pub.publish(override_status);
  }
}

You will be continously publishing the value of override_status which will be changed each time the callback is called. You can also add a timer and change the publishing rate as you want using ros.sleep()

You can do it like that :

//You libraries here
#include <boost/bind.hpp>
#include <tile_planner/reach_goals.h>

//Create a thread only for ros spin
void spinthread()
{
    ros::spin();
}

//Deifne a global variable
std_msgs::Bool override_status;

//Construcor
Override::Override()
{
//Define sub and publishers and start the thread
  boost::thread t = boost::thread(boost::bind(&spinthread));
}

//Callback
void Override::joyCallback(const sensor_msgs::Joy::ConstPtr& joy)
{ 
//Your callback routine here where you set override_status 
}

int main(int argc, char** argv)
{
  ros::init(argc, argv, "override_node");
  Override override;
  while(ros::ok())
  {
    override_pub.publish(override_status);
  }
}

You will be continously publishing the value of override_status which will be changed each time the callback is called. You can also add a timer and change the publishing rate as you want using ros.sleep()

Creating a thread allows you to collect the data continously in the background so that if you have time consuming functions you don't miss messages that couldn't have been received since the program was still in the function.

You can do it like that :

//You libraries here
#include <boost/bind.hpp>
#include <tile_planner/reach_goals.h>

//Create a thread only for ros spin
void spinthread()
{
    ros::spin();
}

//Deifne a global variable
std_msgs::Bool override_status;

//Construcor
Override::Override()
{
//Define sub and publishers and start the thread
  boost::thread t = boost::thread(boost::bind(&spinthread));
}

//Callback
void Override::joyCallback(const sensor_msgs::Joy::ConstPtr& joy)
{ 
//Your callback routine here where you set override_status 
}

int main(int argc, char** argv)
{
  ros::init(argc, argv, "override_node");
  Override override;
  //Set rate at 10Hz 
  ros::Rate r(10);
  while(ros::ok())
  {
    override_pub.publish(override_status);
    r.sleep();
  }
}

You will be continously publishing the value of override_status which will be changed each time the callback is called. You can also add a timer and change the publishing rate as you want using ros.sleep()

Creating a thread allows you to collect the data continously in the background so that if you have time consuming functions you don't miss messages that couldn't have been received since the program was still in the function.