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

With a rosserial client, a ros std_msgs/String data field is converted to a simple c char array. So my guess is that for you to use ==, the correct syntax is:

toggle_msg.data[0] == 'M'

The single quotes are important - you are comparing a char, not a string. Also, to avoid a crash, you need to check the string length to make sure it is not 0.

With a rosserial client, a ros std_msgs/String data field is converted to a simple c char array. So my guess is that for you to use ==, the correct syntax is:

toggle_msg.data[0] == 'M'

'M'

The single quotes are important - you are comparing a char, not a string. Also, to avoid a crash, you need to check the string length to make sure it is not 0.