none
maze simulator with irobot create

    Question

  •  

    Hi. i'm a newbie with MSRS. I practiced the simulation tutorials for now. I wanted to create a maze simulator with irobot create but i don't have idea where to start. Any link or help will be appreciated.
    Thursday, April 24, 2008 3:08 AM

Answers

  • I admit it -- I'm an MRDS junkie! I could not resist the challenge so I have added the iRobot Create to the Maze Simulator. When the code for "Professional Microsoft Robotics Developer Studio" is finally released it will include the simulated CoroBot too. However, you can't use the CoroBot with the old Maze Simulator.

     

    Here is what you need to do. As I said in my previous post, it is not trivial, but you should be able to follow the instructions fairly easily.

     

    Code Snippet

    1. Open the Maze Simulator in Visual Studio.

     

    2. Add a reference to SimulatedDifferentialDrive.Y2006.M06.Proxy.

    This is necessary because the built-in iRobotCreate entity is based on the built-in Simulated Differential Drive, not my modified version.

     

    3. Add a using statement near the top of MazeSimulator.cs:

    using MSDrive = Microsoft.Robotics.Services.Simulation.Drive.Proxy;

     

    4. Locate the AddRobot() method and add the following code just before the final else part of the if statement:

    else if (_state.RobotType.ToLower() == "irobot" || _state.RobotType.ToLower() == "create")

        AddCreate(position);

     

    Notice that I could not decide whether to call the robot an "irobot" or a "create", so I check for both of them.

     

    5. Add the new method AddCreate() as follows:

     

    // Make a new iRobot Create

    void AddCreate(Vector3 position)

    {

        IRobotCreate robotBaseEntity = new IRobotCreate(position);

        // Reverse the orientation of the robot so that it will

        // drive "forwards" from the user's perspective (it is

        // actually driving in the Z direction)

        robotBaseEntity.State.Pose.Orientation = Quaternion.FromAxisAngle(0, 1, 0, (float)(Math.PI));

        if (robotBaseEntity.Bumpers == null)

        {

            BoxShape[] _bumpers;

            string[] bumperName = new string[] { "L1", "L2", "L3", "B1", "B2", "R1", "R2", "R3" };

            // add some bumper shapes

            float start = (float)(-0.78 * Math.PI / 2.0f);

            float end = (float)(0.78 * Math.PI / 2.0f);

            int segments = 8; // 8 bumpers

            float increment = (end - start) / (segments - 1);

            int segment = 0;

            _bumpers = new BoxShape[segments];

            for (float angle = start; angle <= end; angle += increment, segment++)

            {

                BoxShape bumperBox = new BoxShape(

                    new BoxShapeProperties(

                    bumperName[segment], 0.001f, //mass

                    new Pose(new Vector3((float)(0.16 * Math.Sin(angle)), 0.055f, (float)(-0.16 * Math.Cos(angle))), // position

                    Quaternion.FromAxisAngle(0, 1, 0, angle)), // rotation

                    new Vector3(0.053f, 0.06f, 0.01f))); // dimensions

                bumperBox.BoxState.Material = new MaterialProperties("iRobotCreate chassis", 0.0f, 0.25f, 0.5f);

                bumperBox.Parent = robotBaseEntity;

                bumperBox.BoxState.EnableContactNotifications = true;

                if (bumperName[segment][0] == 'L')

                    bumperBox.State.DiffuseColor.X = 1.0f;

                else if (bumperName[segment][0] == 'R')

                    bumperBox.State.DiffuseColor.Y = 1.0f;

                else if (bumperName[segment][0] == 'B')

                {

                    bumperBox.State.DiffuseColor.X = 1.0f;

                    bumperBox.State.DiffuseColor.Y = 1.0f;

                }

                _bumpers[segment] = bumperBox;

            }

            robotBaseEntity.Bumpers = _bumpers;

        }

     

        BumperArrayEntity

            bumperArray = new BumperArrayEntity(robotBaseEntity.Bumpers);

        bumperArray.State.Name = "CreateBumpers";

        robotBaseEntity.InsertEntity(bumperArray);

     

        // Create Camera Entity and start SimulatedWebcam service

        CameraEntity camera = CreateCamera();

        // insert as child of motor base

        robotBaseEntity.InsertEntity(camera);

     

        SimulationEngine.GlobalInstancePort.Insert(robotBaseEntity);

     

        // Start simulated bumper service

        bumper.Contract.CreateService(

            ConstructorPort,

            Microsoft.Robotics.Simulation.Partners.CreateEntityPartner(

                "http://localhost/" + bumperArray.State.Name));

        // Add a Differential Drive service

        MSDrive.Contract.CreateService(ConstructorPort,

            Microsoft.Robotics.Simulation.Partners.CreateEntityPartner(

                "http://localhost/" + robotBaseEntity.State.Name));

        return;

    }

     

    6. Recompile. Hopefully I have not missed anything!

     

    7. Edit the MazeSimulator.config.xml and change the RobotType near the bottom of the file to be irobot or create.

     

    8. Run the new Maze Simulator. You should see a Create robot and be able to control it. It has a set of bumpers that you can also use and I have added a camera for your convenience.

     

    Enjoy!

     

     

    Note that I had to steal some code from the iRobotCreate entity for the bumpers. This is not a good approach. However, the iRobotCreate does not create the bumpers until it is initialized, and so I would have to listen for Insert messages from the Simulator and add them in later. I'm too lazy to do this at the moment and the approach above works because the author of the iRobotCreate entity was smart enough to check if the Bumpers already exist.

     

    Trevor

     

    Friday, April 25, 2008 12:35 PM
  • Up until V1.5 it was called Microsoft Robotics Studio (MSRS). With the release of the CTP of V2.0 the name has changed to Microsoft Robotics Developer Studio (MRDS or maybe MSRDS). They are really the same thing.

     

    As for the Maze Simulator, it is code that Ben Axelrod wrote originally, and then I took over the development and added some enhancements. It has been around since before V1.0. You can download a copy from here:

    http://www.soft-tech.com.au/MSRS/

     

    However, this is now quite old and I have worked on it since then as an example for a book on MRDS coming out in June. I also show how to use it to create a Line Following environment and provide a Maze Generator that creates random mazes for use with the Maze Simulator. Unfortunately, I can't release this code yet because it is tied to the publication of the book. Sorry about that.

     

    Trevor

     

    Monday, April 28, 2008 12:09 PM

All replies

  • Hi,

     

    The Maze Simulator only supports the LEGO NXT and the Pioneer 3DX at the moment. I guess I could add the Create, I just had not thought about it. Unfortunately, I can't commit to doing it right now.

     

    If you look in MazeSimulator.cs you will find a method called AddRobot(). You need to add a code to create a new iRobot Create entity. The code for the simulated Create is in samples\simulation\Entities\Entities.cs. The Sumo competition code uses the Create so you can find some code in there that shows you how to add a Create to a simulation. However, this is not a trivial task.

     

    Trevor

    Thursday, April 24, 2008 6:21 AM
  • I admit it -- I'm an MRDS junkie! I could not resist the challenge so I have added the iRobot Create to the Maze Simulator. When the code for "Professional Microsoft Robotics Developer Studio" is finally released it will include the simulated CoroBot too. However, you can't use the CoroBot with the old Maze Simulator.

     

    Here is what you need to do. As I said in my previous post, it is not trivial, but you should be able to follow the instructions fairly easily.

     

    Code Snippet

    1. Open the Maze Simulator in Visual Studio.

     

    2. Add a reference to SimulatedDifferentialDrive.Y2006.M06.Proxy.

    This is necessary because the built-in iRobotCreate entity is based on the built-in Simulated Differential Drive, not my modified version.

     

    3. Add a using statement near the top of MazeSimulator.cs:

    using MSDrive = Microsoft.Robotics.Services.Simulation.Drive.Proxy;

     

    4. Locate the AddRobot() method and add the following code just before the final else part of the if statement:

    else if (_state.RobotType.ToLower() == "irobot" || _state.RobotType.ToLower() == "create")

        AddCreate(position);

     

    Notice that I could not decide whether to call the robot an "irobot" or a "create", so I check for both of them.

     

    5. Add the new method AddCreate() as follows:

     

    // Make a new iRobot Create

    void AddCreate(Vector3 position)

    {

        IRobotCreate robotBaseEntity = new IRobotCreate(position);

        // Reverse the orientation of the robot so that it will

        // drive "forwards" from the user's perspective (it is

        // actually driving in the Z direction)

        robotBaseEntity.State.Pose.Orientation = Quaternion.FromAxisAngle(0, 1, 0, (float)(Math.PI));

        if (robotBaseEntity.Bumpers == null)

        {

            BoxShape[] _bumpers;

            string[] bumperName = new string[] { "L1", "L2", "L3", "B1", "B2", "R1", "R2", "R3" };

            // add some bumper shapes

            float start = (float)(-0.78 * Math.PI / 2.0f);

            float end = (float)(0.78 * Math.PI / 2.0f);

            int segments = 8; // 8 bumpers

            float increment = (end - start) / (segments - 1);

            int segment = 0;

            _bumpers = new BoxShape[segments];

            for (float angle = start; angle <= end; angle += increment, segment++)

            {

                BoxShape bumperBox = new BoxShape(

                    new BoxShapeProperties(

                    bumperName[segment], 0.001f, //mass

                    new Pose(new Vector3((float)(0.16 * Math.Sin(angle)), 0.055f, (float)(-0.16 * Math.Cos(angle))), // position

                    Quaternion.FromAxisAngle(0, 1, 0, angle)), // rotation

                    new Vector3(0.053f, 0.06f, 0.01f))); // dimensions

                bumperBox.BoxState.Material = new MaterialProperties("iRobotCreate chassis", 0.0f, 0.25f, 0.5f);

                bumperBox.Parent = robotBaseEntity;

                bumperBox.BoxState.EnableContactNotifications = true;

                if (bumperName[segment][0] == 'L')

                    bumperBox.State.DiffuseColor.X = 1.0f;

                else if (bumperName[segment][0] == 'R')

                    bumperBox.State.DiffuseColor.Y = 1.0f;

                else if (bumperName[segment][0] == 'B')

                {

                    bumperBox.State.DiffuseColor.X = 1.0f;

                    bumperBox.State.DiffuseColor.Y = 1.0f;

                }

                _bumpers[segment] = bumperBox;

            }

            robotBaseEntity.Bumpers = _bumpers;

        }

     

        BumperArrayEntity

            bumperArray = new BumperArrayEntity(robotBaseEntity.Bumpers);

        bumperArray.State.Name = "CreateBumpers";

        robotBaseEntity.InsertEntity(bumperArray);

     

        // Create Camera Entity and start SimulatedWebcam service

        CameraEntity camera = CreateCamera();

        // insert as child of motor base

        robotBaseEntity.InsertEntity(camera);

     

        SimulationEngine.GlobalInstancePort.Insert(robotBaseEntity);

     

        // Start simulated bumper service

        bumper.Contract.CreateService(

            ConstructorPort,

            Microsoft.Robotics.Simulation.Partners.CreateEntityPartner(

                "http://localhost/" + bumperArray.State.Name));

        // Add a Differential Drive service

        MSDrive.Contract.CreateService(ConstructorPort,

            Microsoft.Robotics.Simulation.Partners.CreateEntityPartner(

                "http://localhost/" + robotBaseEntity.State.Name));

        return;

    }

     

    6. Recompile. Hopefully I have not missed anything!

     

    7. Edit the MazeSimulator.config.xml and change the RobotType near the bottom of the file to be irobot or create.

     

    8. Run the new Maze Simulator. You should see a Create robot and be able to control it. It has a set of bumpers that you can also use and I have added a camera for your convenience.

     

    Enjoy!

     

     

    Note that I had to steal some code from the iRobotCreate entity for the bumpers. This is not a good approach. However, the iRobotCreate does not create the bumpers until it is initialized, and so I would have to listen for Insert messages from the Simulator and add them in later. I'm too lazy to do this at the moment and the approach above works because the author of the iRobotCreate entity was smart enough to check if the Bumpers already exist.

     

    Trevor

     

    Friday, April 25, 2008 12:35 PM
  • Hi,

    I'm getting an error:

    Error 1 The type 'Microsoft.Robotics.Services.Simulation.Drive.Proxy.Contract' exists in both 'c:\Microsoft Robotics Studio (1.5)\bin\SimulatedDifferentialDriveTT.2007.M06.Proxy.dll' and 'c:\Microsoft Robotics Studio (1.5)\bin\SimulatedDifferentialDrive.2006.M06.proxy.dll' C:\Microsoft Robotics Studio (1.5)\Apps\QUT\MazeSimulator\MazeSimulator.cs 1047 21 MazeSimulator

    I'm a newbie  so I'm prolly doing something wrong.

     

    It seems it is having a problem because it has both of these:

    using drive = Microsoft.Robotics.Services.Simulation.Drive.Proxy;

    using MSDrive = Microsoft.Robotics.Services.Simulation.Drive.Proxy;

     

    But I think they are supposed to be used by the 2 different dll's.

     

    Thanks

    Richard

     

    Saturday, April 26, 2008 6:01 AM
  • Sorry, that's the risk in trying to retrofit code. I have made changes to the my SimulatedDifferentialDriveTT and the namespace no longer conflicts. You can edit the DifferentialDriveTT code and change the namespace so that there is no conflict. Then you will have to change the using statement in the Maze Simulator to match the new namespace.

     

    This would be so much easier if I could release the code for our book, but it is not published yet :-(

     

    Trevor

     

    Sunday, April 27, 2008 10:52 AM
  • hi. sorry to sound stupid but is MSRS different from MRDS? i am using MSRS 1.5 but i cannot locate the maze simulator  folder. Is this part of the MSRS or i need to download from a site? thank you in advance.learning a lot from the post here.

    Monday, April 28, 2008 6:52 AM
  • Up until V1.5 it was called Microsoft Robotics Studio (MSRS). With the release of the CTP of V2.0 the name has changed to Microsoft Robotics Developer Studio (MRDS or maybe MSRDS). They are really the same thing.

     

    As for the Maze Simulator, it is code that Ben Axelrod wrote originally, and then I took over the development and added some enhancements. It has been around since before V1.0. You can download a copy from here:

    http://www.soft-tech.com.au/MSRS/

     

    However, this is now quite old and I have worked on it since then as an example for a book on MRDS coming out in June. I also show how to use it to create a Line Following environment and provide a Maze Generator that creates random mazes for use with the Maze Simulator. Unfortunately, I can't release this code yet because it is tied to the publication of the book. Sorry about that.

     

    Trevor

     

    Monday, April 28, 2008 12:09 PM
  • Hi just a question on adding more than one as follows:

    // the name below must match manifest
    robotBaseEntity.State.Name = "P3DXMotorBase1";

    // Start simulated arcos motor service drive.Contract.CreateService(ConstructorPort, Microsoft.Robotics.Simulation.Partners.CreateEntityPartner( "http://localhost/" + robotBaseEntity.State.Name) );
    ....
    ...
    ....
    ...
    // the name below must match manifest
    robotBaseEntity.State.Name = "P3DXMotorBase2";

    // Start simulated arcos motor service drive.Contract.CreateService(ConstructorPort, Microsoft.Robotics.Simulation.Partners.CreateEntityPartner( "http://localhost/" + robotBaseEntity.State.Name) );


    to run we would need to add the following lines to manfest...

    Start simulated motor service
            <ServiceRecordType>
                <dssp:Contract>http://schemas.microsoft.com/robotics/simulation/services/2006/05/simulateddifferentialdrive.html</dssp:Contract>
                <dsspStick out tongueartnerList>
                    <dsspStick out tongueartner>
                       
                        <dsspTongue Tiedervice>http://localhost/P3DXMotorBase1</dsspTongue Tiedervice>
                        <dssp:Name>P3DXMotorBase1</dssp:Name>
                    </dsspStick out tongueartner>
                </dsspStick out tongueartnerList>
                <Name>drive1</Name>
            </ServiceRecordType>

           
            <ServiceRecordType>
                <dssp:Contract>http://schemas.microsoft.com/robotics/simulation/services/2006/05/simulateddifferentialdrive.html</dssp:Contract>
                <dsspStick out tongueartnerList>
                    <dsspStick out tongueartner>
                       
                        <dsspTongue Tiedervice>http://localhost/P3DXMotorBase2</dsspTongue Tiedervice>
                        <dssp:Name>P3DXMotorBase2</dssp:Name>
                    </dsspStick out tongueartner>
                </dsspStick out tongueartnerList>
                <Name>drive2</Name>
            </ServiceRecordType>


    and if my service is using the simlated drives

    <ServiceRecordType>
                <dssp:Contract>http://schemas.tempuri.org/2008/07/agentmod.html</dssp:Contract>
                <dsspTongue Tiedervice>http://localhost/agent1</dsspTongue Tiedervice>
                <dsspStick out tongueartnerList>             
                    <dsspStick out tongueartner>
                        <dsspStick out tongueartner>
                            <!--The partner name must match the entity name-->
                            <dsspTongue Tiedervice>http://localhost/P3DXMotorBase1</dsspTongue Tiedervice>
                            <dssp:Name>P3DXMotorBase1</dssp:Name>
                        </dsspStick out tongueartner>
                    </dsspStick out tongueartner>
                </dsspStick out tongueartnerList>
            </ServiceRecordType>

    <ServiceRecordType>
                <dssp:Contract>http://schemas.tempuri.org/2008/07/agentmod.html</dssp:Contract>
                <dsspTongue Tiedervice>http://localhost/agent2</dsspTongue Tiedervice>
                <dsspStick out tongueartnerList>             
                    <dsspStick out tongueartner>
                        <dsspStick out tongueartner>
                            <!--The partner name must match the entity name-->
                            <dsspTongue Tiedervice>http://localhost/P3DXMotorBase2</dsspTongue Tiedervice>
                            <dssp:Name>P3DXMotorBase2</dssp:Name>
                        </dsspStick out tongueartner>
                    </dsspStick out tongueartner>
                </dsspStick out tongueartnerList>
            </ServiceRecordType>


    ....and then iam using another service which all agents subcribe to send a boradcast which will set the motors on for all robots..however only robot 1 runs ..what could be the wrong?

    and what is the use of having both <dsspTongue Tiedervice>http://localhost/P3DXMotorBase2</dsspTongue Tiedervice>
                            <dssp:Name>P3DXMotorBase2</dssp:Name> ??

    please help me to find an answer?


    Sunday, July 27, 2008 6:33 PM
  • Hi, can you post this question in a new thread? It's generally suggested to keep threads to the original question(s), and not revive month old threads with a new post (especially when they are already marked as answered as then people think the thread is already answered and don't read it).

     

    Thanks!

    Sunday, July 27, 2008 6:52 PM
  • thanks for the advie. done..plx can u have alook? Sad

     

    Monday, July 28, 2008 1:56 PM
  • Sorry, I have been out of the office. I can't seem to find the new thread.

     

    Anyway, the reason you specify a Service in the manifest is to give the service an instance URI. That makes it easier to locate. As for the Name, it should be something like simulation:Entityname where simulation is defined at the top of the manifest (in the Manifest tag) as an XML NameSpace:

     

     

    Have you seen this post?

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2031264&SiteID=1

     

    Trevor

     

     

    Thursday, July 31, 2008 3:15 AM
    Owner
  • I think the new thread is:

    http://forums.microsoft.com/Forums/ShowPost.aspx?PostID=3673696&SiteID=1

     

    I was waiting for the response with the error message.

    Thursday, July 31, 2008 3:49 PM
  •  

    thanks for the reply, tried it iam getting the same error. plz have a look in the link given above by Michael Wyrzykowski
    Thursday, July 31, 2008 7:23 PM