Making my own Autonomous Robot in ROS / Gazebo

Posted 卡斯柏的博客

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Making my own Autonomous Robot in ROS / Gazebo相关的知识,希望对你有一定的参考价值。

Day 1:

Setting up

  • ROS: Indigo
  • OS: Ubuntu 14.04
  • OS: Gazebo 7.0.0

Initialize the workspace

To create the basic skeleton of the directory structure, we begin with a workspace {WORKSPACE}_ws, where we set {WORKSPACE}=mybot.

cd ~
mkdir -p mybot_ws/src
cd mybot_ws/src
catkin_init_workspace
cd ..
catkin_make
echo "source ~/mybot_ws/devel/setup.bash" >> ~/.bashrc # Adds workspace to search path

In the src folder are three main packages, {MODEL}_control{MODEL}_description{MODEL}_gazebo. We set {MODEL} = mybot. To create a package: catkin_create_pkg {PKG_NAME} {PKG_DEPENDENCIES}. In this case, we have no {PKG_DEPENDENCIES} = “”.

cd ~/mybot_ws/src/
catkin_create_pkg mybot_control
catkin_create_pkg mybot_description
catkin_create_pkg mybot_gazebo

Creating your own World

Let’s start with the gazebo package, go in there and create the following subfolders:

roscd mybot_gazebo 
mkdir launch worlds

At first we want to create a world for our gazebo server. Therefore we switch to our worlds directory and create a new world file.

cd worlds
gedit mybot.world

A basic world file defines at least a name:

<?xml version="1.0"?>
<sdf version="1.4">
<world name="myworld">
</world>
</sdf>

Here you could directly add models and object with their position. Also the laws of physics may be defined in a world. This is an important step to understand, because in this file you could also attach a specific plugin to an object. The plugin itself contains ROS and Gazebo specific code for more complex behaviors.

At first we just want to add some basic objects, like a ground and a basic illumination source inside the world tag.

	<include>
		<uri>model://sun</uri>
	</include>

	<include>
		<uri>model://ground_plane</uri>
	</include>

Check your “~/.gazebo/models” directory, as this is a default path for saved models. If this path does not exist try to find /usr/share/gazebo/setup.sh where gazebo looks for models. Otherwise add it to your model path.

As the ground plane and the sun are basic models that are also on the gazebo server they will be downloaded on startup if they cannot be found locally. If you want to know which object are available on the gazebo server, take a look at Gazebo model database. To start the gazebo server there are several methods. As it is a good practice to use a launch file, we will create one now. This could later also be used for multiple nodes.

Change to the launch directory of your project:

roscd mybot_gazebo/launch

Create a new file:

gedit mybot_world.launch

and insert:

<launch>	  
	<include file="$(find gazebo_ros)/launch/empty_world.launch">	    
		<arg name="world_name" value="$(find mybot_gazebo)/worlds/mybot.world"/>	    
		<arg name="gui" value="true"/>	  
	</include>	
</launch>

This launch file will just execute a default launch file provided by Gazebo, and tell it to load our world file and show the Gazebo client. You can launch it by doing:

roslaunch mybot_gazebo mybot_world.launch

Now you should see the gazebo server and the gui starting with a world that contains a ground plane and a sun (which is not obviously visible without objects). If not, it can be that there are some connections problems with the server.

If that happens, start gazebo without the launch file, go to the models, you should find the one you want in the server. Click on them, they will be put in the cache. Now, if you close gazebo and start it again with the launch file, it should work.

If you would press “Save world as” in “File” in your gazebo client and save the world in a text file, you could investigate the full world description.

If you want to watch a more complex and beautiful world environment then add the following inside your world tag:

  	<include>
		<uri>model://willowgarage</uri>	
	</include>

This one shows you the office of Willow Garage, be careful, it’s huge and may make your simulation extremely slow.

Create the Robot Model (URDF)

In ~/mybot_ws/src/mybot_description/urdf, there are four files:

  • mybot.xacro: primary file that loads the other three files and contains only URDF items like joints and links
  • mybot.gazebo: contains gazebo-specific labels that are wrapped within gaz
  • materials.xacro: maps strings to colors
  • macros.xacro: macros to help simplify

Run the Models

Load the Gazebo simulator and rviz in separate terminals

roslaunch mybot_gazebo mybot_world.launch
roslaunch mybot_description mybot_rviz.launch

Send a base controller command and ensure that the robot moves in both Gazebo and rviz

rostopic pub /cmd_vel geometry_msgs/Twist "linear:
  x: 0.2
  y: 0.0
  z: 0.0
angular:
  x: 0.0
  y: 0.0
  z: 0.1"

 

------------------------------

Reference:

[Tutorial] Getting Starting with Autonomous Robots in ROS via Simulations

以上是关于Making my own Autonomous Robot in ROS / Gazebo的主要内容,如果未能解决你的问题,请参考以下文章

IOS:facebook sdk per my own post

我什么时候应该使用java.util.Stack vs My Own Implementation? [关闭]

roscore报错:Unable to contact my own server at [http://w:46221/].

ROS-debug1 : 运行roscore时报错:Unable to contact my own server at...

运行roscore出现unable to contact my own server无法启动小海龟的部分故障问题解决

my robot 英语作文