Compass in simulation RRS feed

  • Question

  • Hello,


    I'm working on an AI project using the Lego Mindstorm NXT. For this project I basically have to train a robot using the simulator, and then transfer the learning data on the real robot and see how it performs.


    Specifically, I'm trying get the simulated compass to work, but I don't seem to be able to. Specifically, on the simulator side of the code I have:

    using compass = Microsoft.Robotics.Services.Simulation.Sensors.Compass.Proxy;

    I add the compass to the robot:

          SimulatedCompassEntity compassEntity = CreateCompassSensor();
        private SimulatedCompassEntity CreateCompassSensor()
          SimulatedCompassEntity compassSensor = new SimulatedCompassEntity();
          compassSensor.State.Name = "CompassSensor";
          compassSensor.State.Pose.Position = new Vector3(0f, 0.12f, -0.085f);
          Quaternion level = Quaternion.FromAxisAngle(1, 0, 0, 0);
          compassSensor.State.Pose.Orientation = level;
            ConstructorPort, "http://localhost/" + compassSensor.State.Name,
             "http://localhost/" + compassSensor.State.Name)
          return compassSensor;

    On the robot side of the code, I have:

    using compassVirtual = Microsoft.Robotics.Services.Simulation.Sensors.Compass.Proxy;
          Contract = compassVirtual.Contract.Identifier,
          CreationPolicy = PartnerCreationPolicy.UseExisting,
          Optional = false)]
        compassVirtual.CombinedOperationsPort _compassSensorPort = new compassVirtual.CombinedOperationsPort();
        compassVirtual.CombinedOperationsPort _compassSensorNotify = new compassVirtual.CombinedOperationsPort(); 

    I think I know that there is something wrong with the partnership definition, as with the color sensor I'm currently using I have ColorSensorOperations available. Therefore I expected to have CompassSensorOperations too. This, however throws an error. 

    Basically, what I want to do is to set the simulated compass and read the angle from it. 



    Saturday, July 9, 2011 7:06 PM


  • The simulated compass implements the Analog Sensor contract. You should not use the CombinedOperationsPort.

    Please look at the Multiple Simulated Sensors sample under SimulationTutorials\Advanced. This demonstrates how to use all of the simulated sensors.

    BTW, the source code for the Simulated Compass is available in Simulation\Sensors\SimulatedCompass so you can see how it works.



    • Marked as answer by cevripidou Friday, July 29, 2011 3:36 PM
    Sunday, July 24, 2011 5:59 AM