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

Revision history [back]

Can you explain a bit more what you're expecting your code to do.

You seem to have several potential infinite loops in this code and nothing that is attempting to update the values of the data.buttons array.

At a glance this is what I think you're code will be doing.

If button 4 is pressed and button 5 isn't then it will loop forever sending a motor_message with a value of 70 Also within this loop it will check if button 6 is pressed and button 7 isn't if this is the case it will then loop forever sending motor_messages with values of 70 forever and never return to the outer loop.

Unless you're running multi-threaded code and 'data' is a shared variable then it's value isn't going to change while these loops are being executed. Do you have a callback function for joy messages somewhere in your code which handles incoming joystick messages?

Can you explain a bit more what you're expecting your code to do.

You seem to have several potential infinite loops in this code and nothing that is attempting to update the values of the data.buttons array.

At a glance this is what I think you're code will be doing.

If button 4 is pressed and button 5 isn't then it will loop forever sending a motor_message with a value of 70 Also within this loop it will check if button 6 is pressed and button 7 isn't if this is the case it will then loop forever sending motor_messages with values of 70 forever and never return to the outer loop.

Unless you're running multi-threaded code and 'data' is a shared variable then it's value isn't going to change while these loops are being executed. Do you have a callback function for joy messages somewhere in your code which handles incoming joystick messages?

Update: Okay, I understand what you're trying to achieve now. This really depends on the behaviour of your motor controller, when you send it a velocity message does it continue to drive with that velocity until it receives a different velocity message? That would seem likely to me, but you'll need to check to make sure.

In this case it's actually fairly simple, the ROS joystick node publishes new messages every time it's state changes so all you need to do is find out if the motor needs starting or stopping based on the buttons pressed at this point in time and send the appropriate message. You only need to do this once in your callback function because future callbacks will be called automatically when the joystick buttons change state.

The pseudo code for your callback will look something like this:

if button 4 is pressed and button 5 isn't pressed then
      send a motor message with a value of 70
if button 5 is pressed then
      send a motor message with a value of 60

Hope this helps.