@gov.nasa.jpl.honeycomb/ros-transform-tracker
v0.0.6
Published
Helper class for tracking updates to ROS node transforms over time.
Readme
ros-transform-tracker
Package for tracking the state of ros transform data from the /tf and /tf_static ros topics over time, extracting transform information in different frames, and looking back to find transform positions at different points in time.
Use
import { RosTransformTracker } from '@gov.nasa.jpl.honeycomb/ros-transform-tracker';
const tracker = new RosTransformTracker();
ws.subscribe('/tf', msg => tracker.applyMessage(msg, '/tf'));
ws.subscribe('/tf_static', msg => tracker.applyMessage(msg, '/tf_static'));
// get the local transform of "base_link" in "world"
const localTransform = new Matrix4().identity();
tracker.getTransformInFrame('base_link', 'world', localTransform);
// Apply the transform message to the given object in world space
const pointCloud;
const pcMessage;
tracker.applyMessageInFixedFrame(pointCloud, pcMessage.header, pcMessage.transform);API
Functions
compareTimeStamps
compareTimeStamps( a : RosTimeStamp, b : RosTimeStamp ) : voidReturns a number > 0 if a is larger than b, 0 if they're equal, a negative number if a is less than b.
getInFrame
getInFrame(
toTransform : RosFrame,
rosFrame : RosFrame,
posOut : Vector3,
rotOut : Vector4
) : voidGets the position and orientation of frame rosFrame in toTransform.
RosTransformTrackerBase
An abstract base class for tracking and extracting ros transforms over time.
reset
reset( resetStatic : Boolean = true ) : voidReset all the transform information to start from scratch. If resetStatic is true
then static frames are also reset.
applyMessage
applyMessage( msg : RosTfMessage, topic : '/tf' | '/tf_static' ) : voidApply a tf message to the tracked transforms. If the message timestamp is earlier than the last applied message to a certain transform then it is skipped.
getTransformInRootFrame
getTransformInRootFrame(
name : string,
matrix : Matrix4,
time : RosTimeStamp | null = null
) : BooleanSet "matrix" to the transform of the given frame relative to the root at the requested time. Returns true if the frame can be derived, false otherwise.
getTransformInFrame
getTransformInFrame(
fromFrame : string,
toFrame : string,
matrix : Matrix4,
time : RosTimeStamp | null = null
) : BooleanMatrix is a transform matrix relative to the frame called fromFrame. matrix
is modified to be relative to the frame called toFrame. If time is provided
then it is relative to those frames at that given time which is derived by
looking back through the available frames.
Returns false if the requested frames could not be located in the available
lookback transform messages.
getWorldPoseAtTime
getWorldPoseAtTime(
name : String,
time : RosTimeStamp,
outPos : Vector3,
outRot : Vector4
) : BooleanOutputs the position and rotation of the frame with the given name at the given
ROS time. The position data is put on the outPos object and rotation on
outRot. The x, y, z, and w (for rotation) fields will be added if
they're not available.
Returns false if the time frame could not be found. True if it was found successfully.
getParentName
getParentName( name : String ) : String | nullReturns the name of te parent of the provided frame. Returns null if the frame does not exist or it has no parent.
seekBack
seekBack( cb : Function ) : voidOverrideable function that should iterate over the frames back in time starting
at the last applied message passing an object that looks like so into the
callback function cb:
{
'/tf' : RosTfMessage,
'/tf_static : RosTfMessage
}If cb returns true the iteration should stop.
RosTransformTracker
Transform tracker that retains a buffer of tf and tf_static ros messages over time so they can be used to derive the latest position of a ros frame.
extends RosTransformTrackerBase
constructor
constructor( bufferMs : Number = 10000 ) : voidAs well as the name of the root fixed frame to provide transforms relative to a buffer in milliseconds is provided so we know how long to keep data around.
applyMessage
applyMessage( msg : RosTfMessage, topic : '/tf' | '/tf_static' ) : voidOverride of RosTransformTrackerBase.applyMessage that
seekBack
seekBack( cb : Function ) : voidOverride of RosTransformTrackerBase.seekBack that iterates over the the stored messages from latest to earliest.
reset
reset( resetStatic : null, cb : Function ) : voidOverride of RosTransformTrackerBase.reset that clears the saved messages as well as the transforms.
RosTimeStamp
secs
secs : Numbernsecs
nsecs : Numbersec
sec : Numbernsec
nsec : NumberRosFrame
position
position : Array<Number>orientation
orientation : Array<Number>translation
translation : Array<Number>rotation
rotation : Array<Number>