(testmodels-rotationmarkerdeprecationtest)= # rotationMarkerDeprecationTest.py You can view and download this file on Github: [rotationMarkerDeprecationTest.py](https://github.com/jgerstmayr/EXUDYN/tree/master/python/TestModels/rotationMarkerDeprecationTest.py) ```{code-block} python :linenos: #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # This is an EXUDYN example # # Details: The rotation of a joint or connector frame is given to its markers, as localHT (#2745): # a body on a GenericJoint and a body on a RigidBodySpringDamper, each turned once by # rotationMarker0/1 and once by the localHT of the markers, move the same; the # RigidBodySpringDamper applies rotationMarker0 on the same side as all joints (#2801). # rotationMarker0/1 are deprecated: setting one other than the unit matrix warns where it is # added, once per session and name - every time with exu.special.deprecations.warnOnce = False - # and every use is counted in exu.sys['deprecationUse']['items'] (#2804, #2806). GetJointArgs # with a rotation for an existing marker uses no deprecated parameter. # # Author: Johannes Gerstmayr # Date: 2026-10-03 # # Copyright:This file is part of Exudyn. Exudyn is free software. You can redistribute it and/or modify it under the terms of the Exudyn license. See 'LICENSE.txt' for more details. # #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ import exudyn as exu from exudyn.utilities import * import numpy as np import warnings import os testIsActive = exu.sys.get('testIsActive', False) A0 = RotationMatrixX(0.3) @ RotationMatrixY(0.5) #the joint frame on the ground A1 = RotationMatrixZ(-0.4) @ RotationMatrixX(0.2) #the joint frame on the body Ab = A0 @ A1.T #the body, turned so that both joint frames agree in the reference configuration pb = -Ab @ np.array([-0.2, 0, 0]) #and its marker at the origin def ItemUses(): """all recorded uses of deprecated item parameters""" return sum(exu.sys.get('deprecationUse', {}).get('items', {}).values()) def Model(mbs): oGround = mbs.AddObject(ObjectGround()) inertia = InertiaCuboid(density=1000, sideLengths=[0.4, 0.1, 0.1]) node = mbs.AddNode(NodeRigidBodyEP(referenceCoordinates=list(pb) + list(RotationMatrix2EulerParameters(Ab)), initialVelocities=[0]*7)) body = mbs.AddObject(ObjectRigidBody(nodeNumber=node, mass=inertia.Mass(), inertia=inertia.GetInertia6D())) return (oGround, node, body) def Simulate(useLocalHT, connector): SC = exu.SystemContainer() mbs = SC.AddSystem() (oGround, node, body) = Model(mbs) if useLocalHT: m0 = mbs.AddMarker(MarkerBodyRigid(bodyNumber=oGround, localHT=exu.HT(rotation=A0))) m1 = mbs.AddMarker(MarkerBodyRigid(bodyNumber=body, localHT=exu.HT(rotation=A1, translation=[-0.2, 0, 0]))) rotations = {} else: m0 = mbs.AddMarker(MarkerBodyRigid(bodyNumber=oGround, localPosition=[0, 0, 0])) m1 = mbs.AddMarker(MarkerBodyRigid(bodyNumber=body, localPosition=[-0.2, 0, 0])) rotations = {'rotationMarker0': A0, 'rotationMarker1': A1} with warnings.catch_warnings(): warnings.simplefilter('ignore', DeprecationWarning) if connector: k = 2000. mbs.AddObject(RigidBodySpringDamper(markerNumbers=[m0, m1], stiffness=np.diag([k, 2*k, 3*k, 0.1*k, 0.2*k, 0.3*k]), damping=np.diag([1, 1, 1, 0.1, 0.1, 0.1]), **rotations)) else: mbs.AddObject(GenericJoint(markerNumbers=[m0, m1], constrainedAxes=[1, 1, 1, 1, 1, 0], **rotations)) mbs.AddLoad(LoadForceVector(markerNumber=mbs.AddMarker(MarkerBodyPosition(bodyNumber=body, localPosition=[0.2, 0, 0])), loadVector=[0, -10, 5])) mbs.Assemble() simulationSettings = exu.SimulationSettings() simulationSettings.timeIntegration.newton.useModifiedNewton = False #Just for the test; modified Newton is usually faster simulationSettings.timeIntegration.numberOfSteps = 200 simulationSettings.timeIntegration.endTime = 0.2 simulationSettings.timeIntegration.verboseMode = 0 simulationSettings.solution.file.write = False mbs.SolveDynamic(simulationSettings) return np.array(mbs.GetNodeOutput(node, exu.OutputVariableType.Coordinates)) errors = 0 u = 0. #the same motion with the rotation in the markers and in the deprecated parameters; only the latter is recorded for connector in [False, True]: used = ItemUses() qLocalHT = Simulate(True, connector) if ItemUses() != used: errors += 1 qRotationMarker = Simulate(False, connector) if ItemUses() != used + 2: #rotationMarker0 and rotationMarker1 errors += 1 exu.Print('connector' if connector else 'joint', ': difference localHT - rotationMarker =', np.linalg.norm(qLocalHT - qRotationMarker)) if np.linalg.norm(qLocalHT - qRotationMarker) > 1e-10: errors += 1 u += np.sum(qLocalHT) #the warning: at the line that adds the item, once per session and name, or on every use deprecations = exu.special.deprecations warnOnceStored = deprecations.warnOnce SC = exu.SystemContainer() mbs = SC.AddSystem() (oGround, node, body) = Model(mbs) m0 = mbs.AddMarker(MarkerBodyRigid(bodyNumber=oGround)) m1 = mbs.AddMarker(MarkerBodyRigid(bodyNumber=body, localPosition=[-0.2, 0, 0])) nWarnings = [] for warnOnce in [True, False]: deprecations.warnOnce = warnOnce deprecations.Reset() #as if the session had just started with warnings.catch_warnings(record=True) as caught: warnings.simplefilter('always') for i in range(3): mbs.AddObject(GenericJoint(markerNumbers=[m0, m1], constrainedAxes=[0]*6, rotationMarker0=A0)) found = [entry for entry in caught if issubclass(entry.category, DeprecationWarning)] nWarnings.append(len(found)) if any('ObjectJointGeneric: the parameter rotationMarker0' not in str(entry.message) or os.sep + 'exudyn' + os.sep in entry.filename for entry in found): errors += 1 #the message names item and parameter, the warning points at this script, not into Exudyn deprecations.warnOnce = warnOnceStored exu.Print('warnings, once per session and on every use:', nWarnings) if nWarnings != [1, 3]: errors += 1 #GetJointArgs turns a copy of the existing marker instead of passing rotationMarker0 on used = ItemUses() args = GetJointArgs(mbs, markerNumber0=m0, rotationMarker0=A0, bodyNumber1=body) mbs.AddObject(RevoluteJointZ(**args)) if ItemUses() != used or 'rotationMarker0' in args: errors += 1 exu.Print('rotationMarkerDeprecationTest: errors', errors) u += errors exu.Print('solution of rotationMarkerDeprecationTest=', u) exu.sys['testResult'] = u ```