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

My first guess would be that since spinOnce is in the else statement, and the else statement is never getting called, you're node is just starting, checking the state of global_state once, then closing. There should be an outer while loop that contains you're if and else statements, then spinOnce.

I would try printing the value of global_state before the if statement, if it is always false I would make sure the callback is getting called:

void call_back( const std_msgs::Empty & msg)
{
 cout << "setting global_state = true" << endl;  
 global_state = true;
}

If that never prints, I would check that tipper_control is actually being published from the terminal:

rostopic echo tipper_control

My first guess would be that since spinOnce is in the else statement, and the else statement is never getting called, you're node is just starting, checking the state of global_state once, then closing. closing (i.e. the callback never has a chance to get called). There should be an outer while loop that contains you're your if and else statements, then spinOnce. spinOnce.

I would try printing the value of global_state before the if statement, if it is always false I would make sure the callback is getting called:

void call_back( const std_msgs::Empty & msg)
{
 cout << "setting global_state = true" << endl;  
 global_state = true;
}

If that never prints, I would check that tipper_control is actually being published from the terminal:

rostopic echo tipper_control

My first guess would be that since spinOnce is in the else statement, and the else statement is never getting called, you're node is just starting, checking the state of global_state once, then closing (i.e. the callback never has a chance to get called). There should be an outer while loop that contains your if and else statements, then spinOnce.

One more note, global variables can usually be avoided by writing your code as a class, then global_state can be a member variable, the callback can be a member function, and the while loop containing spinOnce can be in the class's constructor. A few tips on that can be found here.

My first guess would be that since spinOnce is in the else statement, and the else statement is never getting called, you're your node is just starting, checking the state of global_state once, then closing (i.e. the callback never has a chance to get called). There should be an outer while loop that contains your if and else statements, then spinOnce.

One more note, global variables can usually be avoided by writing your code as a class, then global_state can be a member variable, the callback can be a member function, and the while loop containing spinOnce can be in the class's constructor. A few tips on that can be found here.