Module: dataFileToViz

Executive Summary

This module reads in simulation data of one or more spacecraft, likely created outside of Basilisk, and creates associated Basilisk messages such that Module: vizInterface can stream of save a Vizard compatible data file. This makes it possible to use Vizard to illustrate a simulation. The use of this module is demonstrates in scenarioDataToViz.

Module Assumptions and Limitations

The module currently reads in the spacecraft position, velocity and orientation states.

Message Connection Descriptions

The following messages are set directly within vizInterface. Additional messages are set within the VizSpacecraftData data structures for each spacecraft.

Module I/O Messages

Msg Variable Name

Msg Type

Description

scStateOutMsgs

SCStatesMsgPayload

Vector of spacecraft output messages

thrScOutMsgs

THROutputMsgPayload

(optional) vector of vectors of thruster output messages per spacecraft

rwScOutMsgs

RWConfigLogMsgPayload

(optional) vector of vectors of RW output messages per spacecraft

User Guide

The module assumes the data file is in plain text form and the following format:

  • time

  • inertial position states (m)

  • inertial velocity states (m/s)

  • inertial attitude state in terms of either MRPs, quaternions or 3-2-1 Euler angles (rad)

  • inertial angular velocity vector in radians per second (rad/s)

  • (optional) thruster force values (N)

  • (optional) RW Speed \(\Omega\) (rad/s) and RW motor torque \(u_s\) (N)

  • repeat on the same line for additional spacecraft

The required module configuration is:

testModule = dataFileToViz.DataFileToViz()
testModule.ModelTag = "testModule"
testModule.setNumOfSatellites(2)
testModule.dataFileName = "dataFile.dat"
unitTestSim.AddModelToTask(unitTaskName, testModule)

Note that setNumOfSatellites() must be called with at least 1 spacecraft.

The module is configurable with the following optional parameters:

Module Optional Parameters

Parameter

Default

Description

delimiter

” “

delimiter string that separates data on a line

convertPosToMeters

1000.0

conversion factor to convert position and velocity measures to meters and meters per second.

headerLine

True

Boolean flag if the data file contains a header line that should be dismissed

attitudeType

0

Specify the attitude coordinate set used in the data file. 0 - MRP, 1 - quaternions as \((q_0, q_1, q_2, q_3)\), and 2 - (3-2-1) Euler angles in radians

To add Thrusters to the setup, for each of the spacecraft included do the following steps. The spacecraft can contain a number of thruster clusters defined through ThrClusterMap. In the examle below, the spacecraft contains 2 clusters (ADCS and DV) which contain one thruster each.

# setup thruster cluster for the current spacecraft
thSetAdcs1 = dataFileToViz.ThrClusterMap()
# set the number of thruster in this cluster
thSetAdcs1.thrCount = 1
# set the thruster cluster tag label string
thSetAdcs1.thrTag = "adcs_sc_0"
# (Optional) set the color for the thruster visualization in this cluster.
thSetAdcs1.color = vizSupport.toRGBA255("red")

thSetDV1 = dataFileToViz.ThrClusterMap()
thSetDV1.thrCount = 1
thSetDV1.thrTag = "dv_sc_0"
thSetDV1.color = vizSupport.toRGBA255("blue")

# assign this thruster cluster to module
thList1 = [thSetAdcs1, thSetDV1]
testModule.appendThrClusterMap(dataFileToViz.VizThrConfig(thList1))

# add the position and orientation information for each thruster in this cluster
# ADCS1
testModule.appendThrPos([0, 0, 3.])  # thr location in B frame, meters
testModule.appendThrDir([0, 0, -1])  # thr force direction in B frame
testModule.appendThrForceMax(1.0)
# DV1
testModule.appendThrPos([0, 0, -3.])  # thr location in B frame, meters
testModule.appendThrDir([0, 0, 1])  # thr force direction in B frame
testModule.appendThrForceMax(1.0)

These steps must be done for each spacecraft in the data file. If a spacecraft does not have thrusters, then an empty thruster cluster vector must be added for that spacecraft. See test_dataFileToViz for an example on how to configure for thruster information.

testModule.appendThrClusterMap([])

To add RW devices to the list, for each spacecraft you must specify the number of RW that it contains through:

testModule.appendNumOfRWs(2)

Next, the RW position, spin axis direction, the wheel speed and the maximum motor torque value is setup using:

testModule.appendRwPos([0, 0, 0])
testModule.appendRwDir([1, 0, 0])
testModule.appendOmegaMax(3000.*macros.RPM)
testModule.appendUMax(0.5)

Repeat the above steps for each wheel.


class DataFileToViz : public SysModel
#include <dataFileToViz.h>

Defines a data structure for the spacecraft state messages and ID’s.

Public Functions

DataFileToViz()

DataFileToViz Constructor

~DataFileToViz()

DataFileToViz Destructor

void Reset(uint64_t CurrentSimNanos)

A Reset method to put the module back into a clean state

Parameters

CurrentSimNanos – The current sim time in nanoseconds

void UpdateState(uint64_t CurrentSimNanos)

Update this module at the task rate

Parameters

CurrentSimNanos – The current sim time

void appendThrPos(double pos_B[3])

Add a thruster 3d position vector to the list of thruster locations

void appendThrDir(double dir_B[3])

Add a thruster 3d unit direction vector to the list. The input vectors gets normalized before being added to the list.

void appendThrForceMax(double)

Add a thruster maximum force value to the list of thrusters.

void appendThrClusterMap(std::vector<ThrClusterMap> thrMsgData, std::vector<int> numThrPerCluster)

Add a thruster cluster map for each spacecraft

void appendRwPos(double pos_B[3])

Add a thruster 3d position vector to the list of thruster locations

void appendRwDir(double dir_B[3])

Add a RW spin axis unit direction vector to the list. The input vectors gets normalized before being added to the list.

void appendOmegaMax(double)

Add a RW wheel rate value to the list

void appendUMax(double)

Add a RW maximum motor torque value to the list

void setNumOfSatellites(int numSat)

set the number of satellites being read in

void appendNumOfRWs(int numRW)

Add a RW output msg list for each spacecraft

Public Members

std::string dataFileName

Name of the simulation data file.

std::vector<Message<SCStatesMsgPayload>*> scStateOutMsgs

vector of spacecraft state messages

std::string delimiter

delimiter string that separates data on a line

double convertPosToMeters

conversion factor to meters

bool headerLine

[bool] flag to mark first line as a header

int attitudeType

0 - MRP, 1 - EP or quaternions (q0, q1, q2, q3), 2 - (3-2-1) Euler angles

std::vector<std::vector<ThrClusterMap>> thrMsgDataSC

(Optional) vector of sets of thruster cluster mapping info

std::vector<std::vector<Message<THROutputMsgPayload>*>> thrScOutMsgs

(Optional) vector of spacecraft thruster output message vectors

std::vector<std::vector<Message<RWConfigLogMsgPayload>*>> rwScOutMsgs

(Optional) vector of sets of RW msg names, each entry is per SC

BSKLogger bskLogger

[-] BSK Logging object

Private Functions

void pullVector(std::istringstream *iss, double*)

pull a 3-d set of double values from the input stream

void pullVector4(std::istringstream *iss, double*)

pull a 4-d set of double values from the input stream

double pullScalar(std::istringstream *iss)

pull a double from the input stream

Private Members

std::vector<std::vector<int>> numThrPerCluster

vector containing list of numbers of thruster per cluster per spacecraft

std::ifstream fileHandle

file handle to the simulation data input file

std::vector<Eigen::Vector3d> thrPosList

[m] vector of thrust positions

std::vector<Eigen::Vector3d> thrDirList

[-] vector of thrust unit direction vectors in B-frame components

std::vector<double> thrForceMaxList

[-] vector of thrust maximum force values

std::vector<Eigen::Vector3d> rwPosList

[m] vector of RW positions

std::vector<Eigen::Vector3d> rwDirList

[-] vector of RW sprin axis unit direction vectors in B-frame components

std::vector<double> rwOmegaMaxList

[r/s] vector of RW maximum spin rate values

std::vector<double> rwUMaxList

[N] vector of RW maximum motor torque values values

int numRW = 0

&#8212; number of RWs across all spacecraft

int numThr = 0

&#8212; number of Thrusters across all spacecraft