locked
Robotics Tutorial 2 (C#) - How do I make it work? RRS feed

  • Question

  • Problem:

    Programming against my MobileRobotics P3-DX, Robotics Tutorial 2 (C#) fails to call the "BumperHandler" method when the bumpers are pressed after the "_motorPort" variable is declared.  NOTE:  When the "_motorPort" declaration and the "_motorPort.SetMotorPower( motorRequest )" call are removed, bumper notifications go back to normal (i.e. the BumperHandler method is once again called when bumpers are pressed).

    Question:

    Is there any way get Robotics Tutorial 2 to work on a P3-DX?

    Thanks In Advance,
    Joshua Burkholder

    BTW:  Here's my command line arguments:

    /port:50000 /tcpport:50001 /manifest:"samples\MyTutorial2\MyTutorial2.manifest.xml" /manifest:"samples\Config\MobileRobots.P3DX.manifest.xml"

    Here's my code for Robotics Tutorial 2 (NOTE:  If I compile these as they are, then nothing works; however, if I uncomment the "//#undef MOTOR_CODE_ENABLED" directive [i.e. disable the _motorPort code], then bumper notifications resume):

    MyTutorial2.cs:

    1 #define MOTOR_CODE_ENABLED  
    2 //#undef MOTOR_CODE_ENABLED  
    3  
    4 using System;  
    5 using System.Collections.Generic;  
    6 using System.ComponentModel;  
    7 using Microsoft.Ccr.Core;  
    8 using Microsoft.Dss.Core.Attributes;  
    9 using Microsoft.Dss.ServiceModel.Dssp;  
    10 using Microsoft.Dss.ServiceModel.DsspServiceBase;  
    11 using W3C.Soap;  
    12  
    13 //BURKIE:  
    14 using Microsoft.Dss.Core;//LogGroups  
    15 using bumper = Microsoft.Robotics.Services.ContactSensor.Proxy;  
    16 using motor = Microsoft.Robotics.Services.Motor.Proxy;  
    17  
    18 namespace MyTutorial2  
    19 {  
    20     [Contract(Contract.Identifier)]  
    21     [DisplayName("MyTutorial2")]  
    22     [Description("MyTutorial2 service (no description provided)")]  
    23     class MyTutorial2Service : DsspServiceBase  
    24     {  
    25         [ServiceState]  
    26         MyTutorial2State _state = new MyTutorial2State();  
    27           
    28         [ServicePort("/MyTutorial2", AllowMultipleInstances = true)]  
    29         MyTutorial2Operations _mainPort = new MyTutorial2Operations();  
    30  
    31         //BURKIE:  
    32         [Partner( "bumper", Contract = bumper.Contract.Identifier, CreationPolicy = PartnerCreationPolicy.UseExisting )]  
    33         private bumper.ContactSensorArrayOperations _bumperPort = new bumper.ContactSensorArrayOperations();  
    34  
    35         //BURKIE:  
    36 #if MOTOR_CODE_ENABLED  
    37         [Partner( "motor", Contract = motor.Contract.Identifier, CreationPolicy = PartnerCreationPolicy.UseExisting )]  
    38         private motor.MotorOperations _motorPort = new motor.MotorOperations();
    39 #endif  
    40  
    41         public MyTutorial2Service(DsspServiceCreationPort creationPort)  
    42             : base(creationPort)  
    43         {  
    44         }  
    45           
    46         protected override void Start()  
    47         {  
    48               
    49             //   
    50             // Add service specific initialization here  
    51             //   
    52  
    53             base.Start();  
    54  
    55             //BURKIE:  
    56             this.SubscribeToBumpers();  
    57         }  
    58  
    59         //BURKIE:  
    60         void SubscribeToBumpers () {  
    61             bumper.ContactSensorArrayOperations bumperNotificationPort = new bumper.ContactSensorArrayOperations();  
    62             _bumperPort.Subscribe( bumperNotificationPort );  
    63             Activate( Arbiter.Receive<bumper.Update>( true, bumperNotificationPort, this.BumperHandler ) );  
    64         }  
    65           
    66         //BURKIE:  
    67         private void BumperHandler ( bumper.Update notification ) {  
    68  
    69             string message;  
    70  
    71             if ( !notification.Body.Pressed ) {  
    72                 return;  
    73             }  
    74  
    75             _state.MotorOn = !_state.MotorOn;  
    76  
    77             motor.SetMotorPowerRequest motorRequest = new motor.SetMotorPowerRequest();  
    78  
    79             if ( _state.MotorOn ) {  
    80  
    81                 motorRequest.TargetPower = 1.0;  
    82                 message = "Motor On";  
    83  
    84             } else {  
    85  
    86                 motorRequest.TargetPower = 0.0;  
    87                 message = "Motor Off";  
    88  
    89             }
    90
    91 #if MOTOR_CODE_ENABLED  
    92             _motorPort.SetMotorPower( motorRequest );
    93 #endif  
    94  
    95             LogInfo( LogGroups.Console, message );  
    96         }  
    97  
    98     }  
    99 }  
    100  

    MyTutorial2Types.cs:

    1 using System;  
    2 using System.Collections.Generic;  
    3 using System.ComponentModel;  
    4 using Microsoft.Ccr.Core;  
    5 using Microsoft.Dss.Core.Attributes;  
    6 using Microsoft.Dss.ServiceModel.Dssp;  
    7 using Microsoft.Dss.ServiceModel.DsspServiceBase;  
    8 using W3C.Soap;  
    9  
    10 namespace MyTutorial2  
    11 {  
    12     public sealed class Contract  
    13     {  
    14         [DataMember]  
    15         public const string Identifier = "http://schemas.tempuri.org/2009/01/mytutorial2.html";  
    16     }  
    17  
    18     //BURKIE:  
    19     [DataContract]  
    20     public class MyTutorial2State {  
    21         [DataMember]  
    22         public bool MotorOn = false;  
    23     }  
    24           
    25     [ServicePort]  
    26     public class MyTutorial2Operations : PortSet<DsspDefaultLookup, DsspDefaultDrop, Get>  
    27     {  
    28     }  
    29       
    30     public class Get : Get<GetRequestType, PortSet<MyTutorial2State, Fault>>  
    31     {  
    32         public Get()  
    33         {  
    34         }  
    35           
    36         public Get(GetRequestType body)  
    37             : base(body)  
    38         {  
    39         }  
    40           
    41         public Get(GetRequestType body, PortSet<MyTutorial2State, Fault> responsePort)  
    42             : base(body, responsePort)  
    43         {  
    44         }  
    45     }  
    46 }  
    47  
    Tuesday, January 6, 2009 3:59 AM