I have a robot with a gazebo_ros_control plugin. So there is a robot/joint_drive_wheel/command
topic to which you publish commands for velocity.
I have also written an rqt plugin that publishes to the topic and ros node that publishes to the topic.
When I use terminal command rostopic pub robot/joint_right_wheel_controller/command std_msgs/Float64 "data: 5.0"
, the robot reacts.
When I use the rqt plugin, the robot reacts.
When I use the ros node, however, the robot reacts only to commands published in a callback function of a subscriber to different topic. When I want to command the velocity in after creating the publisher, the command does get to the topic (I watch with rostopic echo
), but the robot doesn't react to the command.
This is my node:
import rospy
import rospkg
from std_msgs.msg import Bool
from std_msgs.msg import Float64
import time
def callback(data):
_robot_stop()
_robot_backup()
_robot_turn90right()
_robot_forward()
def _robot_stop():
publisher_dict['right'].publish(0.0)
publisher_dict['left'].publish(0.0)
def _robot_backup():
publisher_dict['right'].publish(-5.0)
publisher_dict['left'].publish(-5.0)
time.sleep(1)
_robot_stop()
def _robot_turn90right():
publisher_dict['right'].publish(-5.0)
publisher_dict['left'].publish(5.0)
time.sleep(1)
_robot_stop()
def _robot_turn90left():
publisher_dict['right'].publish(5.0)
publisher_dict['left'].publish(-5.0)
time.sleep(1)
_robot_stop()
def _robot_forward():
publisher_dict['right'].publish(5.0)
publisher_dict['left'].publish(5.0)
def mynode():
rospy.init_node('mynode')
publisher_dict['right'] = rospy.Publisher('/robot/joint_right_wheel_controller/command', Float64, queue_size=1)
publisher_dict['left'] = rospy.Publisher('/robot/joint_left_wheel_controller/command', Float64, queue_size=1)
rospy.Subscriber("/robot/another_topic", Bool, callback)
_robot_forward()
rospy.spin()
publisher_dict = { }
if __name__ == '__main__':
try:
mynode()
except rospy.ROSInterruptException:
pass
Once I run the node (when the simulation is running), I would expect the robot to move forward, because of the command _robot_forward()
right before the rospy.spin()
. And the command does appears at the topic when I listen to it via terminal. But the robot does not move. I'm confused. Why might that be?
Originally posted by kump on ROS Answers with karma: 308 on 2018-10-22
Post score: 0