Start a new topic

Calling the Locked Position value on Prismatic Constraint

Dear mates,


Good Day!


I am new on this field and I would like to ask some questions.

Currently I am making a script for Hydraulic Cylinder movement and its pattern.


How can I exposed this to my script (enclosed in red box) - Locked Position of Prismatic Constraint.


Currenty, I input a value of 0 (for the current position of the cylinder) but I need to equate it to the value of the mentioned parameter. I attached also the script.



Thank you in advance.


Best Regards,

Mark

image

py

Hi Mark,


The Position field in the red box is an input that is used to pass your desired lock position to the constraint. You connect an output field from your script to that field in order to control the constraint. Input fields are only used to receive data from a script or other logic, not to report back current states.


If you want to know the value of that field, you can get it from the logic that is actually controlling the value. In your script, it seems you have an output field that is connected to that input field called "Cylinder RotXPos Desired Position". So if you want to set that value into another variable, you can just add:


self.RotXPos = self.outputs.Cylinder_RotXPos_Desired_Position.value


However, I'm not sure this is really what you want. Your code comment says "Current position of Cylinders", which is not the same thing as the position you set to the lock position field. You request a position, but based on the actual dynamics of the entire simulation, the actual resulting position probably won't be exactly what you requested. For example, the constraint could have stiffness or maximum forces, and maybe is not strong enough to get to the position you requested. 


This is why all constraints also have a large set of output fields that report the actual current positions (as well as many other forces and states) of the constraint: 

image


If your script needs to know the current length of the constraint, you have to create an input field in the script and connect it from the constraint's output field. The code might look like:


def on_add_to_universe(self, universe):

    CreateInput(self, "Cylinder RotXPos Current Position", Types.Type_VxReal)


def pre_step(self):

    self.RotXPos = self.inputs.Cylinder_RotXPos_Current_Position.value



Let me know if this answers your question.


Martin

Just as a note in case other people are looking at the solution: The sample code I wrote and the original post use the functions CreateInput and CreateOutput. These are not built into the Python API, but we use them often to create fields from inside the script (instead of using the field editor dialog in the Vortex Editor). The functions can just be pasted into any script: 

def CreateInput(extension, name, type):
   input = extension.getInput(name)
   if input is None:
      input = extension.addInput(name, type)

def CreateOutput(extension, name, type):
   output = extension.getOutput(name)
   if output is None:
      output = extension.addOutput(name, type)

def CreateParameter(extension, name, type):
   param = extension.getParameter(name)
   if param is None:
      param = extension.addParameter(name, type)

 

Login to post a comment