Using Laser Range Scanners in USARSim with Player

From Usarsim

Jump to: navigation, search

This tutorial will help you to get laser data from Usarsim by a Player controller.


What do you need

The things that you need for implementing this tutorial are:

  • Installation of UT2004 in windows
  • Installation of USARSIM for windows
  • Installation of Player 2.0.5 patched with USARSIM support (latest version) - Download from here : [1]


Add Lasers in you robot

Follow these steps:

  • Open USARBot.ini with a text editor. This file is placed in ut2004_install_dir/System
  • In this example we use the P2AT robot. Go to [USARBot.P2AT] label.
  • Normally the following line should exist:

This is a laser sensor (model SICKLMS). There is a tag in USARBot.ini that is named "USARModels.SICKLMS" and has the characteristics of a SickLMS laser. In this example I will use a Hokuyo laser. The line should be like this:


Pay special attention to the ItemName (you will use it at the Player section).

If you go to the Hokuyo tag you will se this:


From here you can change the properties of the laser. For example you can set the laser to have 10m MaxRange. Also you can see the Scan Field Of View (ScanFov) in rads. Here it is 4.71, so the scanner has 270 degrees field of view. The number of it's rays is ScanFov/Resolution = 270.

Now it's time to open a map. Go to ut2004_install_dir/Usar_Maps_Files/RunClientOnly and double click an a bat file. This should open a map.

Now let's go to Player (in our Linux installation):

Add support for Sonar Sensor

Create an cfg file that you will run with Player. This must look like this:

File robot.cfg :

	name "us_bot"
	provides ["simulation:0"]
	port 3000

	host ""
	# DM-Mapping 250
	pos [0.748 -7.282 -0.446]

	rot [0 0 270]
	bot "USARBot.P2AT"
	botname "P2AT"

  name "us_position"
  provides ["odometry:::position2d:0" ]
  requires ["simulation:0"]

   name "us_laser"
   provides ["laser:0"]
   requires ["simulation:0"]
   laser_name "Scanner1"

In the above example, I will spawn a P2AT robot in UT2004, at position (0.748 -7.282 -0.446), which will have drivers for position and a laser. In the "laser_name" tag you provide the ItemName you saw before in the USARBot.ini file.

IMPORTANT: You must specify the host IP address. This is the IP that the host of UT2004 has.

Start player and subscribe to drivers

Open a console, go to folder where the robot.cfg exists and execute:

player robot.cfg

This should spawn the robot in the map.

Also open another console and run


This will open the player viewer tool. Click on Devices->laser:0 and check the Subscribe button. This will subscribe the Laser in player and the laser's rays will appear.

Hokuyo laser in playerv

Now to write the controller...

Write the player controller

You must create a cpp file and among other stuff (that you need) you must have these lines:

	PlayerCc::PlayerClient 	*robot;
	PlayerCc::Position2dProxy *pp;
	PlayerCc::LaserProxy 	*lp;


	robot = new PlayerClient(PlayerCc::PLAYER_HOSTNAME, PlayerCc::PLAYER_PORTNUM);

	pp = 	new Position2dProxy(robot, 0);
	lp = 	new LaserProxy(robot, 0);

		while(!lp->IsFresh()) ;
		for(unsigned int i=0;i<270;i++){
			float x=lp->GetPoint(i).px;
			float y=lp->GetPoint(i).py;
			float dist=sqrt(x*x+y*y);
			if(!(i%5)) cout<<"\n";

The output should be something like this:

Ray1:3.6316	Ray2:3.6953	Ray3:3.7693	Ray4:3.8463	Ray5:3.9269	
Ray6:4.0079	Ray7:4.099	Ray8:4.1917	Ray9:4.2936	Ray10:4.4011	
Ray11:4.5102	Ray12:4.6338	Ray13:4.7664	Ray14:4.8961	Ray15:5.05	
Ray16:5.2058	Ray17:5.3747	Ray18:5.5601	Ray19:5.7576	Ray20:5.9763	
Ray21:9.9927	Ray22:9.9958	Ray23:10	Ray24:7.0384	Ray25:7.3908	
Ray26:7.7561	Ray27:8.1732	Ray28:8.6283	Ray29:9.1741	Ray30:9.7536	
Ray31:9.9224	Ray32:9.8847	Ray33:9.8443	Ray34:9.8092	Ray35:9.7943	
Ray36:9.7483	Ray37:9.7244	Ray38:9.7179	Ray39:9.6907	Ray40:9.6766	
Ray41:9.659	Ray42:9.6603	Ray43:9.6403	Ray44:9.6414	Ray45:9.6326	
Ray46:9.6324	Ray47:9.6372	Ray48:9.6447	Ray49:9.6601	Ray50:9.6791	
Ray51:9.6832	Ray52:9.7009	Ray53:9.7254	Ray54:9.765	Ray55:9.7947	
Ray56:9.812	Ray57:9.2934	Ray58:8.5962	Ray59:7.9878	Ray60:7.4585	
Ray61:7.0038	Ray62:6.6095	Ray63:6.2437	Ray64:5.9376	Ray65:5.6428	
Ray66:5.389	Ray67:5.1572	Ray68:4.9389	Ray69:4.7439	Ray70:4.5698	
Ray71:4.3998	Ray72:4.2579	Ray73:4.1081	Ray74:3.9842	Ray75:3.8642	
Ray76:3.7456	Ray77:3.6391	Ray78:3.5468	Ray79:3.4486	Ray80:3.3681	
Ray81:3.2868	Ray82:3.2068	Ray83:3.1364	Ray84:3.0683	Ray85:3.0029	
Ray86:2.9445	Ray87:2.8842	Ray88:2.8326	Ray89:2.7773	Ray90:2.7296	
Ray91:2.684	Ray92:2.6376	Ray93:2.599	Ray94:2.5562	Ray95:2.5184	
Ray96:2.4813	Ray97:2.4483	Ray98:2.4157	Ray99:2.3851	Ray100:2.3562	
Ray101:2.3292	Ray102:2.3027	Ray103:2.2737	Ray104:2.2526	Ray105:2.2263	
Ray106:2.2042	Ray107:2.1848	Ray108:2.1637	Ray109:2.1446	Ray110:2.1307	
Ray111:2.1133	Ray112:2.0947	Ray113:2.0791	Ray114:2.0686	Ray115:2.054	
Ray116:2.0401	Ray117:2.028	Ray118:2.0177	Ray119:2.0088	Ray120:1.9978	
Ray121:1.9883	Ray122:1.981	Ray123:1.9735	Ray124:1.9643	Ray125:1.9603	
Ray126:1.9526	Ray127:1.9497	Ray128:1.9426	Ray129:1.9396	Ray130:1.9372	
Ray131:1.9334	Ray132:1.9306	Ray133:1.9288	Ray134:1.931	Ray135:1.9285	
Ray136:1.9296	Ray137:1.9284	Ray138:1.9299	Ray139:1.9319	Ray140:1.937	
Ray141:1.9387	Ray142:1.9438	Ray143:1.9481	Ray144:1.9521	Ray145:1.9597	
Ray146:1.9665	Ray147:1.9725	Ray148:1.9776	Ray149:1.9894	Ray150:1.9966	
Ray151:2.0051	Ray152:2.0156	Ray153:2.0268	Ray154:2.0395	Ray155:2.0508	
Ray156:2.0666	Ray157:2.0781	Ray158:2.0931	Ray159:2.1121	Ray160:2.1265	
Ray161:2.1457	Ray162:2.1628	Ray163:2.1828	Ray164:2.2058	Ray165:2.2269	
Ray166:2.2511	Ray167:2.2756	Ray168:2.2991	Ray169:2.3243	Ray170:2.3538	
Ray171:2.3832	Ray172:2.4168	Ray173:2.4459	Ray174:2.4798	Ray175:2.5194	
Ray176:2.5561	Ray177:2.597	Ray178:2.6341	Ray179:2.6783	Ray180:2.7247	
Ray181:2.7767	Ray182:2.8254	Ray183:2.8813	Ray184:2.9408	Ray185:2.9968	
Ray186:3.0396	Ray187:2.9942	Ray188:2.9575	Ray189:2.9151	Ray190:2.881	
Ray191:2.8431	Ray192:2.811	Ray193:2.7792	Ray194:2.7545	Ray195:2.7229	
Ray196:2.6975	Ray197:2.6718	Ray198:2.6485	Ray199:2.6222	Ray200:1.1921	
Ray201:1.172	Ray202:1.1551	Ray203:1.1392	Ray204:1.1235	Ray205:1.1073	
Ray206:1.0924	Ray207:1.0804	Ray208:1.0664	Ray209:1.055	Ray210:1.0435	
Ray211:1.0311	Ray212:1.0199	Ray213:1.0101	Ray214:1.0011	Ray215:0.9917	
Ray216:0.9824	Ray217:0.9909	Ray218:1.0303	Ray219:1.0748	Ray220:1.1201	
Ray221:1.1737	Ray222:1.2289	Ray223:1.2936	Ray224:1.3625	Ray225:1.4425	
Ray226:1.5309	Ray227:1.845	Ray228:1.9765	Ray229:2.1261	Ray230:2.3682	
Ray231:2.3694	Ray232:2.3747	Ray233:2.379	Ray234:2.3882	Ray235:0.7966	
Ray236:0.7241	Ray237:0.662	Ray238:0.6109	Ray239:0.579	Ray240:0.5821	
Ray241:0.5847	Ray242:0.5885	Ray243:0.5916	Ray244:0.5949	Ray245:0.5985	
Ray246:0.6029	Ray247:0.6066	Ray248:0.6112	Ray249:0.6159	Ray250:0.6214	
Ray251:0.6267	Ray252:0.6317	Ray253:0.6382	Ray254:0.644	Ray255:0.6507	
Ray256:0.6576	Ray257:0.6648	Ray258:0.6722	Ray259:0.6801	Ray260:0.689	
Ray261:0.6982	Ray262:0.7074	Ray263:0.7161	Ray264:0.7268	Ray265:0.7377	
Ray266:0.7484	Ray267:0.7614	Ray268:0.7737	Ray269:0.7861

For any questions/corrections/additions contact me in etsardou(at)

Tsardoulias Manos - Aristotel University of Thessaloniki - Greece

Personal tools