[ROS Q&A] 127 – How to stop robot if /cmd_vel doesn’t receive any message

In this video we are going to see how to create a Python script that stops a robot if no message is received in the /cmd_vel topic after a certain period of time.

This is a video trying to answer the following question posted at the ROS answers forum.

// RELATED LINKS

▸ Original question: https://answers.ros.org/question/292512/stop-my-robot-if-cmd_vel-doesnt-receive-a-message-within-a-certain-time-period/
▸ Robot Ignite Academy: robotigniteacademy.com
▸ ROS Basics in 5 days (Python): /ros-basics-in-5-days/
▸ ROS Development Studio (RDS): /rds-ros-development-studio/

▸ You can get the code and the simulation of this video ready to be used in the ROS Development Studio following this link: https://goo.gl/3u9RuV

[ROS Q&A] 126 – How to configure the differential drive ROS controller

[ROS Q&A] 126 – How to configure the differential drive ROS controller

 

In this video we are going to see how to configure the differential drive ROS controller for a wheeled robot using a Gazebo simulation.

This is a video trying to answer the question of Jaime posted at the ROS answers forum about how he cannot make the controller work, and receiving the error:

Controller Spawner couldn’t find the expected controller_manager ROS interface

 

Step1. Create Project

Let’s start with creating a new project in ROS development studio.

Notice: If you haven’t had an account yet. You can register one here for free.

Step2. Spawn a robot

As an example, we’ll use a self-build two-wheel differential drive robot.

You can test the code with your own robot with differential drive configuration.

Step3. Add the controller configuration file for your robot

Put the configuration file(e.g. the my_diff_drive.yaml file shows here) under the config folder, your source tree may look like this.

Let’s start by pasting the whole code from the question into the my_diff_drive.yaml file.

mobile_base_controller:
  type        : "diff_drive_controller/DiffDriveController"
  left_wheel  : 'wheel_left_joint'
  right_wheel : 'wheel_right_joint'
  publish_rate: 50.0               # default: 50
  pose_covariance_diagonal : [0.001, 0.001, 1000000.0, 1000000.0, 1000000.0, 1000.0]
  twist_covariance_diagonal: [0.001, 0.001, 1000000.0, 1000000.0, 1000000.0, 1000.0]

  # Wheel separation and diameter. These are both optional.
  # diff_drive_controller will attempt to read either one or both from the
  # URDF if not specified as a parameter
  wheel_separation : 1.0
  wheel_radius : 0.3

  # Wheel separation and radius multipliers
  wheel_separation_multiplier: 1.0 # default: 1.0
  wheel_radius_multiplier    : 1.0 # default: 1.0

  # Velocity commands timeout [s], default 0.5
  cmd_vel_timeout: 0.25

  # Base frame_id
  base_frame_id: base_footprint #default: base_link

  # Velocity and acceleration limits
  # Whenever a min_* is unspecified, default to -max_*
  linear:
    x:
      has_velocity_limits    : true
      max_velocity           : 1.0  # m/s
      min_velocity           : -0.5 # m/s
      has_acceleration_limits: true
      max_acceleration       : 0.8  # m/s^2
      min_acceleration       : -0.4 # m/s^2
      has_jerk_limits        : true
      max_jerk               : 5.0  # m/s^3
  angular:
    z:
      has_velocity_limits    : true
      max_velocity           : 1.7  # rad/s
      has_acceleration_limits: true
      max_acceleration       : 1.5  # rad/s^2
      has_jerk_limits        : true
      max_jerk               : 2.5  # rad/s^3

Step4. Create Launch file

For our case, the launch file should look something similar like this.

<?xml version="1.0" encoding="UTF-8"?>
<launch>
    <param name="robot_description" command="cat '$(find two_wheels_description)/urdf/two_wheels.urdf'" />
    
    <arg name="x" default="-2"/>
    <arg name="y" default="0"/>
    <arg name="z" default="0.1"/>
    
    <node name="mybot_spawn" pkg="gazebo_ros" type="spawn_model" output="screen"
          args="-urdf -param robot_description -model mybot -x $(arg x) -y $(arg y) -z $(arg z)" />
          
    <rosparam file="$(find two_wheels_description)/config/my_diff_drive.yaml" command="load" />
    
    <node name="SARA_controller manager" pkg="controller_manager" type="spawner"
          respawn="false" output="screen" args="mobile_base_controller" />
          
          
</launch>

NOTICE:

Two errors are the spot when we are doing this. 

  1. The args for the controller should have the same name in the .yaml file which is “mobile_base_controller”
  2. According to the .yaml file, there is no namespace /robot here, so we don’t need to add this to the controller node.

Things to make sure:

  1. The left wheel and right wheel in the .yaml file should be the same as your robot’s URDF definition.
  2. The gazebo controller should be added to the URDF definition as well as the transmission tag which will be used for the gazebo controller. In our case, we add the following code in the .urdf to add gazebo control in it.
...

<transmission name="left_wheel_transmission">
  <type>transmission_interface/SimpleTransmission</type>
  <joint name="wheel_left_joint">
    <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>  
  </joint>
  <actuator name="left_wheel_actuator">
    <mechanicalReduction>7</mechanicalReduction>
    <hardwareInterface>VelocityJointInterface</hardwareInterface>
  </actuator>
</transmission>

<transmission name="right_wheel_transmission">
  <type>transmission_interface/SimpleTransmission</type>
  <joint name="wheel_right_joint">
    <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>  
  </joint>
  <actuator name="right_wheel_actuator">
    <mechanicalReduction>7</mechanicalReduction>
    <hardwareInterface>VelocityJointInterface</hardwareInterface>
  </actuator>
</transmission>

...

<gazebo>
  <plugin name="gazebo_ros_control" filename="libgazebo_ros_contol.so">
  </plugin>
</gazebo>

 

Step4. Lanch again

It’s better to compile again and run:

cd ~/simulation_ws

catkin_make

source devel/setup.bash

roslaunch two_wheel_drscription question.launch

Then you can use

rostopic list

If you see the following topics, then your controller is up and run correctly.

Takeaway today:

  1. The arg name of the controller node should be the same as in the controller configuration file.
  2. Don’t specify robot namespace if you are not using it.
  3. The joint name in the controller configuration file should be the same as the name in urdf
  4. The gazebo_ros_control plugin should also be added to the urdf file.
  5. Remember to compile again before you run.

If you want to learn more about ROS control and how to build a two-wheel robot in ROS from scratch, please visit Robot Ignite Academy for more information.

 

// RELATED LINKS

▸ Original question: https://answers.ros.org/question/289561/help-to-run-diff_drive_controller/
▸ Robot Ignite Academy: https://goo.gl/pF81sN
▸ ROS Basics in 5 days (Python): https://goo.gl/HGPP1M
▸ ROS Basics in 5 days (C++): https://goo.gl/evXQCA
▸ ROS Development Studio: https://goo.gl/FzHTQU

[ROS Q&A] 125 – Save and load RViz configuration

[ROS Q&A] 125 – Save and load RViz configuration

 

In this video we are going to show how you can easily save and load RViz configurations, using the Robot Ignite Academy.

Step 1. Go to the Robot Ignite Academy

Here is the link: https://goo.gl/631YF4

You can preview every course for free.

Let’s start with the Ch.4 -Path planning 1

Step 2. Visualize path planning in RViz

3 elements are essential for the visualization of the path planning.

  • Map Display (Costmaps)
  • Path Displays (Plans)
  • 2D Tools

Let’s start with launching the move_base by typing the following command in the shell

$ roslaunch husky_navigation move_base_demo.launch

Then start RViz in another shell with

$ rosrun rviz rviz

To visualize the robot model and laser scan, click add at the left bottom corner and select robot model and laser scan. Select topic /scan in the laser scan and make sure you choose a proper size.

Then we add two map visualization by clicking add and set one to visualize the global cost map and another to visualize the local cost map.

To visualize the path plan, we add two Path visualization. Notice: choose correct topics

Now if you close the Rviz, every setting you’ve done will disappear!

Step 3. Save Rviz settings

let’s create a package named husky_nav_rviz by type the following command under ~/catkin_ws/src directory

$ catkin_create_pkg husky_nav_rviz

and create a rviz folder under it.

Then we back to rviz and select File -> save config as to save the path_planning.rviz config file under the folder we just created.

You can close RViz once you are sure the path_planning.rviz is in the folder.

Step 4. Load Rviz settings

By select the path_planning.rviz file from File -> Open Config you can get all your settings back, or you can use the following command

$ rosrun rviz rviz -d `rospack find husky_nav_rviz`/rviz/path_planning.rviz

 

Takeaway Today:

Always save your RViz configuration with .rviz file, so you can restore every setting you’ve done when you launch RViz next time.

 

// RELATED LINKS

▸ Robot Ignite Academy: https://goo.gl/631YF4
▸ ROS Navigation in 5 days online course: https://goo.gl/fkQTR7

[ROS Q&A] 124 – Range sensor does not detect obstacles in Gazebo

[ROS Q&A] 124 – Range sensor does not detect obstacles in Gazebo

In this video, we are answering a question about why the range sensor plugin for Gazebo is not detecting obstacles. The answer to that problem will surprise you !!! (ha, ha, ha).

In this posting, we will go through a demo of laser data visualization

NOTE: This article assumes that the audience is familiar with the following:

  • Running scripts on the terminal
  • Ros filesystem layout (what goes where launch dir, src dir etc)
  • RDS Environment (How to launch a project, how to navigate the directories.

Step – 1. Creating a new project

  • Create a new project. Choose an informative name and add some description in the description field.
  • Load the project. (This can take a few moments to a minute depending on your internet)
  • Run the IDE from the Tools menu and verify the filesystem layout it should have a similar structure

root
├── ai_ws
├── catkin_ws
│ ├── build
│ ├── devel
│ └── src
├── notebook_ws
│ ├── default.ipynb
│ └── images
└── simulation_ws
├── build
├── devel
└── src

Step – 2. Cloning the existing source

root
├── ai_ws
├── catkin_ws
│ ├── build
│ ├── devel
│ └── src
│ ├── CMakeLists.txt
│ └── fakeLaserScan
│ ├── CMakeLists.txt
│ ├── launch
│ │ └── fakeLaserScan.launch
│ ├── package.xml
│ ├── README.md
│ └── src
│ ├── fakeLaserScan.cpp
│ ├── listener.cpp
│ └── talker.cpp
├── notebook_ws
│ ├── default.ipynb
│ └── images
└── simulation_ws
├── build
├── devel
└── src

Step – 3. Briefly skim through the code and run it

  • First, we go through the contents of package.xml (located inside the fakeLaserScan directory) which has the following content
    (NOTE comments are removed in this reproduced code snippet for brevity)
<?xml version="1.0"?>
<package>
  <name>beginner_tutorials</name>
  <version>0.0.0</version>
  <description>The beginner_tutorials package</description>

  <maintainer email="user@todo.todo">user</maintainer>

  <license>TODO</license>

  <buildtool_depend>catkin</buildtool_depend>
  <build_depend>roscpp</build_depend> 
  <build_depend>rospy</build_depend> 
  <build_depend>sensor_msgs</build_depend> 
  <build_depend>std_msgs</build_depend> 
  <build_export_depend>roscpp</build_export_depend> 
  <build_export_depend>rospy</build_export_depend> 
  <build_export_depend>sensor_msgs</build_export_depend> 
  <build_export_depend>std_msgs</build_export_depend> 
  <exec_depend>roscpp</exec_depend> 
  <exec_depend>rospy</exec_depend> 
  <exec_depend>sensor_msgs</exec_depend> 
  <exec_depend>std_msgs</exec_depend>

  <export>
  </export>
</package>

 

This file contains various pieces of information about the project such as the package dependencies (roscpprospysensor_msgsstd_msgs) project nameversionlicensemaintainer etc. Some of this information is vital for building the project (like the dependencies). While other information is important from the perspective of sharing one’s work with the community.

In the given contents of the package.xml file, we notice that the project name specified in the file (beginner_tutorials) is different from the directory name (fakeLaserScanner). While this will not cause the project to crash but it is inconsistent with the project naming guideline.

Next, we take a look at the code inside fakeLaserScan.cpp

 

  • This code creates a publisher with the name fakeScan
  • The scan values are being generated inside a for loop (line 15-18 (excluding the blank lines))
  • These scan values are then copied to a LaserScan message (line 20, 32-35)
  • The message is being published at line 36. Also, note that the publish rate is 1 Hz (line 12)

As all seems okay we will go ahead and build the project. On the console browse to the catkin_ws directory and then run

$ catkin_make

This should proceed without any errors.

Next, we launch the project with the following command

$ roslaunch beginner_project fakeLaserScan.launch

This also should proceed without any errors.

Now we will open another console from the Tools menu and verify the topics with following commands

$ rostopic list

Outputs :

/fakeScan
/rosout
/rosout_agg

In the result, we see out topic /fakeScan appears. Further, we can check if the topic is publishing the correct information or not with the following command

$ rostopic info /fakeScan

Outputs

Type: sensor_msgs/LaserScan

Publishers:
* /fakeLaserScan (http://10.8.0.1:42942/)

Subscribers: None

Thus we verified that the topic is indeed publishing a scan message. Lets load rviz to visualize the data.

$ rosrun rviz rviz

First, we will add a laser component to the displays panel as shown here

Click on the ADD button on the bottom left

From the menu that has just appeared, select the laser component (as shown)

  • Once the laser component appears we can select the topic by clicking on the field (as shown)

Now we see that there is an error with the frame field.

To solve that error we will modify the Fixed Frame field in the Global Option component by writing fake_lasaer_frame in the field (as shown)

Also, we need to modify the size setting of the laser component to see the laser scan

  • Finally, we have the scan showing up in the visualization panel.

What we did is essentially telling rviz to use the laser_frame for the global fixed frame as well.

This can be done by remapping with the following line of command

$ rosrun tf static_transform_publisher 0 0 0 0 0 0 1 map fake_laser_frame 10

 

// RELATED LINKS:

* ROS Answers original question: https://answers.ros.org/question/291726/range-sensor-does-not-detect-objects-in-gazebo/

* Robot Ignite Academy: https://goo.gl/vPiuiC

* ROS Development Studio: https://goo.gl/fGnMuv

[ROS Q&A] 123 – Roslaunch can’t locate node, but rosrun works fine

[ROS Q&A] 123 – Roslaunch can’t locate node, but rosrun works fine

In this video, we are going to answer a question found at ROS answers (https://answers.ros.org/question/291235/roslaunch-cant-locate-node-but-rosrun-works-fine/). The person is asking why he can run a Python script with rosrun, but not when using roslaunch.

Let’s try this out and solve this problem in ROS Development Studio. You can register a free account and follow the tutorial below! 

Step1: create a package

After creating a new project in RDS, open a new shell from the tools tab and type the following command into the shell to create a ROS package.

cd catkin_ws/src/
catkin_create_pkg video_qa rospy

Step2: create a test file for the code.

It’s easier to do this with an IDE. You can find IDE in the tools tab.

Now right click and select the new file to open a new file test under the folder /video_qa/src

Paste the following code into the test file.

#! /usr/bin/env python

import rospy

rospy.init_node('test')
rate = rospy.Rate(1)

while not rospy.is_shutdown():
    print "Hello there"
    rate.sleep()

Step3: create a launch file

According to ROS’s file structure, the launch file should be created under the launch directory. Let’s create it with the IDE and add a test.launch file under the /video_qa/launch folder.

Copy and paste the following code for testing. 

<launch>
    <node pkg="video_qa" type="test" name="test" output="screen">
    </node>
</launch>

Step4: start roscore

To run the code with roslaunch, we need to start roscore. You can either do that by typing roscore into the shell or start a simulation from the Simulations tab.

Step5: rosrun and roslaunch

Firstly, we try to directly execute the test file using rosrun video_qa test, but we got some error message.

[rosrun] Couldn’t find executable named test below /home/user/catkin_ws/src/video_qa

That’s because of the lack of permission for this file. We can give the file permission by typing:

chmod +x video_qa/src/test

then we do rosrun video_qa test again. It works! 

Then we try roslaunch video_qa test.launch. Strangely, it also works…WHY?

It turns out if we name the file test.py instead of test, we will have the same problem. To solve it, we rename the file to test.py and also in the launch file we use test.py instead of test.

TAKEAWAY:

Always name the file with extension(e.g. test.py). However, the type in the launch file takes the executable during the compiling process. Since there is no need for compiling .py file. If you use python, just put the file name with the extension(e.g. test.py) in the type section.

I hope you enjoy the ROS Q&A video today. If you are interested in learning ROS, please check the links below for the Robot ignite academy.

 

// RELATED LINKS
▸ ROS answers question: https://answers.ros.org/question/291235/roslaunch-cant-locate-node-but-rosrun-works-fine/
▸ ROS Development Studio: https://goo.gl/273g12
▸ Robot Ignite Academy: https://goo.gl/LsMMqh
▸ ROS Basics in 5 days online course: https://goo.gl/TDVG1j

[ROS Q&A] 122 – How to show laser data on Rviz

[ROS Q&A] 122 – How to show laser data on Rviz

 

In this video, we are going to answer a question found at ROS answers (https://goo.gl/ws2Whw). The person is asking why he cannot show the laser data of a fake laser given that he is publishing the proper frame and even a static transform from the laser to map.
Very simple and surprise answer!

Step 1. Create project

Instead of installing and configuring a ROS environment locally, we can easily reproduce this question in ROS Development Studio. You can register an account for free now! After signing up and creating a new project, we can clone the repo provided in the question into the workspace. Open a Shell window in the Tools tab and type the following command:

$ cd catkin_ws/src 

$ git clone https://github.com/erenaud3/fakeLaserScan 

You can use IDE tools to check the source tree.

 

Step 2. Compile and Run

It seems the code is mostly correct. Let’s compile it first by typing the following command in the shell.

$ roscd; cd ..

$ catkin_make

$ source devel/setup.bash

Then we launch the fakeLaserScan.launch file in the package.

$ roslaunch beginner_tutorials fakeLaserScan.launch

Step 3. Check if the topic is publishing correctly

To check if the node we just launched really publishing something, we open another shell and type

$ rostopic echo -n1 /fakeScan

The fakeScan topic is publishing.

Let’s check it further with Rviz by typing.

$ rosrun rviz rviz

1.In order to see Rviz running in the RDS, open the Graphical Tools in the Tools Tab.

2.Add a LaserScan visualization.

3. The visualization is not showing due to some problems with the frame.

4. Let’s change the fixed frame to the fake_laser_frame

Now everything looks fine but the laserscan still not showing.

How come?

It turns out, in this particular example, it’s not showing simply because the size of the visualization is too small to be seen. Let’s change the size.

Takeaway Today:

  1. You can check if one topic is publishing correctly by typing rostopic echo /TOPICNAME
  2. If you want to check the topic in RViz, remember to select correct topic type, correct frame and choose a proper size!

 

If you want to learn more about ROS, we have ROS courses for different levels available in Robot Ignite Academy. You can preview any of them for free.

 

Edit by Tony Huang

[irp posts=”7406″ name=”ROS Q&A | How to merge data from two different lasers”]

// RELATED LINKS
▸ ROS answers question: https://goo.gl/ws2Whw
▸ ROS Development Studio: https://goo.gl/Mx18Zn
▸ Robot Ignite Academy: https://goo.gl/XFkCpk
▸ ROS Navigation in 5 days online course: https://goo.gl/AV4hv4

Pin It on Pinterest