Player/Stage Overview

modified on 12 April 2010 at 04:10 - 6,488 views

From RoboWiki

(Redirected from Player/Stage)
Jump to: navigation, search

Please see Player/Stage Drivers for driver design and Writing a Player Plugin to develop your own driver.

The Player/Stage project provides an advanced robotics simulation and interface platform. Player and Stage provide both the tools to simulate, as well as communicate to, a physical robot system. The platform is dynamic enough to allow you to use the Player server to control either your physical robot or a simulated robot in Stage. The Player server provides a set number of defined interfaces, such as sonar and GPS. These interfaces are linked to the world by pieces of code called drivers. Note that a driver does not always have to interact with devices in the real world (i.e. actuators and sensors.) Some drivers provide algorithmic features such as path-planning, vision, and more.

Player works by creating several layers of abstraction. It hides low-level hardware-specific implementations in a set of pre-defined "interfaces". The high-level controls (containing logic) only interact with these interfaces, which means they can be (mostly) agnostic of the devices behind the interfaces. By doing this you can create modular code, interchangeable between hardware and projects. For instance, code that controls an actual robot through the "position2d" and "laser" interfaces can easily be run to control a virtual robot in the Stage simulator. The Player server manages communications (over TCP or UDP) between interfaces, other Player servers, and clients. Player is community supported, as an open-source project, and is continuously improving and expanding.

Note how the Player server uses proxies, which interface with drivers, to control hardware.
  • Player/Stage is a platform to simulate and/or control your robot's sensors and behavior.
  • A client is an external program that interact with the Player server.
  • Player is a server, that recieves and sends standard messages to and from your client and robot.
  • Stage is a simulation system for a robot and it's environment.
  • An Interface is a pre-defined set of messages and datatypes for a certain class of device or algorithm.
  • A proxy is a way to access an interface from a separate program, to provide data to/from the robot/client. This is an abstract level independent of your hardware.
  • A driver is the code implementation that translates between interface commands/data and the device specific languages.

The Player Project provides a Quick Start guide on their site for getting started with Player, though the design and usage of Player is documented below.

Contents

[edit] Installing Player

To install Player:

  1. Follow the instructions provided at the Player project's Download page.
  2. Type player at the command prompt. If all went well, you should get the version information and a list of drivers compiled into Player.

If you have dependency issues, go into Applications -> Add/Remove Software on your desktop. You will be prompted to enter the root password, then the Package Manager will appear. It may take a little while, because it downloads updates from the internet. Under the Development category, check off Development Libraries, Development Tools, and Gnome Software Development. Hit OK and it will install the updates. Try configure --prefix=/usr again. Note that you do not necessarily need to install the Player successfully right away. The archive you unzipped contains all of player's source code, if you go into your file manager and navigate to Examples/libplayerc++ you can see some sample client programs written in C++. All the sources for the drivers are located under server/drivers. Try not to change any of these files as it may break the build.

Errata

Unfortunately, player 2.1.1 and 2.1.2 were not tested with the newest version of gcc, which implements a more strict version of c than player expects. If make starts throwing errors, you may be suffering from this problem.

The quick and dirty fix is to add these libraries:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

to the following files:

client_libs/libplayerc++/playerc++.h
server/driver/laser/lms400_cola.h
server/drivers/mricp/include/geometry2D.h
server/drivers/mricp/include/map.h

Also, Ubuntu is not installed with the requisite libraries to compile player. If you have Ubuntu and you receive an error like /usr/bin/ld: cannot find -lXext, you must download the libxext-dev package and its dependencies. you can do that with:

sudo apt-get install libxext-dev

This helpful tutorial contains information on installing Stage.

[edit] Sample Design

Player and Stage are not complicated, and provide a powerful platform. Since there is a large amount of functionality, the difficulty is learning it all at once. Bellow is a simplistic example of how player works with a two-wheeled robot.

Imagine you have a robot which provides two sonar sensors (Front and back) and moves with two wheels (Froward, backwards, rotates left, and right). Because this robot is too small to hold a PC, it is remotely controlled via a serial-USB cable that connects to an on-robot microcontroller. This microcontroller uses custom code to send and receive data and instructions. We will also assume this project uses C++ as it's programming language and the C++ Player client libraries. It is important to note that Player provides support for several other languages, but this is just an example. To use Player with this project, you will have to write two pieces of code:

You will have to write the Player/Stage Logic(client) and the Custom Driver (driver).
  • Custom controller for your robot functionality called the client
  • A Player driver for interfacing player with your robot's hardware

The client will contain proxies to interfaces, but never any hardware specific code, nor driver-specific code, as they are abstracted through these Player standard interfaces. As defined earlier, a driver is used so that Player can communicate through standard protocols it defines (interfaces) and hides the specific implementation of your custom hardware code. Since many drivers already exist, read the currently supported drivers list you don't need to rewrite existing code and waste your time. A real-world example of this code exists as the Mini Grand Challenge project, specifically the Arduino-to-Player Driver code.

By creating this driver layer, Player allows you to run the same high-level Player logic code on any robot that provides the same basic functionality, regardless of the driver or hardware used. In our case, since we want to provide two functionalities (sonar and movement), we will implement message handling for the PlayerCc::SonarProxy proxy and the PlayerCc::Position2dProxy proxy. These proxies are used from the client, as a way of communicating with a running Player server and accessing the sonar and position2d interfaces. Read the supported Player proxies list to get an idea of all available proxies. Each proxy is a different major and sub type, defining whether they query data or run instructions, as well as how they communicate in terms of data-structures.

Read the Player/Stage Drivers article for more code-specific questions and Writing a Player Plugin for a full walk-through of a sample driver code. It is important to note that this code is compiled as an external library to be loaded at run-time with the Player client.

Once we have created the driver, which is a separate library file paired with a configuration file, we will create the high-level player logic. In this layer we can apply all robot logic, such as avoiding walls and maze navigation. This level only uses proxies to control all the robot's functionality. In this case, we can instance a Position2DProxy class which can control movement by sending a velocity and a wheel angle.

This above example is simplistic, but it goes to show how dynamically Player may be used.

[edit] Sample Client Code

The below client code shows how to connect to a local player client on port 6665, instance a Position2DProxy object, and move the controlled robot in a circle for ten seconds.

// Includes
#include <stdio.h>
#include <libplayerc++/playerc++.h>
 
using namespace PlayerCc;
 
// Initialization
int main()
{
	// Connect to the local player process on port 6665
	PlayerClient myRobot("localhost", 6665);
 
	// Create a position 2d proxy
	Position2DProxy vehicle(&myRobot, 0);
 
	// For 10 seconds move into a circle
	myRobot.Read();
	for(int i = 0; i < 10; i++)
	{
		sleep(1);
		vehicle.SetCarlike(10, -25); // Move 10 m/s with a wheel angle of -25 degrees
	}
 
	// End of program
	return 0;
}

[edit] External Links