Raúl
Moderador
 Moderador
| Mensajes: 444 |  | Karma: 6
|
Re:How do I use the simulated sonar? - 2008/08/12 16:53
Hi, in case you want to use the simulated sonar in your own robot the first thing you need to do is to add the corresponding simulated sonar entity as a child of the robot simulated entity. You can have a look to how this is done in the ExplorerSimSonar Application:
-> ExplorerSimSonarApplication.
In this example, the service MazeSimulatorRA creates a simulated world, including a Pioneer 3DX robot. The simulated sonar is added to the robot as follows:
| Code: | void AddPioneer3DXRobot(Vector3 position)
{
// TT Dec-2006 - Make the position a parameter
// TT Jun-2007 - Changes to the Simulated Differential Drive
// required a new version of the Pioneer3DX. This is annoying
// because it was only a change of class name but it had some
// flow-on effects. The problem arises because you can't just
// replace an entity that is in built into the Simulator.
TTPioneer3DX robotBaseEntity = CreateMotorBase(ref position);
// Raul - Create the sensor entities according to settings.
if (_state.UseLRF)
{
// Create Laser entity and start simulated laser service
LaserRangeFinderEntity laser = CreateLaserRangeFinder();
// Add laser as child to motor base
robotBaseEntity.InsertEntity(laser);
}
if (_state.UseSonar)
{
// Raul - Replace LRF with SONAR:
SonarEntity sonar1 = CreateSonar(0.0f);
// Raul - Insert Sonar
robotBaseEntity.InsertEntity(sonar1);
}
// Create bumper array entity and start simulated bumper service
BumperArrayEntity bumperArray = CreateBumperArray();
// Insert as child of motor base
robotBaseEntity.InsertEntity(bumperArray);
// TT - Copied from Oct CTP Simulation Tutorial 2
// Create Camera Entity and start SimulatedWebcam service
CameraEntity camera = CreateCamera();
// insert as child of motor base
robotBaseEntity.InsertEntity(camera);
// Reverse the orientation of the robot so that it will
// drive "forwards" from the user's perspective (it is
// actually driving in the Z direction)
robotBaseEntity.State.Pose.Orientation = Quaternion.FromAxisAngle(0, 1, 0, (float)(Math.PI));
// Finaly insert the motor base and its two children
// to the simulation
//_simEnginePort.Insert(robotBaseEntity);
SimulationEngine.GlobalInstancePort.Insert(robotBaseEntity);
}
|
Note that I use a flag to insert either a laser or a sonar depending on my current configuration...
And the createSonar method is as follows:
| Code: | /// <summary>
/// Creates a frontal SONAR array entity for the Pioneer 3 DX robot.
/// </summary>
/// <param name="dx">X position of sonar source "rays"</param>
/// <returns></returns>
private SonarEntity CreateSonar(float dx)
{
// Create a Sonar Entity.
// Place it 30cm above base CenterofMass.
SonarEntity sonar = new SonarEntity( new Pose(new Vector3(dx, 0.30f, 0)) );
sonar.State.Name = "SimulatedSonar";
// TT - From Oct CTP
sonar.SonarBox.BoxState.DiffuseColor = new Vector4(0.25f, 0.25f, 0.8f, 1.0f);
// Create Sonar simulation service and specify
// which entity it talks to
CreateService(
pxsonar.Contract.Identifier,
Microsoft.Robotics.Simulation.Partners.CreateEntityPartner(
"http://localhost/" + sonar.State.Name));
return sonar;
}
|
Hope this helps...
Cheers,
Raúl.
Raúl Arrabales Moreno. conscious-robots.com/raul |