[ROS Q&A] 158 – How to publish once (only one message) into a topic

[ROS Q&A] 158 – How to publish once (only one message) into a topic

 

Learn how to publish once (only one message) into a topic by checking the connections of the Publisher.

RELATED LINKS

Robot Ignite Academy
ROS Development Studio (ROSDS)

 

We love 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.

[ROS2 Tutorials] How to Launch a ROS2 Node

About:
In the following video you will learn how to launch a ROS2 node in just a couple of minutes.

RELATED ROS RESOURCES&LINKS:

ROS Development Studio (ROSDS) —▸ http://rosds.online
Robot Ignite Academy –▸ https://www.robotigniteacademy.com


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 🙂

#ROS2 #Robot #ROS2tutorials

[ROS Q&A] 49 – How to navigate while avoiding obstacles

[ROS Q&A] 49 – How to navigate while avoiding obstacles

Q: How to navigate while avoiding obstacles? Original question here: https://answers.ros.org/question/274391/could-use-some-guidance-on-how-to-navigate-while-avoiding-obstacles/?answer=274526#post-id-274526

A: In order to do navigation using a laser for localization and obstacle avoidance, you need to do first a map of the environment you want to move through. For that, you need to use the gmapping package. Launch the gmapping package, and then move the robot around using the keyboard or joystick so it can build the map.

Once the map is done, you need to save it using the following command:
rosrun map_server map_saver -f name_of_map

Then you are ready to use that map for localization and sending the robot to different locations in the map, while avoiding obstacles. Kill the gmapping node and launch now the localization package (the amcl). Together with the amcl you need to launch the map_server (to use the map you created on the previous step) and the move_base (to make the robot move around while avoiding obstacles).

RELATED LINKS:

ROS Q&A | How to Start Programming Drones using ROS

ROS Q&A | How to Start Programming Drones using ROS

In this video answer, we walk through the basics of a Parrot AR Drone Gazebo simulation.
You will learn the topics provided by the simulation and how to use a ROS program to interact, sending commands or reading sensors, with this robot.

[irp posts=”8190″ name=”Performing LSD-SLAM with a ROS based Parrot AR. Drone”]

Let’s get started!

Step1. Create a new project on ROS Development Studio(RDS)

We’ll use ROS Development Studio(RDS) for this tutorial, you can register a free account here.

After logging into RDS, click on create my project. It will move to the public simulation. You can find tons of public simulation here offered by the construct for free and start to work on any of them in just minutes. See how powerful RDS is! For today, we’ll use sjtu_drone_tc project. Please click on it. Click the tools menu, you can find some tools that help you develop in RDS. For example, you have the:

  1.  Shell: it is the terminal where you can execute commands in RDS. You can open it as many as you want in RDS!
  2.  IDE: It’s the best way to explore the source tree of your project. With a right click, you can add or remove files easily.
  3. Jupyter Notebook: You can take notes for your project here. Since it’s working with python shell, you can directly execute python script here. A default notebook is provided to help you start the simulation.
  4. Graphical tool: You can use all the GUIs supported by ROS here(e.g. RViz, rqt_gui…etc.)

Notice:

We are not automatically running the simulation when you start RDS now. In order to have the same simulation shown in the video. Please go Simulations->Select launch file->main.launch to launch it by yourself. Then you can type the following command in a shell to check if the topics are correctly publishing by the drone.

$ rostopic list

 


Step2. Get started with the simulation

Let’s get started by following the instruction in the default jupyter notebook. Open it from tools->jupyter notebook->default.ipynb.

We can make the drone take off with the shell command

$ rostopic pub /drone/takeoff std_msgs/Empty "{}"

You should see the drone take off as soon as you send this command.

Notice:

You can use the ROS auto-completion function while you are typing a ROS command by pressing [TAB]. It’s a good idea to do that when the command is too long and hard to type it correctly.

You can also land the drone with the following command

$ rostopic pub /drone/land std_msgs/Empty "{}"

You can also find an instruction in the default.ipynb shows you how to do it with a python script instead of sending commend from shell.


Step3. Program with drones

We have more examples for you! Let’s say, we want to use the position control function provided by the drone. We found there is a topic called /drone/posctrl, but how to use it? By typing

rostopic info /drone/posctrl

You’ll see the output like this.

Type: std_msgs/Bool

Publishers:
* /my_node (http://ip-172-31-35-31:45972/)

Subscribers:
* /gazebo (http://10.8.0.1:44685/)

It seems that the topic is using the Bool message, but what is Bool message and how can I use it? You can further investigate it by typing

rosmsg show std_msgs/Bool

and got the output

bool data

The Bool message is very simple. It contains only one attribute called data with the type bool. Let’s try to send a message to this topic! Before we publish to the topic, we set up a monitor first with

rostopic echo /drone/posctrl

Then copy, paste and execute the following code in jupyter notebook.

from std_msgs.msg import Bool

var_bool = Bool()
pub_posctrl = rospy.Publisher('/drone/posctrl',Bool,queue_size = 1)
var_bool.data = True
pub_posctrl.publish(var_bool)

You should see

data: True

which means the message is published correctly. We enable the position control function on the drone successfully. Similarly, you can move the drone by publishing Twist message to the /cmd_vel topic. Here is an example script

from geometry_msgs.msg import Twist

var_twist = Twist()
pub_position = rospy.Publisher('/cmd_vel', Twist, queue_size=1)
var_twist.linear.x = 1
var_twist.linear.y = 1
var_twist.linear.z = 2
pub_position.publish(var_twist)

Now you know how to start programming drones easily with RDS! You can do lots of things in RDS(e.g. using the cameras on the drone to implement computer vision algorithms). If you are interested but have no ideas how to do it, you can check our Programming drones with ROS course on robot ignite academy!

 

Edit by Tony Huang

[Links and resources mentioned in the video]

– ROS Development Studio: https://goo.gl/1Qb4AT

– The course of Programming Drones with ROS is available here: https://goo.gl/x6yaZW


programming-drone-with-ros-course-banner

[ROS Q&A] How to import python modules from different ROS packages

[ROS Q&A] How to import python modules from different ROS packages

 

Learn how to import python modules from other packages and make them available for all the system. Also learn how to correctly install python scripts and modules.

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

ROSDS helps you follow our tutorial in a fast pace without dealing without setting up an environment locally. If you haven’t had an account yet, you can create a free account here.

Step 1. Create package

In this ROSject, let’s create a new package which contains the modules that you want to use in other packages.

cd ~/catkin_ws/src
catkin_create_pkg rospy

You also need a folder which has the same name as the package under the src folder and inside it, you need a empty__init__.py file.

cd test_pkg/src
mkdir test_pkg
cd test_pkg
touch __init__.py

Then you create the module you want under the src folder(e.g. the ClockSubscriber module in the coomon_tools_pkg). You’ll also need a setup.py file with the following content under the package to help the ROS system find this package.

from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup

setup_args = generate_disutils_setup(
    packages=['common_tools_pkg'],
    package_dir=['':'src'],
)

setup(**setup_args)

In the CMakeLists.txt file, you should change it like the following

cmake_minium_required(VERSION 2.8.3)
project(common_tools_pkg)
...
find_package(catkin REQUIRED COMPONENTS
    rospy
)
...
catkin_package(
)
...
include_directories(
    ${catkin_INCLUDE_DIRS}
)

Then you can compile the package

cd ~/catkin_ws
catkin_make
source devel/setup.bash

Then you can import the module into other scripts. For example,

from common_tools_pkg.clock_subscriber impot ClockSubscriber

That’s it. You can use modules from other packages now.

In addition, we want to talk about how to install the package in your system by changing the CMakeLists.txt like following

...
file(GLOB python_scripts_DIR
    "scripts/*.py"
)
...
install(DIRECTORY launch
    DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})

catkin_install_python(PROGRAMS ${python_scripts_DIR}
                      DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})

This will install all the script and launch file to the system lib folder so that all scripts using python can access to the module.

 

Edit by: Tony Huang

Pin It on Pinterest