none
Reading data of a Simulated Laser Range Finder RRS feed

  • Question

  • Dear all,

    I am struggling with using a simulated LRF in my simulation to detect obstacles and compute distance measurements.I have followed almost all the post on this forum related to SimulatedLRF queries however, I am still confused in especially reading/accessing the sensor data.

     

    Following is my code related to SimulatedLRF:

     

     Port<RaycastResult> _rayCastPort = new Port<RaycastResult>();
               
                LaserRangeFinderEntity laser = new LaserRangeFinderEntity(
                new Pose(new Vector3(0, 0.1f, -0.2f)));
                laser.State.Name = "RobotLaserRangeFinder";
                laser.LaserBox.State.DiffuseColor = new Vector4(0.25f, 0.25f, 0.8f, 1.0f);
                laser.LaserBox.State.Dimensions.X = 0.02f;
                laser.LaserBox.State.Dimensions.Y = 0.02f;
                laser.LaserBox.State.Dimensions.Z = 0.02f;
                laser.State.Pose.Orientation = UIMath.EulerToQuaternion(new xna.Vector3(-30f, 180f, 0f));

                CreateService(
                    lrf.Proxy.Contract.Identifier,
                    Microsoft.Robotics.Simulation.Partners.CreateEntityPartner(
                    "http://localhost/" + laser.State.Name));

                retValue.InsertEntity(laser);


                laser.Register(_rayCastPort);
                RaycastResult verticalResults;
               
                _rayCastPort.Test(out verticalResults);
                if (verticalResults != null)
                {
                    foreach (RaycastImpactPoint impact in verticalResults.ImpactPoints)
                    {

                        System.Console.WriteLine(impact.Position.X);
                    }
                }

     

    Ok, with the above code, I can see my SimulatedLRF tilted at 30 degrees in visual simulation environment(physics/combine mode) and the red dots appearing at the obstacles in front of the robot however, I have no idea how to read the sensor data. I found the code snippet (as shown above in bold) to read the sensor data however, I dont know where to put this code snippet (the lines in bold) to pull out the sensor data, whether in the public override void Update(FrameUpdate update) or anywhere else.

     

    You guys are expert in communicating with the sensors so it is requested to please assist me in this regard. Please provide some alternate code snippets to read LRF measurements if available.

     

    I appreciate your kind assistance,

    Thanks,

    Best regards,

    Umar


    • Edited by hexapod Monday, January 23, 2012 8:26 AM
    Saturday, January 21, 2012 1:30 PM

Answers

  • I'm not sure why you are using the CombinedOperationsPort. I would have expected something like:

    sicklrf.

    SickLRFOperations _laserPort = new sicklrf.SickLRFOperations();

    Try this code to do a Get. The returned value, s, is the state from the LRF.

     

    int[] dist;

     

    yield return _laserPort.Get().Choice(

        s => { dist = s.DistanceMeasurements; },

        f => LogError(f)

    );

    

    Trevor

    

    Friday, January 27, 2012 2:37 AM

All replies

  • Your code creates a LRF service called RobotLaserRangeFinder. You can write another service and partner with this LRF service and simply do a Get to retrieve the state of the service. The state contains an integer array called DistanceMeasurements. Alternatively, you can subscribe to the service and you will be sent notifications every time that new data is available.

    You do not need the bolded code. If you see the red dots appearing periodically then the simulated LRF is working.

    Trevor

     

    Monday, January 23, 2012 1:49 AM
  • Dear Trevor,

    Many thanks for your prompt response. I appreciate that.

     

    In order to partner with the LRF service service I include the following code:

     

            [Partner("Laser", Contract = lrf.Proxy.Contract.Identifier, CreationPolicy = PartnerCreationPolicy.UseExisting)]
            lrf.Proxy.CombinedOperationsPort _laserPort = new lrf.Proxy.CombinedOperationsPort ();
            lrf.Proxy.CombinedOperationsPort  _laserNotify = new lrf.Proxy.CombinedOperationsPort();

     

    Then, you mentioned: "simply do a Get to retrieve the state of the service." Can you please drop-in some sample code in order to achieve that?

     

    Thanks,

    Umar

    Monday, January 23, 2012 8:22 AM
  • Dear All,

    Any sample code to get the laser range finder data?

     

    Thanks,

    umar

    Wednesday, January 25, 2012 4:13 AM
  • I'm not sure why you are using the CombinedOperationsPort. I would have expected something like:

    sicklrf.

    SickLRFOperations _laserPort = new sicklrf.SickLRFOperations();

    Try this code to do a Get. The returned value, s, is the state from the LRF.

     

    int[] dist;

     

    yield return _laserPort.Get().Choice(

        s => { dist = s.DistanceMeasurements; },

        f => LogError(f)

    );

    

    Trevor

    

    Friday, January 27, 2012 2:37 AM