Hi all,
I've some codes below to connect to gazebo (turtlebot);
>> rosinit('http://192.168.2.87:11311')Initializing global node /matlab_global_node_77319 with NodeURI http://192.168.2.126:62581/>> rosnode list/gazebo/laserscan_nodelet_manager/matlab_global_node_77319/mobile_base_nodelet_manager/robot_state_publisher/rosout>> rostopic list/camera/depth/camera_info /camera/depth/image_raw /camera/depth/points /camera/parameter_descriptions /camera/parameter_updates /camera/rgb/camera_info /camera/rgb/image_raw /camera/rgb/image_raw/compressed /camera/rgb/image_raw/compressed/parameter_descriptions/camera/rgb/image_raw/compressed/parameter_updates /clock /gazebo/link_states /gazebo/model_states /gazebo/parameter_descriptions /gazebo/parameter_updates /gazebo/set_link_state /gazebo/set_model_state /joint_states /mobile_base/commands/motor_power /mobile_base/commands/reset_odometry /mobile_base/commands/velocity /mobile_base/events/bumper /mobile_base/events/cliff /mobile_base/sensors/imu_data /odom /rosout /rosout_agg /tf >> rosnode info /matlab_global_node_77319Node: [/matlab_global_node_77319]URI: [http://192.168.2.126:62581/]Publications (1 Active Topics): * /rosoutSubscriptions (1 Active Topics): * /clock
When I tried to create a publisher for a topic as below (using ‘rospublisher’), it works:
>> robot = rospublisher('/mobile_base/commands/velocity') robot = Publisher with properties: TopicName: '/mobile_base/commands/velocity' IsLatching: 1 NumSubscribers: 0 MessageType: 'geometry_msgs/Twist'
As shown below, the topic is added to the publishers list:
>> rosnode info /matlab_global_node_77319Node: [/matlab_global_node_77319]URI: [http://192.168.2.126:62581/]Publications (3 Active Topics): * /mobile_base/commands/velocity* /odom* /rosoutSubscriptions (1 Active Topics): * /clockServices (0 Active):
Now, I add a new node:
>> node_1 = robotics.ros.Node('node_1', 'http://192.168.2.87:11311');>> rosnode info node_1Node: [/node_1]URI: [http://192.168.2.126:62966/]Publications (1 Active Topics): * /rosoutSubscriptions (1 Active Topics): * /clockServices (0 Active):
And add the same topic to publish but using another code (robotics.ros.publisher). It works too, as shown below:
>> robotics.ros.Publisher(node_1,'/mobile_base/commands/velocity'); >> rosnode info node_1 Node: [/node_1] URI: [http://192.168.2.126:62966/] Publications (2 Active Topics): * /mobile_base/commands/velocity * /rosout Subscriptions (1 Active Topics): * /clock Services (0 Active):
However, now when I tried to use (robotics.ros.publisher) on the first node (/matlab_global_node_77319), it doesn’t work:
>> tPub = robotics.ros.Publisher(matlab_global_node_77319,'/mobile_base/commands/motor_power');Undefined function or variable'matlab_global_node_77319'.>> tPub = robotics.ros.Publisher(matlab_global_node_77319,'/mobile_base/commands/motor_power','kobuki_msgs/MotorPower');Undefined function or variable'matlab_global_node_77319'.>> tPub = robotics.ros.Publisher(/matlab_global_node_77319,'/mobile_base/commands/motor_power','kobuki_msgs/MotorPower');tPub = robotics.ros.Publisher(/matlab_global_node_77319,'/mobile_base/commands/motor_power','kobuki_msgs/MotorPower'); |Error: Unexpected MATLAB operator.
However, if I used the same code on the new node, and publish a new topic, it works:
>> robotics.ros.Publisher(node_1,'/mobile_base/commands/motor_power')ans = Publisher with properties: TopicName: '/mobile_base/commands/motor...' IsLatching: 1 NumSubscribers: 1 MessageType: 'kobuki_msgs/MotorPower'>> rosnode info /node_1Node: [/node_1]URI: [http://192.168.2.126:62966/]Publications (2 Active Topics): * /mobile_base/commands/motor_power* /rosoutSubscriptions (1 Active Topics): * /clockServices (0 Active):
How do I publish a topic for a node that already exist?
Best Answer