vcPythonTransportController
This is a transport controller behavior that delegates the concrete implementation to user-made Python script(s), which allows creating specialized and custom transport controllers. The behaviour provides events and methods required to handle transport and work tasks. Python transport controller behaviours can be added to static components.
The script implementation should subscribe to the OnBeginTransport and OnBeginWorkEx events. When these events are triggered, the script is expected to create tasks to some internal queue and process them asynchronously. Transport controllers must accept and handle all “assigned” transport and work tasks to completion, there is no task rejection or cancellation mechanism. If and how a transport controller uses separate resources for completing the tasks is entirely up to the specific implementation to decide.
A transport task is considered done when the product instance is placed into the target component container. The target container and position should be queried from the target transport node using the method vcTransportNode.getTransportTarget(vcProduct product).
Work tasks need to be completed by calling the workDone method using the RequestId that was received in the OnBeginWorkEx event.
Transport controllers get an event when the controller is assigned as an implementer of a transport link, and similarly when a link is assigned some other controller. These events (OnLinkAssociated and OnLinkDisassociated) allow the controller to create any custom properties into all transport links it implements.
Inherits: vcTransportController, vcBehaviour
Type constant: VC_PYTHONTRANSPORTCONTROLLER
Properties
Name | Type | Access | Description |
Icon |
String | RW |
The icon file used to represent this transport controller in UI. Defines either filesystem path to the SVG image file or an SVG path data. Both relative and absolute paths with/without .svg extension are allowed. Relative paths are relative to the Icons or Icons. Additional folder under VC installation folder. Example: “UPM/pDroneTransportController” |
IconColor | String | RW |
Fill color applied to the of the Icon in ARGB, RGB or unqualified-color-name format. (e.g. #FFFF0000 or #FF0000 or Red) |
IsSystem | Boolean | R |
Always returns False. |
Methods
Name | Return Type | Parameters | Description |
workDone | None | Integer workId |
Notifies the Work statement that work has been done so the process can continue executing. |
Events
Name | Parameters | Description | ||||||||||||||||||||||||
LinkAssociated |
vcTransportLink link |
(Deprecated) Use OnLinkAssociated. |
||||||||||||||||||||||||
LinkDisassociated |
vcTransportLink link |
(Deprecated) Use OnLinkDisassociated. |
||||||||||||||||||||||||
OnBeginTransport |
List of 2-tuple (vcTransportLink link, vcProduct product) products |
Triggered when the transport controller is asked to transport one or more products. Each product should be transported to the Destination node of the respective transport link. |
||||||||||||||||||||||||
OnBeginWork |
Integer workId, vcProperty processTime, vcMatrix resourcePosition, vcMatrix workPosition |
(DEPRECATED) Use the extended version OnBeginWorkEx instead. Triggered when a Work statement gets executed. workDone with correct workId must be called at some point for Work statement to continue execution. If a handler is not registered, Work statement might wait indefinitely. workId is a unique (within this transport controller) identifier of this work assignment. processTime is a property that defines how long the work itself should take in seconds. resourcePosition defines a position hint in world coordinates where the working resource is expected to be while doing the work. workPosition defines a position hint in world coordinates where the actual work is expected to happen. |
||||||||||||||||||||||||
vcDataContainer arguments |
Triggered when a Work statement gets executed. workDone with correct request id must be called at some point for Work statement to continue execution. If a handler is not registered, Work statement might wait indefinitely. The arguments object has the following attributes:
|
|||||||||||||||||||||||||
OnLinkAssociated | vcTransportLink link | Raised when a transport link is associated with this controller. If a handler is not registered, the default internal implementation is called. | ||||||||||||||||||||||||
OnLinkDisassociated |
vcTransportLink link |
Raised when a transport link is disassociated from this controller. If a handler is not registered, the default internal implementation is called. |
Examples
Example. Defining Custom-Made Transport Controller
from vcScript import * # Minimal transport controller script. # Product simply jumps to the target container and position # transportation time is defined in transport link property MyTime def transport_request_event(request_list): # Event executed when transportation is requested from this controller for transport_link, product in request_list: queue.append([transport_link, product]) trigger.signal(True) # dummy boolean signal connected to the script to trigger condition in onrun def OnStart(): global queue queue = [] def OnRun(): while True: condition(lambda: queue) transport_link, product = queue.pop(0) destination = transport_link.Destination # additional info can be accessed via trasportlink target_container = destination.ComponentContainer target_matrix = destination.getTransportTarget(product).ProductPosition part = product.Component delay(transport_link.MyTime) sim.World.attach(part) # attach to world as matrix is given in world coords part.PositionMatrix = target_matrix target_container.grab(part) def link_associated_event(transport_link): prop = transport_link.createProperty(VC_REAL, 'MyTime') def link_disassociated_event(transport_link): prop = transport_link.getProperty('MyTime') if prop: transport_link.deleteProperty(prop) comp = getComponent() sim = getSimulation() trigger = comp.findBehaviour('TriggerSignal') transport_controller = comp.findBehaviour('PythonTransportController') transport_controller.OnBeginTransport = transport_request_event transport_controller.LinkAssociated = link_associated_event transport_controller.LinkDisassociated = link_disassociated_event #creating product properties that not supported in UI # 1. create a distribution property to a product type # 2. during simulation, take a sample of the distribution # 3. use that sample value to a Real type property in the Product instance. |