CalculateVelocity
Short summary
This function can be used to calculate a veloctiy from given distance and time deltas.
Return: the calculated velocity in METER per SECOND
- Return type: Velocity
Parameters
| Name | Type | Comment | Kind |
|---|---|---|---|
| distanceDelta | Length | the distance to travel | inout |
| timeDelta | Duration | the time it needs to travel | inout |
Code
Declaration
FUNCTION CalculateVelocity : Velocity
VAR_IN_OUT
(* the distance to travel *)
distanceDelta :Length;
(* the time it needs to travel *)
timeDelta :Duration;
END_VAR
VAR
tmpDistance :Length;
tmpTime :Duration;
END_VAR
Implementation
RETURN(
(timeDelta.value = 0.0) // we cannot divide by zero without destroying the universe
OR_ELSE
NOT CheckValueIsANumber(distanceDelta.value)
OR_ELSE
NOT CheckValueIsANumber(timeDelta.value)
);
IF ( (distanceDelta.unit = LengthUnit.METER)
AND_THEN
(distanceDelta.prefix = MetricPrefixes.NONE)
AND_THEN
(timeDelta.unit = DurationUnit.SECONDS)
AND_THEN
(timeDelta.prefix = MetricPrefixes.NONE)
)
THEN
CalculateVelocity.value := distanceDelta.value / timeDelta.value;
ELSE
tmpDistance := ConvertLength(distanceDelta);
tmpTime := ConvertDuration(timeDelta);
CalculateVelocity.value := tmpDistance.value / tmpTime.value;
END_IF