Skip to content

Commit

Permalink
Merge pull request #361 from lasp/feature/1270-cielim-interface
Browse files Browse the repository at this point in the history
Feature/1270 cielim interface
  • Loading branch information
thibaudteil authored Dec 12, 2024
2 parents fe77007 + 9b0fbfc commit 390971b
Show file tree
Hide file tree
Showing 8 changed files with 635 additions and 1,082 deletions.
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
bokeh
conan>=1.40.1, <2.00.0
datashader==0.16.3
delimited-protobuf==1.0.0
holoviews==1.19.1
hvplot==0.10.0
opencv-contrib-python
Expand All @@ -9,6 +10,7 @@ pandas
param==2.1.1
parse>=1.18.0
Pillow
protobuf==3.19.1
pytest
pytest-html
pytest-xdist
Expand Down
2 changes: 1 addition & 1 deletion src/simulation/vizard/cielimInterface/Custom.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
find_package(cppzmq CONFIG REQUIRED)
target_link_libraries(${TARGET_NAME} PRIVATE cppzmq::cppzmq)
target_link_libraries(${TARGET_NAME} PRIVATE vizMessage)
target_link_libraries(${TARGET_NAME} PRIVATE cielimMessage)
1,291 changes: 298 additions & 993 deletions src/simulation/vizard/cielimInterface/cielimInterface.cpp

Large diffs are not rendered by default.

118 changes: 74 additions & 44 deletions src/simulation/vizard/cielimInterface/cielimInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,82 +20,112 @@

#include "architecture/_GeneralModuleFiles/sys_model.h"
#include "architecture/messaging/messaging.h"
#include "architecture/msgPayloadDefC/CameraConfigMsgPayload.h"
#include "architecture/msgPayloadDefC/SCStatesMsgPayload.h"
#include "architecture/msgPayloadDefCpp/CameraModelMsgPayload.h"
#include "architecture/msgPayloadDefC/CameraImageMsgPayload.h"
#include "architecture/msgPayloadDefC/SpicePlanetStateMsgPayload.h"
#include "architecture/msgPayloadDefC/RWSpeedMsgPayload.h"
#include "architecture/msgPayloadDefC/EpochMsgPayload.h"
#include "architecture/utilities/bskLogging.h"
#include "architecture/utilities/simDefinitions.h"
#include "utilities/vizProtobuffer/vizMessage.pb.h"
#include "architecture/msgPayloadDefC/CelestialBodyParametersMsgPayload.h"
#include "architecture/msgPayloadDefC/CameraRenderingMsgPayload.h"
#include "architecture/msgPayloadDefCpp/OpNavCOBMsgPayload.h"

#include "architecture/utilities/rigidBodyKinematics.hpp"
#include "utilities/vizProtobuffer/cielimMessage.pb.h"
#include "simulation/vizard/cielimInterface/zmqConnector.h"
#include "simulation/vizard/_GeneralModuleFiles/vizStructures.h"

#include <google/protobuf/util/delimited_message_util.h>
#include <google/protobuf/io/coded_stream.h>
#include <fstream>
#include <vector>
#include <zmq.h>
#include <iostream>
#include <filesystem>

enum class ClosedLoopMode {
OPEN_LOOP = 0,
ALL_FRAMES = 1,
REQUESTED_FRAMES = 2
};

/*! Defines a data structure for the spacecraft state messages and ID's.
class MessageStatus{
public:
uint64_t lastTimeTag = 0xFFFFFFFFFFFFFFFF; //!< [ns] The previous read time-tag for msg
bool dataFresh = false; //!< [-] Flag indicating that new data has been read
};

/*! Structure defining vizard gravity body values */
class SpiceBody{
public:
std::string name{}; //!< [-] celestial body name
ReadFunctor<SpicePlanetStateMsgPayload> spiceStateMessage{}; //!< [-] celestial body name
SpicePlanetStateMsgPayload spiceStatePayload{}; //!< [-] celestial body name
bool isCentralBody = false; //!< [-] celestial body name
};

/*! @brief The interface to Cielim via ZMQ and protobuffers
*/
class CielimInterface : public SysModel {
public:
CielimInterface();
~CielimInterface();

void reset(uint64_t currentSimNanos) override;
void updateState(uint64_t currentSimNanos) override;
void readBskMessages();
void writeProtobuffer(uint64_t currentSimNanos);
void addCamMsgToModule(Message<CameraConfigMsgPayload> *tmpMsg);

void setOpNavMode(ClosedLoopMode mode);
ClosedLoopMode getOpNavMode() const;
int64_t getFrameNumber() const;
void setSaveFile(const std::string &pathAndFilename);
std::string getSaveFilename() const;
void closeProtobufFile();
void setLiveStream(bool liveStreaming);
void setPortNumber(std::string port);
void addCelestialBody(const SpiceBody &celestialBodiesList);
std::vector<SpiceBody> getCelestialBodies() const;

std::vector<VizSpacecraftData> scData; //!< [-] vector of spacecraft data containers
std::vector<ReadFunctor<SpicePlanetStateMsgPayload>> spiceInMsgs; //!< [-] vector of input messages of planet Spice data
std::vector<LocationPbMsg *> locations; //!< [] vector of ground or spacecraft locations
std::vector<GravBodyInfo> gravBodyInformation; //!< [-] vector of gravitational body info
std::vector<Message<CameraImageMsgPayload>*> opnavImageOutMsgs; //!< vector of vizard instrument camera output messages

bool saveFile{false}; //!< [Bool] Set True if Vizard should save a file of the data.
bool liveStream{false}; //!< [Bool] Set True if Vizard should receive a live stream of BSK data.
std::vector<void* >bskImagePtrs; /*!< [RUN] vector of permanent pointers for the images to be used in BSK
without relying on ZMQ because ZMQ will free it (whenever, who knows) */

std::vector<ReadFunctor<CameraConfigMsgPayload>> cameraConfInMsgs; //!< [-] vector of incoming camera data messages
std::vector<MsgCurrStatus> cameraConfMsgStatus; //!< [-] vector of msg status of incoming camera data
std::vector<CameraConfigMsgPayload> cameraConfigBuffers; //!< [-] vector of Camera config buffers

std::string protoFilename; //!< Filename for where to save the protobuff message
VizSettings settings; //!< [-] container for the Viz settings that can be specified from BSK
LiveVizSettings liveSettings; //!< [-] container for Viz settings that are updated on each time step
ReadFunctor<SCStatesMsgPayload> spacecraftMessage; //!< [-] vector of spacecraft data containers
ReadFunctor<CameraModelMsgPayload> cameraModelMessage; //!< [-] incoming camera data message
ReadFunctor<CameraRenderingMsgPayload > cameraRenderingMessage; //!< [-] camera rendering message
ReadFunctor<CelestialBodyParametersMsgPayload> celestialParametersMessage; //!< [-] celestial body parameters
ReadFunctor<EpochMsgPayload> epochMessage; //!< [-] simulation epoch date/time input msg

ReadFunctor<EpochMsgPayload> epochInMsg; //!< [-] simulation epoch date/time input msg
MsgCurrStatus epochMsgStatus; //!< [-] ID of the epoch msg
EpochMsgPayload epochMsgBuffer{}; //!< [-] epoch msg data

BSKLogger bskLogger; //!< [-] BSK Logging object
Message<CameraImageMsgPayload> imageOutMessage; //!< vector of vizard instrument camera output messages
Message<OpNavCOBMsgPayload> centerOfBrightnessOutMessage; //!< The true image center of brightness output message

private:
ZmqConnector connector;
void requestImage(uint64_t currentSimNanos); //!< request image and store it in output image message
bool shouldRequestACameraImage(uint64_t currentSimNanos) const;

bool saveFile{false}; //!< [Bool] Set True if Vizard should save a file of the data.
bool liveStream{false}; //!< [Bool] Set True if Vizard should receive a live stream of BSK data.
void* imagePointer; /*!< [RUN] permanent pointers for the images to be used
without relying on ZMQ because ZMQ will free it (whenever, who knows) */
ZmqConnector connector{};
ClosedLoopMode opNavMode{ClosedLoopMode::ALL_FRAMES}; /*!< [int] Set if Unity/Viz couple in direct communication. */
int64_t frameNumber{-1}; //!< Number of frames that have been updated for TimeStamp message
std::vector<MsgCurrStatus> spiceInMsgStatus; //!< [-] status of the incoming planets' spice data messages
std::vector <SpicePlanetStateMsgPayload> spiceMessage; //!< [-] Spice message copies
std::ofstream *outputStream{}; //!< [-] Output file stream opened in reset
void requestImage(size_t camCounter, uint64_t currentSimNanos); //!< request image from Vizard and store it in output img msg
vizProtobufferMessage::VizMessage::VizSettingsPb* collectVizSettings();
vizProtobufferMessage::VizMessage::LiveVizSettingsPb* collectVizLiveSettings();

void readRWConstellationMessages(VizSpacecraftData &scIt) const;
void readThrusterMessages(VizSpacecraftData &scIt) const;
void readCSSMessages(VizSpacecraftData &scIt) const;
bool shouldRequestACameraImage(uint64_t currentSimNanos) const;

SCStatesMsgPayload spacecraftPayload{}; //!< [-] vector of spacecraft data containers
MessageStatus spacecraftMessageStatus{}; //!< [-] message status of spacecraft data

EpochMsgPayload epochPayload{}; //!< [-] epoch msg data
MessageStatus epochMessageStatus{}; //!< [-] ID of the epoch msg

std::vector<SpicePlanetStateMsgPayload> spiceBodyPayloads; //!< [-] payloads of planet Spice data
std::vector<MessageStatus> spiceBodyMessageStatus; //!< [-] status of the incoming planets' spice data
std::vector<SpiceBody> celestialBodiesList; //!< [-] celestial body names

CameraModelMsgPayload cameraModelPayload{}; //!< [-] camera config buffers
MessageStatus cameraModelMessageStatus{}; //!< [-] message status of incoming camera data

CelestialBodyParametersMsgPayload celestialParametersPayload{}; //!< [-] buffer for celestial parameters
MessageStatus celestialParametersMessageStatus{}; //!< [-] message status of celestial parameter message

CameraRenderingMsgPayload cameraRenderingPayload{}; //!< [-] buffer for camera rendering settings
MessageStatus cameraRenderingMessageStatus{}; //!< [-] message status of the camera rendering message

std::string protoFilename{}; //!< Filename for where to save the protobuff message
std::ofstream outputStream{}; //!< [-] Output file stream opened in reset
};

#endif /* CIELIM_INTERFACE_H */
31 changes: 4 additions & 27 deletions src/simulation/vizard/cielimInterface/cielimInterface.i
Original file line number Diff line number Diff line change
Expand Up @@ -30,40 +30,17 @@ from Basilisk.architecture.swig_common_model import *
%include "sys_model.h"
%include "std_vector.i"

// Instantiate templates used by example
namespace std {
%template(PointLineConfig) vector<PointLine>;
%template(LocationConfig) vector<LocationPbMsg *>;
%template(CustomModelConfig) vector<CustomModel>;
%template(ActuatorGuiSettingsConfig) vector<ActuatorGuiSettings>;
%template(InstrumentGuiSettingsConfig) vector<InstrumentGuiSettings>;
%template(KeepOutInConeConfig) vector<KeepOutInCone>;
%template(StdCameraConfig) vector<StdCameraSettings>;
%template(VizSCVector) vector<VizSpacecraftData>;
%template(ThrClusterVector) vector<ThrClusterMap>;
%template(GravBodyInfoVector) vector<GravBodyInfo>;
%template(GenericSensorVector) vector<GenericSensor *>;
%template(LightVector) vector<Light *>;
%template(TransceiverVector) vector<Transceiver *>;
%template(GenericStorageVector) vector<GenericStorage *>;
%template(MultiSphereVector) vector<MultiSphere *>;
%template(EllipsoidVector) vector<Ellipsoid *>;
}

%include "cielimInterface.h"
%include "simulation/vizard/_GeneralModuleFiles/vizStructures.h"

%include "architecture/msgPayloadDefC/CameraConfigMsgPayload.h"
%include "architecture/msgPayloadDefC/RWConfigLogMsgPayload.h"
%include "architecture/msgPayloadDefCpp/CameraModelMsgPayload.h"
%include "architecture/msgPayloadDefCpp/OpNavCOBMsgPayload.h"
%include "architecture/msgPayloadDefC/SCStatesMsgPayload.h"
%include "architecture/msgPayloadDefC/CameraImageMsgPayload.h"
%include "architecture/msgPayloadDefC/SpicePlanetStateMsgPayload.h"
%include "architecture/msgPayloadDefC/RWSpeedMsgPayload.h"
%include "architecture/msgPayloadDefC/EpochMsgPayload.h"

%include "architecture/msgPayloadDefCpp/CSSConfigLogMsgPayload.h"
%include "architecture/msgPayloadDefCpp/THROutputMsgPayload.h"
%include "architecture/msgPayloadDefCpp/ChargeMsmMsgPayload.h"
%include "architecture/msgPayloadDefC/CelestialBodyParametersMsgPayload.h"
%include "architecture/msgPayloadDefC/CameraRenderingMsgPayload.h"

%pythoncode %{
import sys
Expand Down
Loading

0 comments on commit 390971b

Please sign in to comment.