Remember that if you prefer to watch a video, the following video covers the same content of this post.
Step 1. Create an account in Robot Ignite Academy (RIA)
The steps explained in this post can be executed in your local computer without any problem, but if you want an environment that has everything already set, we highly recommend you creating an account in RIA. The platform helps you to Learn ROS Fast in the easiest way possible, without you having to setup the ROS environment locally. The only thing you need is a web browser! If you want to try the platform, you can easily create an account here and start to browse the trial course for free now! We’ll use the ROS Basic course as an example today.
Step 2. Create a package
In order to create our publisher we first need a package. Let’s create one called tutorial under the ~/catkin_ws/src directory with the following command
cd ~/catkin_ws/src
catkin_create_pkg tutorial rospy
Then we create a file called publisher.py under the ~/catkin_ws/src/tutorial/src folder and insert the following content on that file:
#! /usr/bin/env python
import rospy
from std_msgs.msg import String
rospy.init_node('tutorial')
publisher = rospy.Publisher('/say_hello', String, queue_size=1)
rate = rospy.Rate(3) # 3 Hz
while not rospy.is_shutdown():
publisher.publish('Hey!')
rate.sleep()
Before we execute our file let’s analyze what that code does, starting with the first 3 lines:
#! /usr/bin/env python
import rospy
from std_msgs.msg import String
In the first line we basically tell Linux that we use Python code. In the subsequent two lines we import the required packages. The rospy package contains classes and functions that allow us to easily instantiate ROS Nodes (among other functionalities) using python. The type of message we will publish is a String , that is why we imported it. Let’s analyze the remaining code.
With rospy.init_node(‘tutorial’) we basically initialize our ROS Node and call it tutorial. A ROS Node can have the name you want, as far it doesn’t contain spaces. If you choose a name of a node that already exists, then ROS will automatically kill the existing one when you launch yours. Be aware of that.
After initializing our node we create our publisher. In the first parameter of rospy.Publisher we provide name of the topic in which we want to publish. If you don’t know yet what is a Topic, please check our other posts or take our ROS In 5 Days (Python) course that explains that and also shows you how to create publishers, subscribers, services, actions, how to use debugging tools, etc. Now, back torospy.Publisher , in the second parameter we specify the type of message we want to publish in that topic, which in this case is String. The third parameter is the queue_size, which specify the amount of messages that will be queued before the messages are dropped if not consumed.
The rate variable we created is because we want to publish 3 messages per second. Let’s now check the last part of our code:
while not rospy.is_shutdown():
publisher.publish('Hey!')
rate.sleep()
The line while not rospy.is_shutdown(): is to keep our node publishing messages while roscore is running. If somehow roscore is killed, our ROS Node just finishes. This way, whoever is running our code won’t have to manually kill our node, which is really useful in case you have hundreds of nodes, really common on real robots.
Inside the while block we publish our message. In this example we publish the message Hey!. You can publish any message, like Congratulations YOU_NAME, you have your first ROS Publisher working.
To make sure we publish 3 messages a second we use rate.sleep().
With everything in place, it’s time to run our node. You have to make sure your file is executable. Let’s do that with the following commands:
cd ~/catkin_ws/src/tutorial/src
chmod +x publisher.py
rosrun tutorial publisher.py
In Robot Ignite Academy you already have a roscore running and if you are using the platform, your code should have been executed without any problem. If you are running it on your own computer, you must run roscore in a separated shell (or run it in background with roscore & before actually running your node.
Assuming your node is running, you shouldn’t see any message because we are not printing any, but you can check that your node is running by executing the command below in a separated shell:
rosnode list
That command shows the list of nodes running in your ROS environment. You should see a node called /tutorial, which is the name we gave to our node.
To make sure your publisher is publishing on the correct topic, you can use the command below to list the topics.
rostopic list
You should see a topic called /say_hello because it is what we defined when creating our publisher.
Now, in order to see the messages that are being publishing we just run the command below:
rostopic echo /say_hello
You should see the messages being printed.
That is all for today guys. I hope you have liked the post and the video, if so, please share this post or the video with your friends.
Whether you like the video or not, please leave a comment on the comments section of the video on YouTube.
ROS Control Tutorials #Unit 1: Introduction to ROS Control
In this short video you’ll be introduced to ROS Control, an aspect of ROS that enables robots to move and get things done. We’ll be using Gazebo robot simulation. Follow along!
[irp posts=”8194″ name=”All about Gazebo ROS (Gazebo 9)”]
ROS Control Tutorials #Unit 2: Basic Concepts
In this video we look at some basic theoretical concepts regarding ROS control that we will use throughout the rest of the course.
ROS Control Tutorials #Unit 3 : How To Configure and Launch the Controllers
This video explains how to configure and launch the controllers after configuring transmissions and the Gazebo plugin in the robot URDF files. It shows: 1. how to create a package to launch the controllers, and 2. how to write commands to test the controllers.
Either you like the video or not, please leave a comment on the comments section below, so we can interact and learn from each other.
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! We’ll use the ROS Basics in 5 Days course as an example today.
Step2. Create a ROS Package
You can see the help about the catkin_create_pkg by passing the “-h” parameter: catkin_create_pkg -h
To create your package in the catkin_ws/src folder with the command catkin_create_pkg +package name +package dependencies. For example,
catkin_create_pkg tutorial rospy std_msgs
Here we create a package called tutorial with the dependencies rospy and std_msgs because we want to use the python api and std_msgs package.
After that, ROS will create a package for you. Inside the package, you’ll find the package.xml and CMakeLists.txt which will help you to compile the package.
You can compile them with the catkin_make command.
But sometimes when you create a package, ROS is not able to find it “instantly”. If this happens, just type source devel/setup.bash to source the file.
Want to learn more?
If you are interested in this topic please visit our ROS In 5 Days (Python) course. You’ll learn how to create workspace, package, topic, service, and action in this course.
Either you like the video or not, please leave a comment on the comments section below, so we can interact and learn from each other.
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! We’ll use the ROS Basics in 5 Days course as an example today.
Step2. Create catkin workspace
In the course, we have already created a catkin workspace for you called catkin_ws. You can create it yourself. For example, if you don’t have catkin_ws, you can create it using the following command.
cd ~
mkdir catkin_ws/src -p
cd ~/catkin_ws/src
catkin_init_workspace
You should see that a file called CMakeLists.txt is created which will help you compile the files in the workspace.
cd ~/catkin_ws
catkin_make
With this command, ROS created two extra folders for you called build and devel. To use the package, type
source devel/setup.bash
This command will make sure that you source the right directory which contends all the package you’ve compiled.
Remember that to avoid having to source the ~/catkin_ws/devel/setup.bash each time you open a new shell, you can add the “source ~/catkin_ws/devel/setup.bash” on your ~/.bashrc
Want to learn more?
If you are interested in this topic, please visit our ROS In 5 Days (Python) course. You’ll learn not only how to create the workspace, but also packages, topic, service, and action in ROS.
In this series of videos we are going to learn how to use MoveIt! package with industrial robots. In this series we are going to use the Sawyer robot by Rethink Robotics.
[irp posts=”8709″ name=”Learning MoveIt! with Sawyer robot – #Part 2″]
// PART 1 VIDEO CONTENT
In this first video, we are showing:
▸ How to get the Sawyer simulation up and running
// RELATED LINKS
▸ You can launch the simulation at ROS Development Studio: https://goo.gl/VKDvsk
Want Your Robotics Idea Happen in 2018? This Is Your Webinar!
What you will learn from this ROS Robots Webinar Series
We will guide you step by step from idea to a real robotics product that you can start selling in three weeks from now
We will show you which materials to use, which parts to buy, how to program the whole robot to perform its task, and how to launch it to the world
We will use the example of Barista robot, a robot that serves coffee to the tables, made in 3 months by a couple of students with no prior knowledge of robotics.
EPISODE #1
We will:
▸ Set the outline of the whole project
▸ Find the parts that will have to buy
▸ Decide software to build
EPISODE #2
We will:
▸ Show you the document which describes the Barista robot project (based on what was taught on EPISODE 1).
▸ Based on that document, we will see how to select the parts you need for your project.
▸ Based on that document, we show you how to start with simulating your robot and environment.
▸ Then we start developing the software that will go on the robot, using that simulation.
▸ The whole process will be taught for a general product (your product!). Also, we will show how we applied all this to the development of the Barista robot
▸ We will answer your questions about your own robotic product.
EPISODE #3
We will:
▸ We will show you how to find the people and parts that will make your robot a real product.
▸ We will show you how to proceed to test with the real robot.
▸ We will show you how to iterate, jumping from simulation to the real robot until the product really works as needed.
▸ We will show you how to present to society at a big launching event.
▸ The whole process will be taught for a general product (your product!). Also, we will show how we applied all this to the development of the Barista robot
▸ We will answer your questions about your own robotic product.