Alexander Dahl

As described in other threads around here I have a "simulation service" as in simulation tutorial 2 which creates a world, adds a bot and so on. I write the current position of my bot to the state of this service. The bot is an instance of a derived DifferentialDriveEntity as private member of the service class. (In sim tutorial 2 it's added to the sim engine and then thrown away, I create an instance to be able to access it later.)

I looked at the example code of Ben Axelrod's SimRobot and Logger he published a few days ago. Now the question: I get the position directly from: myBotInstance.Position, this member is defined in class VisualEntity. Ben fetches it from robotEntity.State.Pose.Position. State is a member of class Entity. So far the obvious differences.

Can you please point out which solution should be preferred and why or is this all regardless

Note: Ben uses the Pioneer3DX class, my bot class is derived from DifferentialDriveEntity almost similar, I just changed some dimensions, mass and so on.




Re: Microsoft Robotics - Simulation Where to get position/rotation of robot entities

KyleJ - MSFT

The Position property is mostly meant for use by the simulation editor. I recommend that you code directly accesses the State.Pose.Position in the entity.

If you're just reading the position, the Position property and the State.Pose.Position are essentially the same. The only difference is that the Position property returns an xna.Vector3 while the State.Pose.Position is a Microsoft.Robotics.PhysicalModel.Vector3. Here is the code for the Get accessor of the Position property:

Code Snippet

get

{

return TypeConversion.ToXNA(State.Pose.Position);

}

If you are setting the position, the two things have a very different behavior. Setting the Position property sets the State.Pose.Position and it also calls entity.PhysicsEntity.SetPose() to move the entity to that position and orientation. It also updates any children entities that need to be moved. Setting State.Pose.Position doesn't have an effect on the entity unless you also explicitly call entity.PhysicsEntity.SetPose() with the new pose.

The Rotation property has a similar relationship to State.Pose.Orientation except that it returns an xna.Vector3 of Euler angle rotations instead of a quaternion.

-Kyle





Re: Microsoft Robotics - Simulation Where to get position/rotation of robot entities

Alexander Dahl

KyleJ - MSFT wrote:

The Position property is mostly meant for use by the simulation editor. I recommend that you code directly accesses the State.Pose.Position in the entity.

If you're just reading the position, the Position property and the State.Pose.Position are essentially the same. The only difference is that the Position property returns an xna.Vector3 while the State.Pose.Position is a Microsoft.Robotics.PhysicalModel.Vector3. Here is the code for the Get accessor of the Position property:

Code Snippet

get

{

return TypeConversion.ToXNA(State.Pose.Position);

}

Until now I Just read the position for logging purpose. So it just seems to be a question of choice between xna.Vector3 and Microsoft.Robotics.PhysicalModel.Vector3.

KyleJ - MSFT wrote:

If you are setting the position, the two things have a very different behavior. Setting the Position property sets the State.Pose.Position and it also calls entity.PhysicsEntity.SetPose() to move the entity to that position and orientation. It also updates any children entities that need to be moved. Setting State.Pose.Position doesn't have an effect on the entity unless you also explicitly call entity.PhysicsEntity.SetPose() with the new pose.

Perhaps I will set the position directly later, I don't know yet. I want to try without dirty tricks first and move my (simulated) bot with it's own differential drive.

Thanks for your explanation so far, but I have another question: I'm curious why you introduced a second Vector3 class Does the XNA one lack something the MSRS one has






Re: Microsoft Robotics - Simulation Where to get position/rotation of robot entities

KyleJ - MSFT

The Microsoft.Robotics.PhysicalModel.Vector3 types are used outside of simulation in other robotics services. It didn't make sense to have every service depend on XNA types and we didn't want every service to have to change if we went to another rendering library. It is our intention to make it possible to use the PhysicalModel types in as many places as possible but we still have some work to do.

-Kyle





Re: Microsoft Robotics - Simulation Where to get position/rotation of robot entities

Alexander Dahl

You're right, there's no need to depend on types defined in a library which is not necessarily used in the whole project. You quoted TypeConversion.ToXNA and I saw there is FromXNA too. I assume these conversions are lossless. Thanks for your patience and explanations, this won't be my last question...






Re: Microsoft Robotics - Simulation Where to get position/rotation of robot entities

Alexander Dahl

Ok I got the next one... -- I just use this thread, cause I think it's somewhat ontopic.

I repeat my setup shortly: I have a generic "simulation service" called BotEnvSimulation. I have my implementation of this generic contract called SimpleDoorService. I have a bot similar to the Pioneer3DX from the samples but with changed physical parameter.

Now I added the following member to my generic state in BotEnvSimulationTypes.cs:

Code Block

[DataContract()]

public class BotEnvSimulationState

{

Dictionary<string, Pose> m_botPoses =

new Dictionary<string, Pose>();

[DataMember]

[Description("Positions and Orientations of several entities in a dictionary/hastable.")]

public Dictionary<string, Pose> BotPoses

{

get { return m_botPoses; }

set { m_botPoses = value; }

}

}

Pose is Microsoft.Robotics.PhysicalModel.Pose since I added the following using directive:

Code Block

using Microsoft.Robotics.PhysicalModel;

I use this state in my SimpleDoorService:

Code Block

using pxbotenvsim = Fraunhofer.IFF.MMI.Services.BotEnvSimulation.Proxy;

namespace Fraunhofer.IFF.MMI.Playground.SimpleDoor

{

[DisplayName("SimpleDoor")]

[Description("The SimpleDoor Service")]

[Contract(Contract.Identifier)]

[AlternateContract("http://schemas.tempuri.org/2007/09/botenvsimulation.html")]

[CLSCompliant(true)]

public class SimpleDoorService : DsspServiceBase

{

#region Deklaration der Entities

private EntranceEntity m_entrance;

private PowerBot m_powerBot;

#endregion

#region Service

// partner attribute will cause simulation engine service to start

[Partner("Engine",

Contract = engineproxy.Contract.Identifier,

CreationPolicy = PartnerCreationPolicy.UseExistingOrCreate)]

private engineproxy.SimulationEnginePort m_engineServicePort =

new engineproxy.SimulationEnginePort();

private pxbotenvsim.BotEnvSimulationState m_state =

new pxbotenvsim.BotEnvSimulationState();

Now the whole world creation is done as in Simulation Tutorial 2 and I have a bot adding routine:

Code Block

private void AddPowerBot(Vector3 position)

{

m_powerBot = CreateMotorBase(ref position);

CameraEntity camera = CreateCamera();

// insert as child of motor base

m_powerBot.InsertEntity(camera);

// Finally insert the motor base and its two children to the simulation

SimulationEngine.GlobalInstancePort.Insert(m_powerBot);

m_state.BotPoses.Add("bot", m_powerBot.State.Pose);

}

This last line causes an (sorry, german) error:

Fehler 2 Der Typ "Microsoft.Robotics.PhysicalModel.Proxy.Pose" ist in einer nicht referenzierten Assembly definiert. Fugen Sie einen Verweis auf die Assembly "RoboticsCommon.Proxy, Version=1.5.507.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" hinzu. D:\Work\vs_projects\SimpleDoor\SimpleDoor.cs 311 13 SimpleDoor

The tooltip on the line Visual Studio marks as error says, that it was impossible to convert my argument m_powerBot.State.Pose from type Microsoft.Robotics.PhysicalModel.Pose to Microsoft.Robotics.PhysicalModel.Proxy.Pose. I got two questions here: why does he want to convert this at all I did not use Microsoft.Robotics.PhysicalModel.Proxy in my using directives. And the second question of course: how do I solve this problem

As explanation: I wanna use this dictionary because I want to be able to write a Dashboard and a Logging Service which show or log positions regardless which concrete simulation environment I start. I could hardcode this all, but I want the LoggingService to fetch the instance of the dictionary as state from a service implementing the BotEnvSimulation as alternate contract. It would be possible to take all keys and values or just some I'm interested in in my concrete Logging Service setup/implementation.






Re: Microsoft Robotics - Simulation Where to get position/rotation of robot entities

KyleJ - MSFT

It is better if you post new questions to a new thread. That way other people can more easily find the answers they need and I can more easily keep track of which questions have been answered and which still need attention.

Can you please re-post this question in a new thread

Thanks!

-Kyle





Re: Microsoft Robotics - Simulation Where to get position/rotation of robot entities

Alexander Dahl

ACK and done.