none
microsoft robotics Unable to load CorobotWheel.dos RRS feed

  • 问题

  • I want to use Visual Studio 2008 to  creat a MRDS sevice .when I run the code ,it points out " unable to load CorobotWheel.dos"

    thank you!

    2012年5月3日 14:10

答案

全部回复

  • using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Xml;
    using corobot = ProMRDS.Simulation.Corobot;
    using Microsoft.Ccr.Core;
    using Microsoft.Dss.Core;
    using Microsoft.Dss.Core.Attributes;
    using Microsoft.Dss.ServiceModel.Dssp;
    using Microsoft.Dss.ServiceModel.DsspServiceBase;
    using W3C.Soap;
    using submgr = Microsoft.Dss.Services.SubscriptionManager;
    
    #region Simulation namespaces
    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 xna = Microsoft.Xna.Framework;
    using xnagrfx = Microsoft.Xna.Framework.Graphics;
    #endregion
    
    
    namespace ProMRDS.Simulation.Corobot
    {
        [Contract(Contract.Identifier)]
        [DisplayName("Corobot")]
        [Description("Corobot service (no description provided)")]
       public class CorobotService : DsspServiceBase
        {
    
           [Partner("Engine",
           Contract = engineproxy.Contract.Identifier,
           CreationPolicy = PartnerCreationPolicy.UseExistingOrCreate)]
            private engineproxy.SimulationEnginePort _engineStub =
                new engineproxy.SimulationEnginePort();
    
            
            /// <summary>
            /// Service state
            /// </summary>
            [ServiceState]
            CorobotState _state = new CorobotState();
    
            /// <summary>
            /// Main service port
            /// </summary>
            [ServicePort("/Corobot", AllowMultipleInstances = true)]
           private CorobotOperations _mainPort = new CorobotOperations();
    
            [SubscriptionManagerPartner]
            submgr.SubscriptionManagerPort _submgrPort = new submgr.SubscriptionManagerPort();
    
            /// <summary>
            /// Service constructor
            /// </summary>
            public CorobotService(DsspServiceCreationPort creationPort)
                : base(creationPort)
            {
            }
    
            /// <summary>
            /// Service start
            /// </summary>
            protected override void Start()
            {
    
                // 
                // Add service specific initialization here
                // 
    
                base.Start();
    
                //MainCamera initial view
                CameraView view = new CameraView();
                view.EyePosition = new Vector3(-1.65f, 1.63f, -0.29f);
                view.LookAtPoint = new Vector3(0, 0, 0);
                SimulationEngine.GlobalInstancePort.Update(view);
    
                //Add a SkyDome.
                SkyDomeEntity sky = new SkyDomeEntity("skydome.dds", "sky_diff.dds");
                SimulationEngine.GlobalInstancePort.Insert(sky);
    
                // Add a directional light to simulate the sun.
                LightSourceEntity sun = new LightSourceEntity();
                sun.State.Name = "Sun";
                sun.Type = LightSourceEntityType.Directional;
                sun.Color = new Vector4(0.8f, 0.8f, 0.8f, 1);
                sun.Direction = new Vector3(0.5f, -.75f, 0.5f);
                SimulationEngine.GlobalInstancePort.Insert(sun);
    
                // create a large horizontal plane, at zero elevation.
                HeightFieldEntity ground = new HeightFieldEntity(
                    "Ground", // name
                    "Gravel.dds", // texture image
                    new MaterialProperties("ground",
                        0.2f, // restitution
                        0.5f, // dynamic friction
                        0.5f) // static friction
                    );
                SimulationEngine.GlobalInstancePort.Insert(ground);
    
                Vector3 dimensions = new Vector3(2f, 2f, 2f); // meters
    
                // create simple movable entity, with a single shape
                SingleShapeEntity box = new SingleShapeEntity(
                    new BoxShape(
                        new BoxShapeProperties(
                        100, // mass in kilograms.
                        new Pose(), // relative pose
                        dimensions)), // dimensions
                        new Vector3(0, 1f, 29f * 2.54f / 100f + 1f));
    
                // Name the entity. All entities must have unique names
                box.State.Name = "box";
    
                // Insert entity in simulation.  
                SimulationEngine.GlobalInstancePort.Insert(box);
    
                // create a Corobot
                SimulationEngine.GlobalInstancePort.Insert(new CorobotEntity("Corobot", new Vector3(0, 0, 0)));
               }
            }
            ///<summary>
            /// An entity which represents a Corobot.  This entity is created facing in the +Z direction meaning
            /// that its front has positive Z coordinates.  Front and Rear IR sensors are included along with a front-facing camera.
            /// </summary>
            [DataContract]
            [DataMemberConstructor]
            public class CorobotEntity : VisualEntity
            {
              private static float InchesToMeters(float inches)
              {
                  return (float)(inches * 2.54 / 100.0);
              }
              static float mass = 3.63f; // kg
              static float chassisClearance = InchesToMeters(1.5f);
              static float wheelGap = InchesToMeters(3f / 8f);
              static float wheelWidth = InchesToMeters(2.2f);
              static float wheelDiameter = 0.10f; // 10 cm
              static float wheelMass = 0.1f; // kg
              static float platformClearance = InchesToMeters(5.75f);
    
              static Vector3 platformDimensions = new Vector3(
                InchesToMeters(11.0f),
                InchesToMeters(3.0f),
                InchesToMeters(8.5f));
              static Vector3 chassisDimensions = new Vector3(
                platformDimensions.X - 2 * wheelWidth - 2 * wheelGap,
                InchesToMeters(2.5f),
                platformDimensions.Z);
              static Vector3 wheelFRPosition = new Vector3(
                chassisDimensions.X / 2.0f + wheelGap + wheelWidth / 2.0f,
                wheelDiameter / 2.0f,
                -InchesToMeters(5.5f - 2f));
              static Vector3 wheelFLPosition = new Vector3(
                -wheelFRPosition.X,
                wheelFRPosition.Y,
                wheelFRPosition.Z);
              static Vector3 wheelRRPosition = new Vector3(
                wheelFRPosition.X,
                wheelFRPosition.Y,
                -wheelFRPosition.Z);
              static Vector3 wheelRLPosition = new Vector3(
                -wheelFRPosition.X,
                wheelFRPosition.Y,
                -wheelFRPosition.Z);
    
              // instance variables
              WheelEntity _wheelFR;
              WheelEntity _wheelFL;
              WheelEntity _wheelRR;
              WheelEntity _wheelRL;
    
              [Category("Wheels")]
              [DataMember]
              public WheelEntity FrontRightWheel
              {
                get { return _wheelFR; }
                set { _wheelFR = value; }
              }
    
              [Category("Wheels")]
              [DataMember]
              public WheelEntity FrontLeftWheel
              {
                get { return _wheelFL; }
                set { _wheelFL = value; }
              }
    
              [Category("Wheels")]
              [DataMember]
              public WheelEntity RearRightWheel
              {
                get { return _wheelRR; }
                set { _wheelRR = value; }
              }
    
              [Category("Wheels")]
              [DataMember]
              public WheelEntity RearLeftWheel
              {
                get { return _wheelRL; }
                set { _wheelRL = value; }
              }
    
            
    
              /// <summary>
              /// Default constructor used when this entity is deserialized
              /// </summar
              public CorobotEntity()
              {
              }
    
              /// <summary>
              /// Initialization constructor used when this entity is built programmatically
              /// </summary>
              /// <param name="initialPos"></param>
              public CorobotEntity(string name, Vector3 initialPos)
              {
                base.State.Name = name;
                base.State.Pose.Position = initialPos;
              }
            
              public override void Initialize(xnagrfx.GraphicsDevice device, PhysicsEngine physicsEngine)
              {
                  try
                  {
                      // chassis
                      BoxShapeProperties chassisDesc = new BoxShapeProperties(
                          "chassis",
                          mass / 2.0f,
                          new Pose(new Vector3(0, chassisClearance + chassisDimensions.Y / 2.0f, 0)),
                          chassisDimensions);
    
                      chassisDesc.Material = new MaterialProperties("chassisMaterial", 0.0f, 0.5f, 0.5f);
    
                      BoxShape chassis = new BoxShape(chassisDesc);
                      chassis.State.Name = "ChassisShape";
                      base.State.PhysicsPrimitives.Add(chassis);
    
                      // platform
                      BoxShapeProperties platformDesc = new BoxShapeProperties(
                          "platform",
                          mass / 2.0f,
                          new Pose(new Vector3(0, platformClearance + platformDimensions.Y / 2.0f, 0)),
                          platformDimensions);
                      platformDesc.Material = chassisDesc.Material;
                      BoxShape platform = new BoxShape(platformDesc);
                      platform.State.Name = "PlatformShape";
                      base.State.PhysicsPrimitives.Add(platform);
    
                      base.CreateAndInsertPhysicsEntity(physicsEngine);
                      base.PhysicsEntity.SolverIterationCount = 128;
    
                      // Wheels
                      WheelShapeProperties wheelFRprop = new WheelShapeProperties("FrontRightWheel", wheelMass, wheelDiameter / 2.0f);
                      WheelShapeProperties wheelFLprop = new WheelShapeProperties("FrontLeftWheel", wheelMass, wheelDiameter / 2.0f);
                      WheelShapeProperties wheelRRprop = new WheelShapeProperties("RearRightWheel", wheelMass, wheelDiameter / 2.0f);
                      WheelShapeProperties wheelRLprop = new WheelShapeProperties("RearLeftWheel", wheelMass, wheelDiameter / 2.0f);
    
                      wheelFRprop.Flags |= WheelShapeBehavior.OverrideAxleSpeed;
                      wheelFLprop.Flags |= WheelShapeBehavior.OverrideAxleSpeed;
                      wheelRRprop.Flags |= WheelShapeBehavior.OverrideAxleSpeed;
                      wheelRLprop.Flags |= WheelShapeBehavior.OverrideAxleSpeed;
    
                      wheelFRprop.InnerRadius = 0.7f * wheelDiameter / 2.0f;
                      wheelFLprop.InnerRadius = 0.7f * wheelDiameter / 2.0f;
                      wheelRRprop.InnerRadius = 0.7f * wheelDiameter / 2.0f;
                      wheelRLprop.InnerRadius = 0.7f * wheelDiameter / 2.0f;
    
                      wheelFRprop.LocalPose = new Pose(wheelFRPosition);
                      wheelFLprop.LocalPose = new Pose(wheelFLPosition);
                      wheelRRprop.LocalPose = new Pose(wheelRRPosition);
                      wheelRLprop.LocalPose = new Pose(wheelRLPosition);
    
                      _wheelFR = new WheelEntity(wheelFRprop);
                    _wheelFR.State.Name = base.State.Name + " FrontRightWheel";
                    _wheelFR.Parent = this;
                    _wheelFR.State.Assets.Mesh = "CorobotWheel.obj";
                    _wheelFR.MeshRotation = new Vector3(0, 180, 0);   // flip the wheel mesh
                    _wheelFR.Initialize(device, physicsEngine);
    
                    _wheelFL = new WheelEntity(wheelFLprop);
                    _wheelFL.State.Name = base.State.Name + " FrontLeftWheel";
                    _wheelFL.Parent = this;
                    _wheelFL.State.Assets.Mesh = "CorobotWheel.obj";
                    _wheelFL.Initialize(device, physicsEngine);
    
                    _wheelRR = new WheelEntity(wheelRRprop);
                    _wheelRR.State.Name = base.State.Name + " RearRightWheel";
                    _wheelRR.Parent = this;
                    _wheelRR.State.Assets.Mesh = "CorobotWheel.obj";
                    _wheelRR.MeshRotation = new Vector3(0, 180, 0);   // flip the wheel mesh
                    _wheelRR.Initialize(device, physicsEngine);
    
                    _wheelRL = new WheelEntity(wheelRLprop);
                    _wheelRL.State.Name = base.State.Name + " RearLeftWheel";
    
                    _wheelRL.Parent = this;
                    _wheelRL.State.Assets.Mesh = "CorobotWheel.obj";
                    _wheelRL.Initialize(device, physicsEngine);
    
    
    
                  }
                  catch
                  { 
                  }
    
              }
    
              // /// <summary>
              // /// Handles Subscribe messages
              // /// </summary>
             //  /// <param name="subscribe">the subscribe request</param>
              // [ServiceHandler]
             //  public void SubscribeHandler(Subscribe subscribe)
              // {
              //   SubscribeHelper(_submgrPort, subscribe.Body, subscribe.ResponsePort);
             //  }
           }
        }
    this is the code of the service.
    2012年5月4日 1:41
  • Hi guy,

      Here is a series of code samples coming from Codeplex which is talking about how to learn RDS.

      http://mrdssamples.codeplex.com/

      Hope it helps you.

      Sincerely,

      Jason Wang


    Jason Wang [MSFT]
    MSDN Community Support | Feedback to us

    2012年5月4日 7:34
    版主