[ROS Q&A] 128 – Can’t access messages of the ROS topic Publisher

[ROS Q&A] 128 – Can’t access messages of the ROS topic Publisher

In this video we are going to see why a user can’t access the message that he is publishing into a topic using a ROS Publisher.

This is a video trying to answer the following question posted at the ROS answers forum: https://answers.ros.org/question/293898/init_node-need-locating-after-publisher/

Step 1. Create a project in ROS Development Studio(ROSDS)

We can do any ROS development we want easily, without setting up environment locally in ROSDS and that’s the reason why we will use ROSDS for this tutorial. If you haven’t had an account yet. You can create one here for free now. After logging in, let’s begin our journey by clicking on the create new project and call it pub_example.

Step 2. Create a new package for testing

Now, let’s create a new package for testing with the following command

cd ~/catkin_ws/src/
catkin_create_pkg pub_example rospy

Then we create a new file called pub_ex.py under /pub_example/src with copying and pasting the following code.

#!/usr/bin/env python
# license removed for brevity
import rospy
from std_msgs.msg import String

def talker():
    rospy.init_node('talker')
    pub = rospy.Publisher('chatter', String, queue_size=10)    
    hello_str = "hello world %s" % rospy.get_time()
    pub.publish(hello_str)
    rospy.loginfo(hello_str)

if __name__ == '__main__':
    talker()

NOTICE: We no longer run ROS master for you in the backend, please launch it with the command roscore in a new terminal.

Now you can run it with the command rosrun pub_example pub_ex.py

You will get the output hello world, however, if you check with rostopic list , there is no chatter topic.

It turns out the talker function only publish once and was killed. If we want to access it, we have to keep publishing it. Let’s change our code.

def talker():
    rospy.init_node('talker')
    rate = rospy.Rate(1) # this defines the publish rate
    pub = rospy.Publisher('chatter', String, queue_size=10)    
    hello_str = "hello world %s" % rospy.get_time()
    while not rospy.is_shutdown(): 
        # put everything in a while loop to keep publishiing topic
        pub.publish(hello_str)
        rospy.loginfo(hello_str)
        rate.sleep() # this make sure that the topic is publishing at 1 Hz

When you run it again, you can see that the topic is publishing every 1 second and you can access it from other node.

 

 

Edit by: Tony Huang

 

RELATED LINKS & RESOURCES

▸ Original question: https://answers.ros.org/question/293898/init_node-need-locating-after-publisher/
Robot Ignite Academy
ROS Basics in 5 days Course (Python)
ROS Development Studio (RDS)

 


If you want to learn about other ROS topics, please let us know on the comments area and we will do a video about it.

[ROS IN 5 MIN] 011 – What is catkin_make & how do you use it?

[ROS IN 5 MIN] 011 – What is catkin_make & how do you use it?

Hello ROS Developers! In this ROS in 5 min tutorial, we’re going to see what catkin_make is, how it works, and what its advantages are.

For that, we are going to use Robot Ignite Academy.

But before we start, if you are new to ROS and want to Learn ROS fast, I recommend that you take any of the following courses in Robot Ignite Academy:

Whether you like the video or not, or if you want to learn about specific ROS subjects, please leave a comment in the comments section below, so we can interact and learn from each other.

ROS Basics python Course Cover - ROS Online Courses - Robot Ignite Academy

ROS Basics for Beginners (Python)

ROS Basics C++ Course Cover - ROS Online Courses - Robot Ignite Academy

ROS Basics for Beginners (C++)

Question: What is catkin_make

Step1. Create a project in Robot Ignite Academy(RIA)

We have the best online ROS course available in RIA. It helps you learn ROS in the easiest way without setting up ROS environment locally. The only thing you need is a browser! Create an account here and start to browse the trial course for free now!

Step2. Create a package

Almost all the package you will need is already installed in RIA. We’ll create the package in the ROS Autonomous Vehicles 101 course as an example in this video, but you can choose any course you want to do this.

Please type the following command in shell to create a new package

cd ~/catkin_ws/src
catkin_create_pkg test roscpp

Step3. Compile the package with catkin_make

Now you can type catkin_make to compile the package.

cd ..
catkin_make

It shows a lot of outputs, but what did it really do?

The catkin_make is actually a macro which creates directories and runs cmake command for you. If you want to do it yourself, just delete the build and devel directories first.

rm -rf build/ devel/

Now you can create a build directory and run the cmake command by yourself to get the exact same result as catkin_make did.

mkdir build&&cd build
cmake /home/user/catkin_ws/src -DCATKIN_DEVEL_PREFIX=/home/user/catkin_ws/devel -DCMAKE_INSTALL_PREFIX=/home/user/catkin_ws/install -G "Unix Makefiles"

Take away today- The Answer:

catkin_make is a macro which creates source directories and runs the cmake commands for you. You can test out with the following step.

 

Edit by Tony Huang

ROS Developers LIVE-Class #21: A Basic Example of OpenAI with ROS

ROS Developers LIVE-Class #21: A Basic Example of OpenAI with ROS

 

In this ROS LIVE-Class we’re going to learn how to create our own Qlearning training for a cart pole in Gazebo using both OpenAI and ROS.

We will see:

  •  How to create a Python training program that uses OpenAI infrastructure
  •  How to create the environment that allows to get the observations and take the actions on a Gazebo simulation
  •  How to interface everything with ROS

Every Tuesday at 18:00 CET/CEST.

This is a LIVE Class on how to develop with ROS. In Live Classes you practice with me at the same time that I explain, with the provided free ROS material.

IMPORTANT: Remember to be on time for the class because at the beginning of the class we will share the code with the attendants.

IMPORTANT 2: in order to start practicing quickly, we are using the ROS Development Studio for doing the practice. You will need a free account to attend the class. Go to ROS Development Stdio and create an account prior to the class.

[irp posts=”9720″ name=”ROS Developers LIVE-Class #22: How to create an OpenAI environment for your robotic problem”]

RELATED LINKS & RESOURCES

▸ OpenAI libraries: https://gym.openai.com/
ROS Development Studio
Next ROS Developers Live Classes

***


open-ai-gym-for-robotics-ros-course-banner

[ROS Q&A] 129 – Which ROS controllers required for PR2 ?

 

In this video we are going to see why a ROS developer can’t launch a PR2 Gazebo simulation, mainly because the ROS controllers are not found.

We will see which are the ROS packages which provide all the required controllers for the PR2. We will also see how you can apply this check to your own robot simulation, in case it complains about the controllers not being loaded.

This is a video trying to answer the following question posted at the ROS answers forum: https://answers.ros.org/question/294245/roslaunch-pr2_gazebo-pr2_empty_worldlaunch/

 

The following steps take throught the development as shown in the video

  • Open Robot Development Studio and create a new project (use a suitable name for project).
  • Launch the PR2 simulation by entering the following commands in a SHELL

    $ roslaunch pr2_gazebo pr2_empty_world.launch

It will take a while to load the simulation and we need to open a gazebo window (Tools>Gazebo) to see the visualization.

If the simulation doesn’t launch then we need to check for a few things

  • Controller manager : It is important that controller manager be running, we can check that with the following command

$ rosservice list| grep controller_manager

In the output of the above command, if you see enteries starting with /pr2_controller_manager/ that means everything is OK.

The different types of controllers available can be checked with command

$ rosservice call /pr2_controller_manager/list_controller_types

If you see controller types in the output of the above command then everything is OK.

We can check if these controllers are loaded or not using the following command

$ rosservice call /pr2_controller_manager/list_controllers

The above command should output various controllers and thier status.

Now the above case is for the working environment where all the required packages are installed. If some packages are missing then we should systematically look for packages and dependencies. The packages mostly fall into two categories: gazebo-ros controllers and robot specific controllers (pr2-controllers specifically for our case)

  • ros-control : To list the available ros-control packages use the following command

$ dpkg -l | grep ros-control

There are two important packages in this category ros-kinetic-gazebo-ros-control and ros-kinetic-ros-controllers

  • gazebo-ros : To list the available gazebo-ros related packages use the following command

$ dpkg -l | grep gazebo-ros

The output of the command should contain the following two names ros-kinetic-gezebo-ros and ros-kinetic-gezebo-ros-control (this one was seen in previous commands output also)

  • controller interfaces : To list the installed controller interface packages use the command

$ dpkg -l | grep controller-interface

The output of this command should show the following names ros-kinetic-controller-interface, ros-kinetic-controller-manager, ros-kinetic-controller-manager-msgs

  • controllers : In gazebo we use various controllers to actuate different types of joints. We need to check for the following ones
    • joint state controllers : The output of the following command should contain ros-kinetic-joint-state-controller

      $ dpkg -l | grep joint-state

    • joint trajectory controllers : The output of the following command should contain ros-kinetic-joint-trajectory-controller

      $ dpkg -l | grep joint-trajectory

    • effort controllers : The output of the following command should contain ros-kinetic-effort-controllers

      $ dpkg -l | grep effort-controllers

    • velocity controllers : The output of the following command should contain ros-kinetic-velocity-controllers

      $ dpkg -l | grep velocity-controllers

Finally we need to check for PR2 robot related controllers to be able to launch the simulation. Use the following commands

$ dpkg -l | grep pr2-controller $ dpkg -l | grep pr2-mechanism

We expect to see the following names in the output of those commands

  • ros-kinetic-pr2-controller-manager,
  • ros-kinetic-pr2-controller-interface,
  • ros-kinetic-pr2-controller-configuration-gazebo,
  • ros-kinetic-pr2-controllers-msgs,
  • ros-kinetic-pr2-mechanism-controllers,
  • ros-kinetic-pr2-mechanism-diagnostics,
  • ros-kinetic-pr2-mechanism-models,
  • ros-kinetic-pr2-mechanism-msgs

If we have all of these packages installed in our computer, we will be able to launch the pr2 robot. That’s all for this post. Thanks for watching the video, please leave your comments and subscribe the channel if you want to see more such videos.

RELATED LINKS AND RESOURCES

▸ Original question: https://answers.ros.org/question/294245/roslaunch-pr2_gazebo-pr2_empty_worldlaunch/
ROS Development Studio (RDS)
Robot Ignite Academy
ROS Control 101 online course

LIST OF ROS PACKAGES REQUIRED

1st- Gazebo – ROS controllers
* ros-kinetic-ros-control
* ros-kinetic-ros-controllers

* ros-kinetic-controller-interface
* ros-kinetic-controller-manager
* ros-kinetic-controller-manager-msgs

* ros-kinetic-gazebo-ros
* ros-kinetic-gazebo-ros-control

* ros-kinetic-joint-state-controller
* ros-kinetic-joint-trajectory-controller
* ros-kinetic-effort-controllers
* ros-kinetic-velocity-controllers

2nd- PR2 robot specific controllers

* ros-kinetic-pr2-controller-manager
* ros-kinetic-pr2-controllers
* ros-kinetic-pr2-controller-interface
* ros-kinetic-pr2-controller-configuration-gazebo

* ros-kinetic-pr2-mechanism-controllers
* ros-kinetic-pr2-mechanism
* ros-kinetic-pr2-mechanism-diagnostics
* ros-kinetic-pr2-mechanism-model


Feedback

Did you like this video? Do you have questions about what is explained? Whatever the case, please leave a comment on the comments section below, so we can interact and learn from each other.

If you want to learn about other ROS topics, please let us know on the comments area and we will do a video about it.

ros-control-course-banner

ROS Extra Class: How to use GPS to do autonomous robot navigation?

ROS Extra Class: How to use GPS to do autonomous robot navigation?

 

Basically what we are going to teach in this extra Live-Class is:
1- How to record a trajectory that you would like the robot to do
2- How to make the robot reproduce that trajectory

Everything using the GPS as localization system.

This time we are going to use the ROS Development Studio to do the practice. Please you need to have an account at RDS (free account is ok, and fully working). Please it is very important that attendants have the account created prior to the class so we do not waste time with that process.

All the attendants will receive a full notebook and code that does the two points. The notebook will explain step by step how the code works and where to change for another robot different than the one used in the simulation.

This is an Extra Live Class requested by the ROS Agriculture community (http://rosagriculture.org/), that is why we are doing this Live Class on Saturday (instead of Wednesday). This is an extra class. Wednesday Live Class are still on the schedule (check it out Wednesday schedule here: ROS LIVE-Classes).

ROS Developers LIVE-Class #18: Let’s Simulate a World in Gazebo Simulator

ROS Developers LIVE-Class #18: Let’s Simulate a World in Gazebo Simulator

 

In this ROS LIVE-Class we’re going to create a world in the Gazebo simulator for the previous differential drive manipulator we created in the previous class, so the robot can navigate around and interact with the objects.

The model of the robot was created using URDF. However, the model of the environment will be created using SDF.

We will see:
▸ How to create the world for the robot using SDF
▸ How to add models of any object you may think of
▸ How to spawn ROS based robots in the world

Part 1

Part 2

Every Wednesday at 18:00 CET/CEST. 

This is a LIVE Class on how to develop with ROS. In Live Classes you practice with me at the same time that I explain, with the provided free ROS material.

IMPORTANT: Remember to be on time for the class because at the beginning of the class we will share the code with the attendants.

IMPORTANT 2: in order to start practicing quickly, we are using the ROS Development Studio for doing the practice. You will need a free account to attend the class. Go to http://rds.theconstructsim.com and create an account prior to the class.

// RELATED LINKS
▸ Gazebo simulator
▸ SDF format

Pin It on Pinterest