Difference between revisions of "Robitics Studio MSRS"

From no name for this wiki
Jump to: navigation, search
(Links)
(HttpGet aufrufen)
 
Line 49: Line 49:
 
</source>
 
</source>
  
== HttpGet aufrufen ==
+
== HttpGet und Get aufrufen ==
 
Beispiel, wie man ein HttpGet aufruft und zur Antwort kommt.
 
Beispiel, wie man ein HttpGet aufruft und zur Antwort kommt.
 
Service Port Operations Definition:
 
Service Port Operations Definition:
Line 80: Line 80:
 
  object yuppi =  result.Body;
 
  object yuppi =  result.Body;
 
}
 
}
 +
</source>
 +
 +
DSS Tutorial 1 erweitert:
 +
 +
<source lang="csharp">
 +
        /// <summary>
 +
        /// Handle Bumper Notifications
 +
        /// </summary>
 +
        /// <param name="notification">Update notification</param>
 +
        private void BumperHandler(bumper.Update notification)
 +
        {
 +
            if (notification.Body.Pressed)
 +
                LogInfo(LogGroups.Console, "Ouch - the bumper was pressed.");
 +
 +
            bumper.Get get = new bumper.Get();
 +
            _bumperPort.Post(get);
 +
            Activate(Arbiter.Choice(get.ResponsePort, GetResponseHandler,  ex => LogError(ex)));         
 +
           
 +
        }
 +
 +
 +
        private void GetResponseHandler(bumper.ContactSensorArrayState sensorState)
 +
        {
 +
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
 +
            foreach (bumper.ContactSensor sensor in sensorState.Sensors)
 +
            {
 +
                bool pressed = sensor.Pressed;
 +
                sb.Append(pressed);
 +
                sb.Append(" ");
 +
            }
 +
            LogInfo(sb.ToString());
 +
        }
 
</source>
 
</source>
  

Latest revision as of 17:13, 23 December 2008

Commands in der Commandline

dssnewservice

Beispiel

dssnewservice /namespace:MyImpl /service:MyTouchSensor

Client/Server Beispiel

Server Service

Client Service

PortSet Beispiel mit Arbiter.Choice

protected override void Start()
{
  base.Start();
  Dispatcher dispatcher = new Dispatcher();
  DispatcherQueue taskQueue = new DispatcherQueue("sample queue", dispatcher);

  Arbiter.Activate(taskQueue,
   Arbiter.FromIteratorHandler(IteratorExample)
  );

}
	
IEnumerator<ITask> IteratorExample()
{
   PortSet<int, string> operations = new PortSet<int, string>();
   //operations.Post(888);
   operations.Post("Hello");

   int resultInt = 0;
   string resultString = "";


   yield return Arbiter.Choice(operations, i => resultInt = i, s => resultString = s);

   LogInfo("" + resultInt); //Da der zweite Port im Portset eine Stringmessage enthaelt,
                            //aber der erste Port leer ist, wird die lokale Variable resultString gefuellt sein,
                            //die lokale Variable resultInt wird leer sein.
   LogInfo(resultString);

   yield break;
}

HttpGet und Get aufrufen

Beispiel, wie man ein HttpGet aufruft und zur Antwort kommt. Service Port Operations Definition:

[ServicePort]
public class ClaudeTestsOperations : PortSet<DsspDefaultLookup, DsspDefaultDrop, Get, HttpGet>{}


[ServiceHandler(ServiceHandlerBehavior.Concurrent)]
public IEnumerator<ITask> HttpGetHandler(HttpGet get)
{
  get.ResponsePort.Post(new HttpResponseType(_state));
  yield break;
}

IEnumerator<ITask> IteratorExample()
{
 HttpGet get = new HttpGet();            
 this._mainPort.P3.Post(get);

 HttpResponseType result = null;

 yield return Arbiter.Choice(get.ResponsePort, myRes => result = myRes, ex => LogError(ex));

 object yuppi =  result.Body;
}

DSS Tutorial 1 erweitert:

        /// <summary>
        /// Handle Bumper Notifications
        /// </summary>
        /// <param name="notification">Update notification</param>
        private void BumperHandler(bumper.Update notification)
        {
            if (notification.Body.Pressed)
                LogInfo(LogGroups.Console, "Ouch - the bumper was pressed.");

            bumper.Get get = new bumper.Get();
            _bumperPort.Post(get);
            Activate(Arbiter.Choice(get.ResponsePort, GetResponseHandler,  ex => LogError(ex)));           
            
        }


        private void GetResponseHandler(bumper.ContactSensorArrayState sensorState)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            foreach (bumper.ContactSensor sensor in sensorState.Sensors)
            {
                bool pressed = sensor.Pressed;
                sb.Append(pressed);
                sb.Append(" ");
            }
            LogInfo(sb.ToString());
        }

Implementation eines generellen Contracts

In diesen Beispiel wird der Microsoft.Robotics.Services.ContactSensor.Proxy.Contract Contract implementiert. Mit dem Robotics Tutorial 1 kann der ContactSensor ausprobiert werden.

Links