I’m new to VC but I would like to thank your courses and lessons that are very clear even for people like me where english is not native language.
I’m able to simulate a conveyor that feed different kind of boxes but I kept changing the box’s height in order to check if my robot do the job the way I wanted.
Is there a way with python script to randomly modify box’s height into the conveyor , then to simulate it and the conveyor send box with different height.
Hope you’ll be able to understand what I’m saying.
thx in advance
With python’s random module you can randomly set a real parameter. So let’s say you have a conveyor component which has a path called “Path__HIDE__”. Then you feed block parts on the conveyor which have a real parameter “Height_Z” to set the height of the block. Now you could create a python script in the conveyor and use the snippet below to set that height to a random value between 200 and 400 mm when part enters the conveyor.
from vcScript import *
comp = getComponent()
path = comp.getBehaviour('Path__HIDE__')
def part_transition(part, arrive):
if not arrive:
prop = part.getProperty('Height_Z')
if not prop:
prop.Value = random.uniform(200, 400)
path.OnTransition = part_transition
Here’s an example model (app version 4.2):
Random_block.vcmx (180.4 KB)
I’ve an example with creating randomized cylinders, which are in a component.
The “Cylinder” feature is changed after creation randomly and then it’s updated.
Setting properties on a feature (Height, Radius, etc.) requires str as far I know. They are expressions.
The second part is the detection of these properties on the “Cylinder” feature.
CreatorRandomCylinder.vcmx (194.3 KB)
PS: Using path-sensors, require that the frame is also on the Path itself. If you forget this, the sensor does not detect anything. A better approach could be the use of the ProcessModel. But I haven’t used it yet.
Others have given examples that answer your question. If it is for debug or testing purposes, consider using Advanced feeder or library like Works to create boxes with different heights that are fed to conveyor as alternative to scripting.
I made a test layout in which the box changes its height when it is created during simulation. I do not recommend this approach for various reasons.
- It is just an experiment to test certain things such as feature sharing, feature tree evaluation, performance, expression calculation, troubleshooting primitive feature expression versus Transform scaling expression, part vs component creator, etc. I did not go so far with the layout to test with Python Feature since it is rarely used in component modeling, albeit as an alternative for Transform feature.
Layout - Box with Pseudo-random Height.vcmx (54.6 KB)
Some additional comments on keke and deadeye examples if it helps.
When box arrives at conveyor, it is transferred to path. A One-Way Path is vcMotionPath object that inherits from vcContainer.
The OnTransition event is from vcContainer. The event itself is logical (box is being transferred to or from path).
The OnPhysicalTransition is from vcMotionPath. The event itself is physical (box is physically entering or leaving the path).
Generally, an event-based approach is straightforward. That is what keke and deadeye did using the OnTransition event. Here are two lessons in Academy that might help if the concept is new to you in Visual Components Python API.
The examples of keke and deadeye use the random module in Python 2.7 to get a pseudo-random number. In keke’s example, keke uses a component property (parameter) to control the height, which is a real number. In deadeye’s example, deadeye uses expression, which is a string, to set a default property of a Cylinder feature. The expression is calculated to return a value (the calculated value).
Perhaps this lesson in Academy can help with understanding how Visual Components can generate pseudo-random numbers.
Side question: Do you plan on doing any machine learning for your robot or need to make datasets from the simulation?
thanks a lot for your help,
This is exaclty what I’m looking for
For sure I can send that random height number to robot’s variable.
Is it possible to get calculation for TCP?
let’s say my random height number is 275 so I want my new Tool Center Point (TCP2) = TPC1+275.