```{raw} latex \clearpage ``` (sec-item-sensorbody)= # SensorBody A sensor attached to a body at a local position $\pLocB$, which measures one of the output variables of the body at that point. ## Parameters The parameters of the item; in a dictionary, its type is 'Body': | name | type | size | default | description | |---|---|---|---|---| | **name** | String | | '' | sensor's unique name | | **bodyNumber** | ObjectIndex | | invalid (-1) | body (=object) number to which sensor is attached to | | **localPosition** | Vector3D | 3 | [0.,0.,0.] | (symbol: $\pLocB$) local (body-fixed) body position of sensor | | **writeToFile** | Bool | | True | True: write sensor output to file; flag is ignored (interpreted as False), if fileName='' | | **fileName** | String | | '' | directory and file name for sensor file output; empty: no file is written; a relative name is placed in `exudyn.config.outputDirectory` if that is set; the directory is created if it does not exist | | **outputVariableType** | OutputVariableType | | OutputVariableType::_None | OutputVariableType for sensor | | **storeInternal** | Bool | | False | true: store sensor data in memory (faster, but may consume large amounts of memory); false: internal storage not available | | **visualization** | VSensorBody | | | parameters for visualization of item | ## Visualization parameters The parameters of `VSensorBody`, given as `visualization`: | name | type | size | default | description | |---|---|---|---|---| | **show** | Bool | | True | set true, if item is shown in visualization and false if it is not shown | ## Drawing Drawn as [all sensors](#sec-drawing-sensors). (description-sensorbody)= ## Detailed description ### Attached to The body `bodyNumber`, at the point `localPosition` $\pLocB$. The local position is given in the body frame and measured from the **reference point** of the body - the position of its node, which is `referencePosition` in `CreateRigidBody`. The center of mass of an `ObjectRigidBody` lies at `centerOfMass` from it, so a sensor at the center of mass has that local position. ### Measures `outputVariableType` is one of the output variables of the body, evaluated at $\pLocB$, as its page lists them under **Output variables** - e.g. `Position`, `Velocity`, `Displacement`, `AngularVelocity`; for a flexible body also strains or forces along its axis. (miniexample-sensorbody)= ## Mini example ```python #a point of a body given by its local position: a planar rigid body spinning about its center node = mbs.AddNode(NodeRigidBody2D(referenceCoordinates=[0.5,0.2,0], initialVelocities=[0,0,0.5*np.pi])) body = mbs.AddObject(ObjectRigidBody2D(nodeNumber=node, mass=1, inertia=0.1)) sPoint = mbs.AddSensor(SensorBody(bodyNumber=body, localPosition=[0.5,0,0], outputVariableType=exu.OutputVariableType.Position, storeInternal=True, writeToFile=False)) mbs.Assemble() mbs.SolveDynamic() #after a quarter turn the point [0.5,0,0] of the body at [0.5,0.2] is at [0.5,0.7,0] exu.sys['testResult'] = mbs.GetSensorValues(sPoint)[1] #0.7 ``` Examples (Ex) and TestModels (TM) that show this item, with weblink to github: [`tutorialSpringDamperCreate.py`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/Examples/notebooks/tutorialSpringDamperCreate.py) (Ex), [`tutorialRigidBody.py`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/Examples/notebooks/tutorialRigidBody.py) (Ex), [`tutorialRigidBodyCreate.py`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/Examples/notebooks/tutorialRigidBodyCreate.py) (Ex), [`fourBarMechanism3D.py`](https://github.com/jgerstmayr/EXUDYN/blob/master/python/Examples/fourBarMechanism3D.py) (Ex)