To create the arena, we are going to create a seperate entity "ArenaEntity" to insert the object into the simulation engine. We'll start by adding a C# class file to our simulation project. Then inside the class, we create 4 walls (made out of a box shape) and place these as the corners. there is no floor, so make sure the simulation has an appropiate floor.
using System.Collections.Generic;
using Microsoft.Dss.Core.Attributes;
using Microsoft.Robotics.Simulation.Engine;
using Microsoft.Robotics.PhysicalModel;
using Microsoft.Robotics.Simulation.Physics;
namespace Robotics.Rc2009Arena
{
[DataContract, DataMemberConstructor]
public class ArenaEntity : MultiShapeEntity
{
public ArenaEntity() { }
public ArenaEntity(Vector3 position)
{
Vector3 arenaBorderH = new Vector3(5.0f, 0.8f, 0.01f);
Vector3 arenaBorderV = new Vector3(0.01f, 0.8f, 5.0f);
Vector4 arenaColor = new Vector4(0.7f, 0.7f, 0.7f, 0.7f);
float arenaHeight = arenaBorderH.Y / 2;
State.Pose.Position = position;
State.Flags = EntitySimulationModifiers.Kinematic;
BoxShape rand1 = new BoxShape(
new BoxShapeProperties(
30, new Pose(
new Vector3(0, arenaHeight, -2.5f)),
arenaBorderH
)
);
BoxShape rand2 = new BoxShape(
new BoxShapeProperties(
30, new Pose(
new Vector3(
0, arenaHeight, 2.5f)),
arenaBorderH
)
);
BoxShape rand3 = new BoxShape(
new BoxShapeProperties(
30, new Pose(
new Vector3(
-2.5f, arenaHeight, 0)),
arenaBorderV
)
);
BoxShape rand4 = new BoxShape(
new BoxShapeProperties(
30, new Pose(
new Vector3(
2.5f, arenaHeight, 0)),
arenaBorderV
)
);
rand1.BoxState.DiffuseColor = arenaColor;
rand2.BoxState.DiffuseColor = arenaColor;
rand3.BoxState.DiffuseColor = arenaColor;
rand4.BoxState.DiffuseColor = arenaColor;
this.BoxShapes = new List<BoxShape>();
this.BoxShapes.Add(rand1);
this.BoxShapes.Add(rand2);
this.BoxShapes.Add(rand3);
this.BoxShapes.Add(rand4);
}
}
}
Finally we need to insert the arenaEntity into our simulation world, so from the start method in our simulation project, add a call to AddArena to position it in your world.
AddArena(new Vector3(2.5f, 0, 2.5f));
private void AddArena(Vector3 position)
{
ArenaEntity ISR = new ArenaEntity(position);
ISR.State.Name = "Info Support Arena";
SimulationEngine.GlobalInstancePort.Insert(ISR);
}back
Posted
10-08-2008 12:47
by
Erik Oppedijk