Matt Zukowski

I've been playing around with using Python to run simulations. So far I've managed to get things more or less working by modifying the robotics tutorials, but I'm a bit confused about a few things.

For example, the robotics tutorial uses the following code to initialize a bumper sensor:

Code Snippet

_bumperPort = DssEnvironment.ServiceForwarder[bumper.ContactSensorArrayOperations](bumperServiceUri)
bumperNotificationPort = bumper.ContactSensorArrayOperations()
_bumperPort.Subscribe(bumperNotificationPort)



and then

Code Snippet

Arbiter.Activate(DssEnvironment.TaskQueue,Arbiter.Receive[bumper.Update](True, bumperNotificationPort, bumperUpdate) )



Unfortunately this last part doesn't work for me at all. I get an error saying something to the effect of "Port[Update] expected, but was given ContactSensorArrayOperations". Through trial and error, I found that I had to add .ToPortOfType4() to make this work, like so:

Code Snippet

Arbiter.Activate(DssEnvironment.TaskQueue,Arbiter.Receive[bumper.Update](True, bumperNotificationPort.ToPortOfType4(), bumperUpdate) )



What exactly is going on here This works, but I'm not quite sure what I'm doing... i.e. why might the sample code from the tutorial require this modification




Re: Microsoft Robotics - Community python, ContactSensorArrayOperations, and Port[Update]

George Chrysanthakopoulos

When you have a CCR PortSet like the ContactSensorArrayOperations, you basically have a collection of ports, each typed to some message type. When using the Arbiter.Receive() methods, they expect a single port. So we generate implicit conversion methods and add them to the operation PortSet, so when they are using in the Arbiter.XXXX methods, they automatically "extract" the sub-port from the PortSet. On some languages however this does not work.

More specifically, when you do

Code Snippet

Arbiter.Receive[bumper.Update](true,bumperNotificationPort,bumperUpdateHandler)

what we do underneath is:

Code Snippet

Arbiter.Receive[bumper.Update](true, (Port<bumper.Update>)bumperNotificationsPort ,bumperUpdateHandler)

which becomes

Code Snippet

Arbiter.Receive[bumper.Update](true, bumperNotificationPort.ToPortOfType4() ,bumperUpdateHandler)

which is what you had to do manually on Python! Smile





Re: Microsoft Robotics - Community python, ContactSensorArrayOperations, and Port[Update]

Pavel Khijniak [MSFT]

What version of Iron Python are you using We don't work with their 1.0 release, however we do work with their new 1.1 RC1 release and later. You can download the latest 1.1 release from here: http://www.codeplex.com/Wiki/View.aspx ProjectName=IronPython

Pavel





Re: Microsoft Robotics - Community python, ContactSensorArrayOperations, and Port[Update]

Matt Zukowski

Thanks for both answers. The explanation was very helpful, and I will upgrade to IronPython 1.1.