none
BEGINNER: NXT 2.0 / C# / Robotics Tutorial 3 (C#) - Creating Reusable Orchestration Services / Problem with 2 Bumpers RRS feed

  • Question

  • Hi Guys,

    I'm new to robotics development. I've bought the LEGO MINDSTORMS NXT 2.0 and started with the Tutorials in the offical Robotics Development Studio Documentation. Now I have problems with this tutorial:  "Robotics Tutorial 3 (C#) - Creating Reusable Orchestration Services". This tutorial seems to be designed for the old revision of the NXT, because it is always talking about the tribot. Due to my research i found out that the tribot uses just one touchsensor. But the code seems to be designed for two touchsensors. So I've connected to touchsensors to the brick and modified the manifest file. Although just the first sensor seems to be working. I hope somebody can tell me whats wrong. When i press the front sensor the programm works as expected, but when i press the back sensor nothing happens.

    I used the code from this site: http://msdn.microsoft.com/en-us/library/bb483052.aspx with some modifications.

    The modified manifest file and code can be found at the bottom of this thread. I created it with the Microsoft Manifest-Editor.

    THANKS!

    Cheers,

    Mike

     

    Here ist the "LEGO.NXT.TriBot.user.manifest.xml" file.

    <?xml version="1.0"?>
    <!--This file was created with the Microsoft Visual Programming Language.-->
    <Manifest xmlns:dssp="http://schemas.microsoft.com/xw/2004/10/dssp.html" xmlns:this="urn:uuid:4d67ae18-316a-410a-b2b2-50f9c01ce674" xmlns:user="http://schemas.microsoft.com/robotics/2007/07/lego/nxt/brick.user.html" xmlns="http://schemas.microsoft.com/xw/2004/10/manifest.html">
     <CreateServiceList>
      <ServiceRecordType>
       <dssp:Contract>http://schemas.microsoft.com/robotics/2007/07/lego/nxt/brick.user.html</dssp:Contract>
       <dssp:PartnerList>
        <dssp:Partner>
         <dssp:Contract>http://schemas.microsoft.com/robotics/2007/07/lego/nxt/brick.user.html</dssp:Contract>
         <dssp:Service>lego.nxt.brick.user.config.xml</dssp:Service>
         <dssp:PartnerList />
         <dssp:Name>dssp:StateService</dssp:Name>
        </dssp:Partner>
       </dssp:PartnerList>
       <Name>this:LegoNXTBrickv2</Name>
      </ServiceRecordType>
      <ServiceRecordType>
       <dssp:Contract>http://schemas.microsoft.com/robotics/2007/07/lego/nxt/drive.user.html</dssp:Contract>
       <dssp:PartnerList>
        <dssp:Partner>
         <dssp:Contract>http://schemas.microsoft.com/robotics/2007/07/lego/nxt/drive.user.html</dssp:Contract>
         <dssp:Service>lego.nxt.tribot.drive.user.config.xml</dssp:Service>
         <dssp:PartnerList />
         <dssp:Name>dssp:StateService</dssp:Name>
        </dssp:Partner>
        <dssp:Partner>
         <dssp:Contract>http://schemas.microsoft.com/robotics/2007/07/lego/nxt/brick.user.html</dssp:Contract>
         <dssp:PartnerList />
         <dssp:Name xmlns:q1="http://schemas.microsoft.com/robotics/2007/07/lego/nxt/drive.user.html">q1:brick</dssp:Name>
         <dssp:ServiceName>this:LegoNXTBrickv2</dssp:ServiceName>
        </dssp:Partner>
       </dssp:PartnerList>
       <Name>this:LegoNXTDrivev2</Name>
      </ServiceRecordType>
      <ServiceRecordType>
       <dssp:Contract>http://schemas.microsoft.com/robotics/2007/07/lego/nxt/touchsensor.user.html</dssp:Contract>
       <dssp:PartnerList>
        <dssp:Partner>
         <dssp:Contract>http://schemas.microsoft.com/robotics/2007/07/lego/nxt/touchsensor.user.html</dssp:Contract>
         <dssp:Service>lego.nxt.tribot.bumper.user.config.xml</dssp:Service>
         <dssp:PartnerList />
         <dssp:Name>dssp:StateService</dssp:Name>
        </dssp:Partner>
        <dssp:Partner>
         <dssp:Contract>http://schemas.microsoft.com/robotics/2007/07/lego/nxt/brick.user.html</dssp:Contract>
         <dssp:PartnerList />
         <dssp:Name xmlns:q2="http://schemas.microsoft.com/robotics/2007/07/lego/nxt/touchsensor.user.html">q2:brick</dssp:Name>
         <dssp:ServiceName>this:LegoNXTBrickv2</dssp:ServiceName>
        </dssp:Partner>
       </dssp:PartnerList>
       <Name>this:LegoNXTTouchSensor_front</Name>
      </ServiceRecordType>
      <ServiceRecordType>
       <dssp:Contract>http://schemas.microsoft.com/robotics/2007/07/lego/nxt/touchsensor.user.html</dssp:Contract>
       <dssp:PartnerList>
        <dssp:Partner>
         <dssp:Contract>http://schemas.microsoft.com/robotics/2007/07/lego/nxt/touchsensor.user.html</dssp:Contract>
         <dssp:Service>lego.nxt.tribot.bumper2.user.config.xml</dssp:Service>
         <dssp:PartnerList />
         <dssp:Name>dssp:StateService</dssp:Name>
        </dssp:Partner>
        <dssp:Partner>
         <dssp:Contract>http://schemas.microsoft.com/robotics/2007/07/lego/nxt/brick.user.html</dssp:Contract>
         <dssp:PartnerList />
         <dssp:Name xmlns:q3="http://schemas.microsoft.com/robotics/2007/07/lego/nxt/touchsensor.user.html">q3:brick</dssp:Name>
         <dssp:ServiceName>this:LegoNXTBrickv2</dssp:ServiceName>
        </dssp:Partner>
       </dssp:PartnerList>
       <Name>this:LegoNXTTouchSensor_back</Name>
      </ServiceRecordType>
     </CreateServiceList>
    </Manifest>
    


    "LEGO.NXT.TriBot.Bumper.user.config.xml"

    <?xml version="1.0" encoding="utf-8"?>
    <TouchSensorState xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/robotics/2007/07/lego/nxt/touchsensor.user.html">
    	<Name>front</Name>
    	<SensorPort>Sensor1</SensorPort>
    	<PollingFrequencyMs>0</PollingFrequencyMs>
    </TouchSensorState>
    

     

    "LEGO.NXT.TriBot.Bumper2.user.config.xml"

    <?xml version="1.0" encoding="utf-8"?>
    <TouchSensorState xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/robotics/2007/07/lego/nxt/touchsensor.user.html">
    	<Name>back</Name>
    	<SensorPort>Sensor2</SensorPort>
    	<PollingFrequencyMs>0</PollingFrequencyMs>
    </TouchSensorState>
    


    CODE

    #region CODECLIP 01-2
        [Partner("Bumper",
          Contract = contactsensor.Contract.Identifier,
          CreationPolicy = PartnerCreationPolicy.UseExisting)]
        contactsensor.ContactSensorArrayOperations _contactSensorPort = new contactsensor.ContactSensorArrayOperations();
    
        [Partner("Drive",
          Contract = drive.Contract.Identifier,
          CreationPolicy = PartnerCreationPolicy.UseExisting)]
        drive.DriveOperations _drivePort = new drive.DriveOperations();
        #endregion
    
        #region CODECLIP 02-1
        // target port for bumper notifications
        contactsensor.ContactSensorArrayOperations _contactNotificationPort = new contactsensor.ContactSensorArrayOperations();
        #endregion
    
        [ServicePort("/RoboticsTutorial3", AllowMultipleInstances=false)]
        private RoboticsTutorial3Operations _mainPort = new RoboticsTutorial3Operations();
    
        public RoboticsTutorial3Service(DsspServiceCreationPort creationPort) :
            base(creationPort)
        {
        }
    
        #region CODECLIP 02-2
        /// <summary>
        /// Service Start
        /// </summary>
        protected override void Start()
        {
          // Listen on the main port for requests and call the appropriate handler.
          // Publish the service to the local Node Directory
          base.Start();
    
          SubscribeToBumperSensors();
        }
    
        /// <summary>
        /// Subscribe to sensors and send notifications
        /// to BumperNotificationHandler
        /// </summary>
        void SubscribeToBumperSensors()
        {
          _contactSensorPort.Subscribe(_contactNotificationPort);
    
          // Attach handler to update notification on bumpers
          Activate(Arbiter.Receive<contactsensor.Update>(true, _contactNotificationPort, BumperNotificationHandler));
        }
        #endregion
    
        #region CODECLIP 02-3
        /// <summary>
        /// Handler for Contact Sensor Notifications
        /// </summary>
        /// <param name="updateNotification"></param>
        void BumperNotificationHandler(contactsensor.Update updateNotification)
        {
          // Since we are writing a generic wander service we dont really know
          // which bumper is front, side, rear etc. We expect a navigation service to be tuned
          // to a robot platform or read configuration through its initial state.
          // here, we just assume the bumpers are named intuitively so we search by name
    
          contactsensor.ContactSensor s = updateNotification.Body;
          if (!s.Pressed)
            return;
    
          LogInfo(LogGroups.Console, "Sensor pressed: " + s.Name);
    
          if (!string.IsNullOrEmpty(s.Name) &&
            s.Name.ToLowerInvariant().Contains("front"))
          {
            SpawnIterator<double>(-1,BackUpTurnAndMove);
            return;
          }
    
          if (!string.IsNullOrEmpty(s.Name) &&
            s.Name.ToLowerInvariant().Contains("back"))
          {
            SpawnIterator<double>(1,BackUpTurnAndMove);
            return;
          }
        }
        #endregion
    


    Wednesday, July 13, 2011 8:08 AM

Answers

  • I've only had a quick look at this, but here are a couple of comments.

    The ContactSensorArray needs a list of sensors. I don't see a config file for that.

    Can you see the touch sensor services if you open a web browser and look at the Service Directory? If so, you should be able to verify that the touch sensors are working via the web browser and pressing the buttons / refreshing the page. Assuming that there are two services and they are both working, the is it just the config that needs to be fixed.

    Did you look at your manifest using the DSS Manifest Editor? This might be clearer than looking at the XML.

    Trevor

     

    Wednesday, July 13, 2011 8:15 PM