locked
Multiple touch sensors (NXT) RRS feed

  • Question

  • Hello

    I'm having trouble receiving updates for both touch sensors. I have specified both sensors in my manifest and in my program (Using C# in MSRS 2008 R2) I have subscribed to TouchSensorOperations (using Microsoft.Robotics.Services.Sample.Lego.Nxt.TouchSensor.Proxy) but only the first touch sensor in the manifest ever fires events.

    When I launch my app, I check in the web utilty under "Home" that each of the "Lego NXT Touch Sensor v2" sensors work (I can refresh the page while I push the sensors and see them both update).  However, in the "Debug and Trace messages", only one of the sensor events ever fires (I can confirm this through breakpoints too).

    It's always the first touch sensor in the manifest that works.

    I found this previous post, but the only thing they suggest is checking manifests, but I have checked my using the VPL and Manifest editor and I think they are ok (hence I can use the web utility to check they work).
    http://social.msdn.microsoft.com/forums/en-US/roboticstroubleshooting/thread/1976f4b4-a0ac-4b98-9334-c7a3de0792ae/

    Does anyone have any ideas?

    Thanks!
    Saturday, February 20, 2010 4:37 PM

Answers

  • This is really a different topic. In future it might be better to start another thread and restate the question.

    Anyway, I used the Touch sensor because you know it is a LEGO NXT, and it is a little easier. You could also create a serivce that used two generic contact sensors. The idea of generic contracts is to make your code portable, but if you know you are only using a single type of robot and never plan to use a different one, they don't really gain you much. Generic contracts are usually implemented as alternate contracts on "native" services, i.e. there are two ways to access the device. Quite often the native service has more features because a generic contract has to be a sort of "lowest common denominator" so that it can work with a variety of different models of hardware.

    So to summarize, the "best practise" is to use generic contracts. But the practicalities are that the native contracts work just as well if you plan to stick to one type of hardware.

    Trevor

     

    Thursday, March 25, 2010 5:09 AM

All replies

  • Here is my code

    using bumper = Microsoft.Robotics.Services.Sample.Lego.Nxt.TouchSensor.Proxy;
    
    class ...
    
            [Partner("bumper", Contract = bumper.Contract.Identifier, Optional = false, CreationPolicy = PartnerCreationPolicy.UseExisting)];
            private bumper.TouchSensorOperations _bumperPort = new bumper.TouchSensorOperations();
    
            protected override void Start()
            {
                   base.Start();
    
                   bumper.TouchSensorOperations bumperNotifyPort = new bumper.TouchSensorOperations();
                   _bumperPort.Subscribe(bumperNotifyPort);
                   Activate(Arbiter.Receive<bumper.TouchSensorUpdate>(true, bumperNotifyPort, BumperHandler));
    
                   ...
    
            }
    
            private void BumperHandler(bumper.TouchSensorUpdate msg)
            {
                if (msg.Body.TouchSensorOn)
                {
                   if (msg.Body.Name == "Right")
                    {
                       LogInfo("Right Pressed");
                    }
                    else if (msg.Body.Name == "Left")
                    {
                       LogInfo("Left Pressed");
                    }
                }
            }
    
    
    
    • Edited by jelicon Saturday, February 27, 2010 12:00 PM
    Saturday, February 20, 2010 4:49 PM
  • You need to subscribe to each of the Touch Sensors separately because each one runs as a service. That's why you only see notifications from one of them.

    Trevor
    Monday, February 22, 2010 5:28 AM
  • Hi Trevor,

    Thanks for your reply.  I have actually tried adding a second one, but I ended up receiving two "Right" notifications, and no "Left". I think I was a bit stuck on where I specify which touch sensor I am subscribing to!  Could you highlight in my code where I am specifying which touch sensor to subscribe to, and therefore what I should change on my second subscription?

    Thanks again for your help!
    Monday, February 22, 2010 2:42 PM
  • If anyone can offer some advice, it would be greatfully received!  Is there anything in my manifest that I need to set up in order to subscribe to both touch sensors?

    I've included part of my manifest  below:

        <ServiceRecordType>
          <dssp:Contract>http://schemas.microsoft.com/robotics/2007/07/lego/nxt/touchsensor.html</dssp:Contract>
          <dssp:PartnerList>
            <dssp:Partner>
              <dssp:Contract>http://schemas.microsoft.com/robotics/2007/07/lego/nxt/touchsensor.html</dssp:Contract>
              <dssp:Service>LEGO.NXT.Proj.BumperR.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.html</dssp:Contract>
              <dssp:PartnerList />
              <dssp:Name>touchsensor:brick</dssp:Name>
              <dssp:ServiceName>this:LegoNXTBrickv2</dssp:ServiceName>
            </dssp:Partner>
          </dssp:PartnerList>
          <Name>this:LegoNXTTouchSensorv2-Right</Name>
        </ServiceRecordType>    
        
        <ServiceRecordType>
          <dssp:Contract>http://schemas.microsoft.com/robotics/2007/07/lego/nxt/touchsensor.html</dssp:Contract>
          <dssp:PartnerList>
            <dssp:Partner>
              <dssp:Contract>http://schemas.microsoft.com/robotics/2007/07/lego/nxt/touchsensor.html</dssp:Contract>
              <dssp:Service>LEGO.NXT.Proj.BumperL.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.html</dssp:Contract>
              <dssp:PartnerList />
              <dssp:Name>touchsensor:brick</dssp:Name>
              <dssp:ServiceName>this:LegoNXTBrickv2</dssp:ServiceName>
            </dssp:Partner>
          </dssp:PartnerList>
          <Name>this:LegoNXTTouchSensorv2-Left</Name>
        </ServiceRecordType>
    Saturday, February 27, 2010 11:57 AM
  • I agree this is a mess; there have been numerous questions aound the same issue.

    A definite example (including manifest, c# source code) using multiple touch sensors would really be appreciated
    Tuesday, March 2, 2010 1:47 PM
  • just out of curiosity, there is only 1 socket for touch sensor in the NXT brick, so how to connect the two sensors?
    Thursday, March 4, 2010 9:09 AM
  • Well... this is not correct. The NXT xomes with 4 sensors ports and is delivered with 2 touch sensors by default. Those can be connectect to any of the 4 ports as far as I know.

    Solution might be with the "contact sensors array" but I cannot get it to work either.
    Thursday, March 4, 2010 2:59 PM
  • I'm glad i'm not the only one!

    I've tried using the Microsoft.Robotics.Services.Sample.Lego.Nxt.ContactSensorArray.Proxy service as well, but still have the same issue.  It will only ever subscribe to the first touch sensor listed in the manifest.

    I've been through all of the robotics tutorials to see if there are any clues I can glean, but nothing seems to work - Gone through the forums too, but not much info there either!

    I agree that a sample on this would be helpful.
    Sunday, March 7, 2010 12:07 PM
  • i know there are 4 ports in the NX1T but each port is for a particular sensor. 1-touch, 2- sound, 3-light, 4 - ultrasonic. Can i just mixed it up? So going back to my original question, How to connect the two touch sensons when only 1 can be used at one time?
    Tuesday, March 9, 2010 12:53 AM
  • Sorry but you are wrong. The NXT has 4 sensor ports which can be used for any of the NXT provided sensors (or compatible sensors). Again the best proof that this is a real issue is that the standard NXT package contains 2 touch sensors. If you do not have an NXT just look at the box picture anywhere on the web you will see. How would you connect them ? and, more relevant to this forum, how can we control them through a c# program?
    Tuesday, March 9, 2010 7:53 AM
  • Yes, you can attach touch sensors to all of the 4 ports if you wish.

    What you need to do in the manifest is specify two touch sensor services and for each of them specify a config file. In the config files you can specify the sensor ports that are used by each of them on the brick.

    Another alternative if you need a lot of touch sensors is to buy the Touch Mux from HiTechnic. I have written a service for the Touch Mux that you can get from here:
    http://mrdshitechnic.codeplex.com

    Note that I do not work for HiTechnic, or get anything from them.

    Trevor
    Tuesday, March 9, 2010 10:37 AM
  • Thank you Trevor for this input. Before buying additional stuff I'd like to have the basic things working which is still not true for me.

    I did what you say in the config/manifests. The issue lies within the csharp code. If I use "creation policy" "UseExisting" both Partners return the first dumper and I find no examples of using "USePartnerListEntry" (if this is the solution)

    Pierre
    Wednesday, March 10, 2010 1:20 PM
  • I'll see if I can write an example over the weekend.

    Trevor

     

    Saturday, March 20, 2010 3:59 AM
  • I have created a sample C# program that simply writes out messages to the console when two touch sensors are pressed. They have to be attached to Sensor ports 1 and 2. The code is available here:

    http://www.promrds.com/downloads/touchx2.zip

    To use it you need to do the following:

    • Download the ZIP file.
    • Unzip somewhere under your RDS installation.
    • Open a DSS Command Prompt and run DssProjectMigration on the folder you just created to fix up the file paths.
    • Edit the LegoNXTBrickv2.Config.xml and set the correct SerialPort for your LEGO NXT.
    • Open the solution in Visual Studio (2008 or 2010) and rebuild it.
    • Run it in the debugger.
    • Press the touch sensors on ports 1 and 2 and you should see messages in the console window.

    The key points are that the C# service (touchx2) uses the UsePartnerListEntry policy on two partners called TouchSensor1 and TouchSensor2. In the manifest, you will see that the touchx2 service is partnered with two touch sensors with Name TouchSensor1 and TouchSensor2. The code below shows the first partner.

        <ServiceRecordType>
          <dssp:Contract>http://schemas.microsoft.com/robotics/2010/03/touchx2.html</dssp:Contract>
         <dssp:PartnerList>
         <dssp:Partner>
          <dssp:Contract>http://schemas.microsoft.com/robotics/2007/07/lego/nxt/touchsensor.html</dssp:Contract>
          <dssp:PartnerList />
          <dssp:Name>touchx2:TouchSensor1</dssp:Name>
          <dssp:ServiceName>this:TouchSensorxxx1</dssp:ServiceName>
         </dssp:Partner>
    ...

    Also note that the ServiceName is TouchSensorxxx1 in this case. I added the xxx just to make it clear that this name is used further down in the manifest. It could have just been TouchSensor1 as well, but I wanted to make the association clearly visible. So there is a service record for the Touch Sensor:

       <ServiceRecordType>
        <dssp:Contract>http://schemas.microsoft.com/robotics/2007/07/lego/nxt/touchsensor.html</dssp:Contract>
        <dssp:PartnerList>
         <dssp:Partner>
          <dssp:Contract>http://schemas.microsoft.com/robotics/2007/07/lego/nxt/touchsensor.html</dssp:Contract>
          <dssp:Service>touchsensor1.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.html</dssp:Contract>
          <dssp:PartnerList />
          <dssp:Name>touchsensor:brick</dssp:Name>
          <dssp:ServiceName>this:LegoNXTBrickv2</dssp:ServiceName>
         </dssp:Partner>
        </dssp:PartnerList>
        <Name>this:TouchSensorxxx1</Name>
       </ServiceRecordType>

    Notice that the Touch Sensor has to be partnered with the Brick as well. You can set most of this up using the DSS Manifest Editor.

    In the C# code the partner entry looks like:

        // Partner: TouchSensor1, Contract: http://schemas.microsoft.com/robotics/2007/07/lego/nxt/touchsensor.html
        [Partner("TouchSensor1", Contract = touch.Contract.Identifier, CreationPolicy = PartnerCreationPolicy.UsePartnerListEntry)]
        touch.TouchSensorOperations _TouchSensor1Port = new touch.TouchSensorOperations();
        touch.TouchSensorOperations _TouchSensor1Notify = new touch.TouchSensorOperations();
    

    You can extend process this to all four sensor ports if you have four touch sensors. (I don't!)

    Trevor

     

     

    Tuesday, March 23, 2010 4:45 AM
  • Thank you very much for this clear and detailed explanation! this helps a lot.

    something is still somewhat confusing for me: in which case are we supposed to use NXT specific definitions (in this example you use

    Microsoft.Robotics.Services.Sample.Lego.Nxt.TouchSensor.Proxy instead of the generic ContactSensor) instead of the generic ones? (in an other thread you mentionned that Tutorial 6 was outdated)

    where can we find out about the differences? for instance is it better to use the generic motors/encoders or, if we have an NXT and associated motors, should we use the specific motor defined in Sample.Lego.Nxt?

    many thanks

    Pierre

    Tuesday, March 23, 2010 1:54 PM
  • This is really a different topic. In future it might be better to start another thread and restate the question.

    Anyway, I used the Touch sensor because you know it is a LEGO NXT, and it is a little easier. You could also create a serivce that used two generic contact sensors. The idea of generic contracts is to make your code portable, but if you know you are only using a single type of robot and never plan to use a different one, they don't really gain you much. Generic contracts are usually implemented as alternate contracts on "native" services, i.e. there are two ways to access the device. Quite often the native service has more features because a generic contract has to be a sort of "lowest common denominator" so that it can work with a variety of different models of hardware.

    So to summarize, the "best practise" is to use generic contracts. But the practicalities are that the native contracts work just as well if you plan to stick to one type of hardware.

    Trevor

     

    Thursday, March 25, 2010 5:09 AM
  • Now I am facing a follow up problem. To make things interesting I need additional devices on my NXT (for instance 2 motors: when pressing sensor 1 I want to start Motor A and when pressing sensor 2 I start motor B). I can do that easily in VPL. In Csharp I am back with the same issue: if I try to add the motors in the partners list of service touchx2 it complains (if I do not add them it complains also)

      Partner enumeration during service startup failed. Partner Name:http://schemas.microsoft.com/robotics/2006/06/touchx2.user.html:TouchSensor1 Partner Contract: Partners specified statically in service implementation class: PartnerAttribute Name:TouchSensor1,Contract:http://schemas.microsoft.com/robotics/2007/07/lego/nxt/touchsensor.html,CreationPolicy:UsePartnerListEntry PartnerAttribute Name:TouchSensor2,Contract:http://schemas.microsoft.com/robotics/2007/07/lego/nxt/touchsensor.html,CreationPolicy:UsePartnerListEntry PartnerAttribute Name:motor1,Contract:http://schemas.microsoft.com/robotics/2007/07/lego/nxt/motor.html,CreationPolicy:UsePartnerListEntry PartnerAttribute Name:motor2,Contract:http://schemas.microsoft.com/robotics/2007/07/lego/nxt/motor.html,CreationPolicy:UsePartnerListEntry Partners specified at runtime, in CreateRequest: Name: http://schemas.microsoft.com/robotics/2006/06/touchx2.html:TouchSensor1, Contract: http://schemas.microsoft.com/robotics/2007/07/lego/nxt/touchsensor.user.html, Service: Name: http://schemas.microsoft.com/robotics/2006/06/touchx2.html:TouchSensor2, Contract: http://schemas.microsoft.com/robotics/2007/07/lego/nxt/touchsensor.user.html, Service: Name: http://schemas.microsoft.com/robotics/2006/06/touchx2.html:motor1, Contract: http://schemas.microsoft.com/robotics/2007/07/lego/nxt/motor.user.html, Service: Name: http://schemas.microsoft.com/robotics/2006/06/touchx2.html:motor2, Contract: http://schemas.microsoft.com/robotics/2007/07/lego/nxt/motor.user.html, Service: Name: http://schemas.microsoft.com/xw/2004/10/dssp.html:ConstructorService, Contract: http://schemas.microsoft.com/xw/2004/10/constructor.html, Service: dssp.tcp://your-2f73f42422:50001/constructor Name: http://schemas.microsoft.com/xw/2004/10/dssp.html:PartnerListService, Contract: http://schemas.microsoft.com/xw/2004/10/partnerlist.html, Service: dssp.tcp://your-2f73f42422:50001/touchx2/914db2fc-7e57-4126-a7a6-dd5990697168/dss/partnermanager
    3 15:17:16 *** Service failed second phase of Start. Calling Shutdown
    4 15:17:16 *** Service failed second phase of Start. Calling Shutdown

    Tuesday, March 30, 2010 1:21 PM
  • It would be best to move this to a new thread. Please open a new question.

    The pattern for two motors is the same as for two touch sensors, or two of anything for that matter. Have you tried using DSSME?

    Trevor

    Tuesday, March 30, 2010 6:24 PM
  • I tried edititing that with DSSME and failed. I also bought the recommended book. It just made things more confusing for me. The inconsistancies between version 1.5 and 2 are also making it difficult to follow; for the same reason the previous answers in this forum are often difficult to use (and should be removed or a separate forum should have been created).

    All in all I just gave up and am using less sophisticated but understandable/stable software (NXC). Having worked 15 years for MS this is painful but seemed the only way forward.;-(

    Tuesday, April 13, 2010 3:39 PM
  • There seems to be a mix of ".user" services and Microsoft services in the error messages that you posted. Maybe things got mixed up along the way. The source code for the services that ship with RDS are ".user" versions so if you recompile they won't overwrite the Microsoft DLLs. This sometimes creates confusion, especially when editing manifests by hand. However, DSSME should create consistent manifests.

    Anyway, I'm sorry to hear that you have given up on RDS. Good luck wtih NXC.

    Trevor

     

    Wednesday, April 14, 2010 5:35 AM