Developing a new simulated robot entity

I created a 3D model for the boe-bot. Now I would like to drive it around, as it is possible with for example the LogoNXTTribot. Thing is, I run into a lot of problems developing such an entity and there isn't any documentation on it available (or I overlooked something).

In "C:\Microsoft Robotics Studio (1.0)\samples\Simulation\Entities\Entities.cs" it seems as if this is an example of a simulated entity (LegoNXTTribot), but it only shows the MotorBase entity (differentialdriveentity). The loading of the model (the .bos file, or .obj file) isn't shown in here and when I look at SimulationTutorial 5, nothing but loading this MotorBase entity is done. It is as if the 3D model of the robot appears out of nothing.

Now, can someone give some pointers on how to create a complete new simulated entity with a motorbase, because after 2 days of staring at errors and the lack of documentation explaining this, I think I am missing something.

Tnx!Smile

Dennie

ps. If there is someone out there who allready created this (or another) simulated model, that would be a great reference too.

[1232 byte] By [Dennie] at [2008-1-5]
# 1
I can help here =). First, you need to add the following assemblies to the project if they're not in it already: Microsoft.Xna.Framework.dll, PhysicsEngine.dll. Both of them are in the MSRS/services directory. Of course, as usual, you need to add a few using lines at the top:

Code Snippet
using xna = Microsoft.Xna.Framework;
using xnagrfx = Microsoft.Xna.Framework.Graphics;
using xnaprof = Microsoft.Robotics.Simulation.MeshLoader;
using Microsoft.Robotics.Simulation.Physics;


Ok, so there is already MultiShapeEntity and SingleShapeEntity for you to use to create entities, but if you want to specify all of the physics, joints, mesh, and texture within a class definition, like they do for the Pioneer3DX entity, then just follow these steps.

1.) Derive your new entity from the VisualEntity class

Code Snippet
class MyEntity : VisualEntity
{

}

2.) Override these three functions from the base class. Within each of the overridden functions, call the base version of that function.

Code Snippet
class MyEntity : VisualEntity
{
public MyEntity() {} //Constructor, nothing needs to be here

public override void Initialize(Microsoft.Xna.Framework.Graphics.GraphicsDevice device, PhysicsEngine physicsEngine)
{
base.Initialize(device, physicsEngine);
}

public override void Render(Microsoft.Xna.Framework.Graphics.GraphicsDevice device, MatrixTransforms transforms, CameraEntity currentCamera)
{
base.Render(device, transforms, currentCamera);
}

public override void Update(FrameUpdate update)
{
base.Update(update);
}
}

Initialize() is called when the entity is inserted into the world and generally is the function where you construct the entity, Render() actually renders the visual representation of the entity, and Update() updates the physics of the entity.

I should note that unless you're doing something special in the Render() and Update() functions, then you don't need to worry about overriding them. However, it's still a good idea to do so considering that if you're making a custom entity, you're likely going to be doing something special in the Update() function, and perhaps occasionally in the Render() function. So I just override them just in case.

3.) Alright, so now we have an entity that we can put in the world, but it won't have any physics or visual representation. So, we want to add a BoxShape to our newly created entity. So, do it like this:

Code Snippet
class MyEntity : VisualEntity
{
public MyEntity() {} //Constructor, nothing needs to be here

public override void Initialize(Microsoft.Xna.Framework.Graphics.GraphicsDevice device, PhysicsEngine physicsEngine)
{
BoxShape entityShape = new BoxShape(new BoxShapeProperties(1.0f, new Pose(), new Vector3(1,1,1)));
this.State.PhysicsPrimitives.Add(entityShape);
base.Initialize(device, physicsEngine);
}

public override void Render(Microsoft.Xna.Framework.Graphics.GraphicsDevice device, MatrixTransforms transforms, CameraEntity currentCamera)
{
base.Render(device, transforms, currentCamera);
}

public override void Update(FrameUpdate update)
{
base.Update(update);
}
}

So, we've given it a shape, a box in particular, with dimensions of (1,1,1) and a position of (0,0,0), but if you compile and run this, you'll notice that the entity does not interact with the world, it just kind of sits there. You couldn't even connect joints to it really.

That is because there are no physics associated with it. The physics primitives merely specify the shapes that make up the physics of this entity, they do not imply any kind of interaction.

4.) So, you need to create a physics entity within this entity. You do it like this.

Code Snippet
class MyEntity : VisualEntity
{
public MyEntity() {} //Constructor, nothing needs to be here

public override void Initialize(Microsoft.Xna.Framework.Graphics.GraphicsDevice device, PhysicsEngine physicsEngine)
{
BoxShape entityShape = new BoxShape(new BoxShapeProperties(1.0f, new Pose(), new Vector3(1,1,1)));
this.State.PhysicsPrimitives.Add(entityShape);
CreateAndInsertPhysicsEntity(physicsEngine);

base.Initialize(device, physicsEngine);
}

public override void Render(Microsoft.Xna.Framework.Graphics.GraphicsDevice device, MatrixTransforms transforms, CameraEntity currentCamera)
{
base.Render(device, transforms, currentCamera);
}

public override void Update(FrameUpdate update)
{
base.Update(update);
}
}

A few notes on the additional line:
1.) If you try to create a physics entity before you put in a physics primitive, you will get a crashing error on the entity. Always add the primitives and then create the physics entity.
2.) If you base.Initialize() and then add the primitive and create the entity, it will not actually render the object, but the physics representation will still be there. The visual representation will be gone.

The optimal way of doing it is how I made it above.

Now, if you compile this, you will have an entity that will both render and interact with the world. This is the barest bones entity that you can create that A.) interacts with forces and the world and B.) has a visual representation - in this case it's a box.

If you notice, I did nothing with the constructor. That's because Initialize() is automatically called and you really can't do any of what I showed above in the constructor. However, you can always make member variables in the entity and initialize them in the constructor, as per usual.

Also, you may need to give the entity, not the box, a different position so that it does not start at (0,0,0), which would mean the world is passing right through the middle of the box. To modify the entity position (which will also modify the physics box position), use the MyEntity.State.Pose.Position property and set a new Vector3() to it (or by setting a new Pose(new Vector3()) to MyEntity.State.Pose).

From here, you can apply force (MyEntity.PhysicsEntity.ApplyForce(), or MyEntity.PhysicsEntity.ApplyForceAtLocalPosition()), torque (MyEntity.PhysicsEntity.ApplyTorque()), or bump it around with the rigid body camera.

Let me know if you have any problems. To read up further on the relationship between the physics representation and the visual representation, read the thread entitled "Documentation on Pose". =)

Take care!

Edit: Sorry, I had to edit a quite few times to fix some minor errors and clarify things.

EricFritzinger at 2007-10-3 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Simulation...
# 2
Wow, tnx for that. This will help me a lot. Smile
Dennie at 2007-10-3 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Simulation...
# 3
That's a great post, thanks!
Don at 2007-10-3 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Simulation...
# 4
I'm a bit of a newbie with this so can someone please tell me why i get and error saying :

"The type or namespace name 'Xna' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) "

I just used the code Eric posted so i don't understand. Sorry for being such a layman Smile

DeniBertovic at 2007-10-3 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Simulation...
# 5
I believe you are probably missing the DLL reference to Microsoft.Xna.Framework.dll.

For MSRS 1.0, it is located in the /services directory.


For MSRS 1.5, however, it's a bit different. There is another post located *here* which explains how to get access to that DLL for MSRS 1.5. Alan posts a link on his second post which explains how to get it. It's a crazy thing where you need to make a drive that contains the DLLs from a file in the windows directory and then extract the desired DLL from there.

Read through the whole thing and it should solve your problem =).

EricFritzinger at 2007-10-3 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Simulation...
# 6
Hi there,
I am, too, trying to create a simple snake-like robot from scratch. I have created a new service with dssnewservice and wanted to add the robot entity there. Having followed the instructions above, Visual Studio 2005 Express says that it can't find the namespace or type "MeshLoader" and, more important, it can't find the type "VisualEntity".
Which dlls and/or using statements do I need for this? I am using MSRS 1.5 (May CTP).

Thanks in advance,
Ben

bkloster at 2007-10-3 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Simulation...
# 7
Here is the complete list of using statements that I have in the project with a custom VisualEntity:
using Microsoft.Ccr.Core;
using Microsoft.Dss.Core;
using Microsoft.Dss.Core.Attributes;
using Microsoft.Dss.ServiceModel.Dssp;
using Microsoft.Dss.ServiceModel.DsspServiceBase;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Xml;
using simulation = Simulation;

using submgr = Microsoft.Dss.Services.SubscriptionManager;

using xna = Microsoft.Xna.Framework;
using xnagrfx = Microsoft.Xna.Framework.Graphics;
using xnaprof = Microsoft.Robotics.Simulation.MeshLoader;

using Microsoft.Robotics.PhysicalModel;
using Microsoft.Robotics;
using Microsoft.Robotics.Simulation;
using Microsoft.Robotics.Simulation.Engine;
using engproxy = Microsoft.Robotics.Simulation.Engine.Proxy;
using Microsoft.Robotics.Simulation.Physics;

Here are the DLLs I'm using:
Microsoft.Xna.Framework.dll
PhysicsEngine.dll
RoboticsCommon.dll
SimulationEngine.dll
SimulationEngineProxy.dll
SimulationCommon.dll

I hope this helps! =)
You probably don't need them all, but from here it can be a trial by testing to see which ones you need. At the moment I don't have .NET 3.0 installed to test all of this, but if I had to guess, I would say all you need is SimulationCommon.dll and Microsoft.Xna.Framework.dll added to the project to fix the problem. If not SimulationCommon.dll, then SimulationEngine.dll should do it.

EricFritzinger at 2007-10-3 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Simulation...
# 8
Thank you, it was SimulationEngine.dll.
bkloster at 2007-10-3 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Simulation...
# 9
Great to hear. Let me know if you need anything else! =D
EricFritzinger at 2007-10-3 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Simulation...
# 10

Hi,

Compiler is complaining it cannot find VisualEntity, I have added:

using xna = Microsoft.Xna.Framework;
using xnagrfx = Microsoft.Xna.Framework.Graphics;
using xnaprof = Microsoft.Robotics.Simulation.MeshLoader;
using Microsoft.Robotics.Simulation.Physics;

as well as PhysicsEngine and Microsoft.Xna.Framework.dll reference into the project.

Any suggestions?

Thanks

dextersim at 2007-10-3 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Simulation...
# 11

Hi,

Compiler is complaining it cannot find VisualEntity, I have added:

using xna = Microsoft.Xna.Framework;
using xnagrfx = Microsoft.Xna.Framework.Graphics;
using xnaprof = Microsoft.Robotics.Simulation.MeshLoader;
using Microsoft.Robotics.Simulation.Physics;

as well as PhysicsEngine and Microsoft.Xna.Framework.dll reference into the project.

Any suggestions?

Thanks

dextersim at 2007-10-3 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Simulation...
# 12
Go through the list of DLLs that Eric posted. You are probably missing SimulationCommon.dll and / or SimulationEngine.dll.
bkloster at 2007-10-3 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Simulation...
# 13

Hi I also need to create a new robot entity, so I tried to see how Eric's code works but I can't make it run.

I already added all the using statements and also the DLLs that Eric posted, also I had to add a few DLLs more. All of the DLLs that I'm using are:

Ccr.Core.dll
DssBase.dll
DssRuntime.dll
Microsoft.Xna.Framework.dll
PhysicsEngine.dll
RoboticsCommon.dll
SimulationCommon.dll
SimulationEngine.dll
SimulationEngine.proxy.dll
SimulationEngine.transform.dll

but still i got the following error: The type or namespace name 'Simulation' could not be found (are you missing a using directive or an assembly reference?)

I don't have any more DLLs related with Simulation, so I don't understand what's going on here

I would really apreciate some help and if anyone out there knows what is that "Simulation"? Is it a library or something like that?

VaqueritoFantasma at 2007-10-3 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Simulation...
# 14

Try deleting the using simulation = Simulation; statement.

The using statements that I usually use just for the simulation engine in simulation services are:

Code Snippet
using Microsoft.Robotics.Simulation;
using Microsoft.Robotics.Simulation.Engine;
using engineproxy = Microsoft.Robotics.Simulation.Engine.Proxy;
using Microsoft.Robotics.Simulation.Physics;
using Microsoft.Robotics.PhysicalModel;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

and the simulation-specific DLLs that need to be referenced are:

Microsoft.Xna.Framework
PhysicsEngine
RoboticsCommon
SimulationCommon
SimulationEngine
SimulationEngine.proxy
KyleJ-MSFT at 2007-10-3 > top of Msdn Tech,Microsoft Robotics Studio,Microsoft Robotics - Simulation...

Microsoft Robotics Studio

Site Classified