Part 2: Mastering Variables with Inspire Python APIs - Motion
Karthi Kandasamy
Altair Employee
Motion
This discussion explains the Python code for assigning variables to motion entities such as motors, actuators, coil springs, torsion springs, translational initial conditions, rotational initial conditions, and motion contact friction coefficients.
Motor
#Create variable
model.variables.add("Angle", type=None, expression='100 deg')
model.variables.add("Speed", type=None, expression='100 rpm')
model.variables.add("Acceleration", type=None, expression='100rad/s^2')
model.variables.add("Torque", type=None, expression='10 N*m')
#Motor's value can passed in four different ways (Angle, Speed, Acceleration, Torque) based
in its Type.
#Query an existing Motor with its name 'Motor 1'
Motor = model.getChild(type ='Motor', name = 'Motor 1')
if Motor:
#Assign Motor type as ANGLE and assign a Angle variable
Motor.type = 'ANGLE'
#Asign the variable to the Motor.
Motor.value='Angle'
#Assign Motor type as SPEED and assign a speed variable
Motor.type = 'SPEED'
#Asign the variable to the Motor.
Motor.value='Speed'
#Assign Motor type as ACCELERATION and assign a Acceleration variable
Motor.type = 'ACCELERATION'
#Asign the variable to the Motor.
Motor.value='Acceleration'
#Assign Motor type as TORQUE and assign a Torque variable
Motor.type = 'TORQUE'
#Asign the variable to the Motor.
Motor.value='Torque'
Actuators
#Create variable
model.variables.add("Displacement", type=None, expression='100 mm')
model.variables.add("Velocity", type=None, expression='100 m/s')
model.variables.add("Acceleration", type=None, expression='100 m/s^2')
model.variables.add("Force", type=None, expression='10 N')
#Actuators's value can passed in four different ways (Displacement, Speed, Acceleration,
#Force) based in its Type.
#Query an existing Actuators with its name 'Actuator 1'
Actuator = model.getChild(type ='Actuator', name = 'Actuator 1')
if Actuator:
#Assign Actuator type as ANGLE and assign a Angle variable
Actuator.type = 'DISPLACEMENT'
#Asign the variable to the Actuator.
Actuator.value='Displacement'
#Assign Actuator type as SPEED and assign a speed variable
Actuator.type = 'SPEED'
#Asign the variable to the Actuator.
Actuator.value='Velocity'
#Assign Actuator type as ACCELERATION and assign a Acceleration variable
Actuator.type = 'ACCELERATION'
#Asign the variable to the Actuator.
Actuator.value='Acceleration'
#Assign Actuator type as TORQUE and assign a Torque variable
Actuator.type = 'Force'
#Asign the variable to the Actuator.
Actuator.value='Force'
Coil Spring
model.variables.add("Stiffness", type=None, expression='100 N/m')
model.variables.add("freelength", type=None, expression='100 mm')
model.variables.add("Force", type=None, expression='10 N')
model.variables.add("Damping", type=None, expression='1.0 N*s/m')
#Query an existing CoilSpring with its name 'Coil Spring 1'
CoilSpring = model.getChild(type ='CoilSpring', name = 'Coil Spring 1')
#CoilSpring can have three different type namely SPRING, DAMPER, SPRINGDAMPER.
if CoilSpring:
CoilSpring.type = 'SPRINGDAMPER'
CoilSpring.k= 'Stiffness'
CoilSpring.c = "Damping"
CoilSpring.freeLength = 'freelength'
CoilSpring.type = 'SPRING'
CoilSpring.k= 'Stiffness'
CoilSpring.preload = 'Force'
CoilSpring.type = 'DAMPER'
CoilSpring.c = "Damping"
Motion Contacts
#Create Variables
model.variables.add("static_friction_coefficient", type=None, expression='0.1')
model.variables.add("Dynamic_friction_coefficient", type=None, expression='0.3')
model.variables.add("Damping", type=None, expression='12.0 N*s/m')
#Query an existing MotionContact with its name 'Motion Contact 1'
MotionContact = model.getChild(type ='MotionContact', name = 'Motion Contact 1')
if MotionContact:
MotionContact.damping = "Damping"
MotionContact.muDynamic = 'Dynamic_friction_coefficient'
MotionContact.muStatic = 'static_friction_coefficient'
Initial Velocity
#Create variables
model.variables.add("velocity", type=None, expression='12.0 m/s')
#Query an existing InitialVelocity with its name 'Motion Contact 1'
InitialVelocity = model.getChild(type ='TranslationalInitialCondition', name = 'Initial Velocity 1')
if InitialVelocity:
InitialVelocity.magnitude='velocity'
Initial Angular Velocity
#Create variable
model.variables.add("AngularVelocity", type=None, expression='12.0 rpm')
#Query an existing AngularInitialCondition with its name 'Initial Angular Velocity 1'
AngularInitialCondition = model.getChild(type ='AngularInitialCondition', name = 'Initial Angular Velocity 1')
if AngularInitialCondition:
AngularInitialCondition.magnitude='AngularVelocity'
Coming soon,
Part 3: Mastering Variables with Inspire Python APIs - Sketch
0