Table of contents
CSPICE_CKW03 adds a type 3 segment to a C-kernel.
Given:
handle the handle of the CK file to which the segment will be written.
help, handle
LONG = Scalar
The file must have been opened with write access.
begtim,
endtim the beginning and ending encoded SCLK times for which the
segment provides pointing information.
help, begtim
DOUBLE = Scalar
help, endtim
DOUBLE = Scalar
`begtim' must be less than or equal to the SCLK time associated
with the first pointing instance in the segment, and `endtim'
must be greater than or equal to the time associated with the
last pointing instance in the segment.
inst the NAIF integer ID code for the instrument that this segment
will contain pointing information for.
help, inst
LONG = Scalar
ref a character string which specifies the inertial reference frame
of the segment.
help, ref
STRING = Scalar
The rotation matrices represented by the quaternions
that are to be written to the segment transform the
components of vectors from the inertial reference frame
specified by `ref' to components in the instrument fixed
frame. Also, the components of the angular velocity
vectors to be written to the segment should be given
with respect to `ref'.
`ref' should be the name of one of the frames supported
by the SPICELIB routine FRAMEX.
avflag a logical flag which indicates whether or not the segment will
contain angular velocity.
help, avflag
BOOLEAN = Scalar
segid the segment identifier.
help, segid
STRING = Scalar
A CK segment identifier may contain up to 40 printable
characters and spaces.
sclkdp the encoded spacecraft clock times associated with each pointing
instance.
help, sclkdp
DOUBLE = Array[N]
These times must be strictly increasing.
quats an array of SPICE-style quaternions representing a sequence of
C-matrices.
help, quats
DOUBLE = Array[4,N]
See the discussion of quaternion styles in -Particulars below.
The C-matrix represented by the ith quaternion in
`quats' is a rotation matrix that transforms the
components of a vector expressed in the inertial
frame specified by `ref' to components expressed in
the instrument fixed frame at the time sclkdp(i).
Thus, if a vector V has components x, y, z in the
inertial frame, then V has components x', y', z' in
the instrument fixed frame where:
[ x' ] [ ] [ x ]
| y' | = | CMAT | | y |
[ z' ] [ ] [ z ]
avvs the angular velocity vectors ( optional ).
help, avvs
DOUBLE = Array[3,N]
The ith vector in `avvs' gives the angular velocity of
the instrument fixed frame at time sclkdp(i). The
components of the angular velocity vectors should
be given with respect to the inertial reference frame
specified by `ref'.
The direction of an angular velocity vector gives
the right-handed axis about which the instrument fixed
reference frame is rotating. The magnitude of the
vector is the magnitude of the instantaneous velocity
of the rotation, in radians per second.
If `avflag' is False then this array is ignored by the
routine; however it still must be supplied as part of
the calling sequence.
starts the start times of each of the interpolation intervals.
help, starts
DOUBLE = Array[M]
These times must be strictly increasing and must coincide with
times for which the segment contains pointing.
the call:
cspice_ckw03, handle, begtim, endtim, inst, ref, avflag, $
segid, sclkdp, quats, avvs, starts
writes the data for a type 3 segment to the open CK file
indicated by 'handle'.
None.
Any numerical results shown for this example may differ between
platforms as the results depend on the SPICE kernels used as input
and the machine specific arithmetic implementation.
1) Create a CK type 3 segment; fill with data for a simple time
dependent rotation and angular velocity.
Example code begins here.
PRO ckw03_ex1
;;
;; Define needed parameters.
;;
SPICETRUE = 1L
CK3 = "ckw03_ex1.bc"
IFNAME = "Test CK type 3 created by cspice_ckw03"
INST = -77703
MAXREC = 201
SC = -777
SECPERTICK = 0.001d
SEGID = "Test type 3 segment test CK"
SPACING_TICKS = 10.d
;;
;; `NCOMCH' defines the number of characters to reserve for
;; the kernel's comment area. This example doesn't write
;; comments, but it reserves room for 5000 characters.
;;
NCOMCH = 5000
;;
;; The base reference from for the rotation data.
;;
REF = "J2000"
;;
;; Time spacing in encoded ticks.
;;
SPACING_TICKS = 10.d
;;
;; Time spacing in seconds
;;
SPACING_SECS = SPACING_TICKS * SECPERTICK
;;
;; Declare an angular rate in radians per sec.
;;
RATE = 1.d-2
;;
;; Create a 4xMAXREC matrix for quaternions, and a
;; 3xMAXREC for angular velocity.
;;
quats = dblarr( 4, MAXREC )
av = dblarr( 3, MAXREC )
;;
;; Create a 3x3 double precision identity matrix.
;; The Icy call:
;;
;; cspice_ident, work_mat
;;
;; performs the same function.
;;
work_mat = identity( 3 )
;;
;; Convert the matrix to quaternion.
;;
cspice_m2q, work_mat, work_quat
;;
;; Copy the work quaternion to the first row of
;; quats.
;;
quats[0:3] = work_quat
;;
;; Create an angular velocity vector. Copy to the first row
;; of `av'. This vector is in the `REF' reference frame.
;;
av [0:2] = [0.d, 0.d, RATE ]
;;
;; Create an array of encoded tick values in increments of
;; `SPACING_TICKS' with an initial value of 1000 ticks...
;;
sclkdp = dindgen(MAXREC) * SPACING_TICKS
sclkdp = sclkdp + 1000.d
;;
;; Fill the rest of the av and quats matrices
;; with simple data.
;;
for i = 1, (MAXREC-1) do begin
;;
;; Create the transformation matrix for a rotation of `theta'
;; about the Z axis. Calculate `theta' from the constant
;; angular rate `RATE' at increments of `SPACING_SECS'.
;;
;; theta = t * d(theta)
;; --------
;; dt
;;
theta = ( double(i) * RATE * SPACING_SECS)
cspice_rotmat, work_mat, theta, 3, rwmat
;;
;; Convert the `rwmat' matrix to SPICE type quaternion.
;;
cspice_m2q, rwmat, work_quat
;;
;; Store the quaternion in the `quats' matrix.
;; Store angular velocity in `av'. Both variables
;; represent arrays, but in IDL you can fill them
;; as vectors.
;;
;;
quats[ (i*4):((i*4)+3) ] = work_quat
av [ (i*3):((i*3)+2) ] = [ 0.d, 0.d, RATE ]
endfor
;;
;; Create and open the new CK file.
;;
cspice_ckopn, CK3, IFNAME, NCOMCH, handle
;;
;; Create an array start times for the interpolation intervals.
;; The end time for a particular interval is determined as the
;; time of the final data value prior in time to the next start
;; time.
;;
numint = MAXREC/2
starts = dblarr( numint )
for i = 0, (numint-1) do begin
starts[i] = sclkdp[2*i]
endfor
;;
;; Set the segment boundaries equal to the first and last
;; time in the segment.
;;
begtim = sclkdp[ 0]
endtim = sclkdp[MAXREC-1]
;;
;; Enter the information to go in the segment descriptor.
;;
;; This segment contains angular velocity.
;;
avflag = SPICETRUE
;;
;; All information ready to write. Write to a CK type 3 segment
;; to the file indicated by `handle'.
;;
cspice_ckw03, handle, $
begtim, $
endtim, $
INST , $
REF, $
avflag, $
SEGID , $
sclkdp, $
quats, $
av, $
starts
;;
;; SAFELY close the file
;;
cspice_ckcls, handle
END
When this program is executed, no output is presented on
screen. After run completion, a new CK file exists in the
output directory.
For a detailed description of a type 3 CK segment please see the
CK Required Reading.
This routine relieves the user from performing the repetitive
calls to the DAF routines necessary to construct a CK segment.
Quaternion Styles
-----------------
There are different "styles" of quaternions used in
science and engineering applications. Quaternion styles
are characterized by
- The order of quaternion elements
- The quaternion multiplication formula
- The convention for associating quaternions
with rotation matrices
Two of the commonly used styles are
- "SPICE"
> Invented by Sir William Rowan Hamilton
> Frequently used in mathematics and physics textbooks
- "Engineering"
> Widely used in aerospace engineering applications
Icy routine interfaces ALWAYS use SPICE quaternions.
Quaternions of any other style must be converted to SPICE
quaternions before they are passed to Icy routines.
Relationship between SPICE and Engineering Quaternions
------------------------------------------------------
Let `m' be a rotation matrix such that for any vector `v',
m*v
is the result of rotating `v' by theta radians in the
counterclockwise direction about unit rotation axis vector `a'.
Then the SPICE quaternions representing `m' are
(+/-) ( cos(theta/2),
sin(theta/2) a[0],
sin(theta/2) a[1],
sin(theta/2) a[2] )
while the engineering quaternions representing `m' are
(+/-) ( -sin(theta/2) a[0],
-sin(theta/2) a[1],
-sin(theta/2) a[2],
cos(theta/2) )
For both styles of quaternions, if a quaternion q represents
a rotation matrix `m', then -q represents `m' as well.
Given an engineering quaternion
qeng = ( q0, q1, q2, q3 )
the equivalent SPICE quaternion is
qspice = ( q3, -q0, -q1, -q2 )
Associating SPICE Quaternions with Rotation Matrices
----------------------------------------------------
Let `from' and `to' be two right-handed reference frames, for
example, an inertial frame and a spacecraft-fixed frame. Let the
symbols
v , v
from to
denote, respectively, an arbitrary vector expressed relative to
the `from' and `to' frames. Let `m' denote the transformation matrix
that transforms vectors from frame `from' to frame `to'; then
v = m * v
to from
where the expression on the right hand side represents left
multiplication of the vector by the matrix.
Then if the unit-length SPICE quaternion q represents `m', where
q = (q0, q1, q2, q3)
the elements of `m' are derived from the elements of q as follows:
.- -.
| 2 2 |
| 1 - 2*( q2 + q3 ) 2*(q1*q2 - q0*q3) 2*(q1*q3 + q0*q2) |
| |
| |
| 2 2 |
m = | 2*(q1*q2 + q0*q3) 1 - 2*( q1 + q3 ) 2*(q2*q3 - q0*q1) |
| |
| |
| 2 2 |
| 2*(q1*q3 - q0*q2) 2*(q2*q3 + q0*q1) 1 - 2*( q1 + q2 ) |
| |
`- -'
Note that substituting the elements of -q for those of q in the
right hand side leaves each element of `m' unchanged; this shows
that if a quaternion q represents a matrix `m', then so does the
quaternion -q.
To map the rotation matrix `m' to a unit quaternion, we start by
decomposing the rotation matrix as a sum of symmetric
and skew-symmetric parts:
2
m = [ i + (1-cos(theta)) omega ] + [ sin(theta) omega ]
symmetric skew-symmetric
`omega' is a skew-symmetric matrix of the form
.- -.
| 0 -n3 n2 |
| |
omega = | n3 0 -n1 |
| |
| -n2 n1 0 |
`- -'
The vector N of matrix entries (n1, n2, n3) is the rotation axis
of `m' and theta is M's rotation angle. Note that N and theta
are not unique.
Let
C = cos(theta/2)
s = sin(theta/2)
Then the unit quaternions `q' corresponding to `m' are
q = +/- ( C, S*n1, S*n2, S*n3 )
The mappings between quaternions and the corresponding rotations
are carried out by the Icy routines
cspice_q2m {quaternion to matrix}
cspice_m2q {matrix to quaternion}
cspice_m2q always returns a quaternion with scalar part greater than
or equal to zero.
SPICE Quaternion Multiplication Formula
---------------------------------------
Given a SPICE quaternion
q = ( q0, q1, q2, q3 )
corresponding to rotation axis `a' and angle theta as above, we can
represent `q' using "scalar + vector" notation as follows:
s = q0 = cos(theta/2)
v = ( q1, q2, q3 ) = sin(theta/2) * a
q = s + v
Let `q1' and `q2' be SPICE quaternions with respective scalar
and vector parts s1, s2 and v1, v2:
q1 = s1 + v1
q2 = s2 + v2
We represent the dot product of v1 and v2 by
<v1, v2>
and the cross product of v1 and v2 by
v1 x v2
Then the SPICE quaternion product is
q1*q2 = s1*s2 - <v1,v2> + s1*v2 + s2*v1 + (v1 x v2)
If `q1' and `q2' represent the rotation matrices `m1' and `m2'
respectively, then the quaternion product
q1*q2
represents the matrix product
m1*m2
1) If `handle' is not the handle of a C-kernel opened for writing,
an error is signaled by a routine in the call tree of this
routine.
2) If `segid' is more than 40 characters long, the error
SPICE(SEGIDTOOLONG) is signaled by a routine in the call tree
of this routine.
3) If `segid' contains any non-printable characters, the error
SPICE(NONPRINTABLECHARS) is signaled by a routine in the call
tree of this routine.
4) If the first encoded SCLK time is negative, the error
SPICE(INVALIDSCLKTIME) is signaled by a routine in the call
tree of this routine.
5) If the second encoded SCLK or any subsequent times, or if the
encoded SCLK times are not strictly increasing, the error
SPICE(TIMESOUTOFORDER) is signaled by a routine in the call
tree of this routine.
6) If `begtim' is greater than sclkdp[0] or `endtim' is less than
sclkdp[nrec-1], where `nrec' is the number of pointing records,
the error SPICE(INVALIDDESCRTIME) is signaled by a routine in
the call tree of this routine.
7) If the name of the reference frame is not one of those
supported by the Icy routine cspice_namfrm, the error
SPICE(INVALIDREFFRAME) is signaled by a routine in the call
tree of this routine.
8) If `nrec', the number of pointing records, is less than or
equal to 0, the error SPICE(INVALIDNUMREC) is signaled by a
routine in the call tree of this routine.
9) If `nints', the number of interpolation intervals, is less
than or equal to 0, the error SPICE(INVALIDNUMINT) is signaled
by a routine in the call tree of this routine.
10) If the encoded SCLK interval start times are not strictly
increasing, the error SPICE(TIMESOUTOFORDER) is signaled by a
routine in the call tree of this routine.
11) If an interval start time does not coincide with a time for
which there is an actual pointing instance in the segment, the
error SPICE(INVALIDSTARTTIME) is signaled by a routine in the
call tree of this routine.
12) This routine assumes that the rotation between adjacent
quaternions that are stored in the same interval has a
rotation angle of `theta' radians, where
0 <= theta < pi.
The routines that evaluate the data in the segment produced
by this routine cannot distinguish between rotations of `theta'
radians, where `theta' is in the interval [0, pi), and
rotations of
theta + 2 * k * pi
radians, where k is any integer. These `large' rotations
will yield invalid results when interpolated. You must
ensure that the data stored in the segment will not be
subject to this sort of ambiguity.
13) If any quaternion has magnitude zero, the error
SPICE(ZEROQUATERNION) is signaled by a routine in the call
tree of this routine.
14) If the start time of the first interval and the time of the
first pointing instance are not the same, the error
SPICE(TIMESDONTMATCH) is signaled by a routine in the call
tree of this routine.
15) If any of the input arguments, `handle', `begtim', `endtim',
`inst', `ref', `avflag', `segid', `sclkdp', `quats', `avvs' or
`starts', is undefined, an error is signaled by the IDL error
handling system.
16) If any of the input arguments, `handle', `begtim', `endtim',
`inst', `ref', `avflag', `segid', `sclkdp', `quats', `avvs' or
`starts', is not of the expected type, or it does not have the
expected dimensions and size, an error is signaled by the Icy
interface.
17) If the input vector arguments `sclkdp', `quats' and `avvs' do
not have the same dimension (N), an error is signaled by the
Icy interface.
This routine adds a type 3 segment to a C-kernel. The C-kernel
may be either a new one or an existing one opened for writing.
1) The creator of the segment is given the responsibility for
determining whether it is reasonable to interpolate between
two given pointing values.
2) This routine assumes that the rotation between adjacent
quaternions that are stored in the same interval has a
rotation angle of `theta' radians, where
0 <= theta < pi.
The routines that evaluate the data in the segment produced
by this routine cannot distinguish between rotations of `theta'
radians, where `theta' is in the interval [0, pi), and
rotations of
theta + 2 * k * pi
radians, where k is any integer. These `large' rotations will
yield invalid results when interpolated. You must ensure that
the data stored in the segment will not be subject to this
sort of ambiguity.
3) All pointing instances in the segment must belong to one and
only one of the intervals.
ICY.REQ
CK.REQ
DAF.REQ
SCLK.REQ
None.
J. Diaz del Rio (ODC Space)
E.D. Wright (JPL)
-Icy Version 1.0.1, 25-AUG-2021 (JDR)
Edited the header to comply with NAIF standard. Added
example's problem statement.
Added -Parameters, -Exceptions, -Files, -Restrictions,
-Literature_References and -Author_and_Institution sections, and
completed -Particulars section.
Removed reference to the routine's corresponding CSPICE header from
-Abstract section.
Added arguments' type and size information in the -I/O section.
-Icy Version 1.0.0, 16-JUN-2003 (EDW)
write CK type_3 pointing data segment
|