Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/1096 protobuffer update #353

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ src/cmake-build-debug/*
supportData/*/__init__.py
src/utilities/MonteCarlo/__init__.py
src/utilities/vizProtobuffer/__init__.py
src/utilities/vizProtobuffer/vizMessage.pb.cc
src/utilities/vizProtobuffer/vizMessage.pb.h
src/utilities/vizProtobuffer/*.pb.cc
src/utilities/vizProtobuffer/*.pb.h
src/utilities/vizProtobuffer/*.pb2.py
externalTools/fswAuto/autosetter/sets/*
externalTools/fswAuto/autowrapper/wraps/*
**/outputFiles/*
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@
typedef struct {
char bodyName[MAX_STRING_LENGTH];
char shapeModel[MAX_STRING_LENGTH];
double sigma_BN[3];
double perlinNoise;
double proceduralRocks;
char brdf[MAX_STRING_LENGTH];
double reflectanceParameters[MAX_PARAMETER_LENGTH];
double meanRadius;
double principalAxisDistortion;
double principalAxisDistortion[3];
}CelestialBodyParametersMsgPayload;

#endif //CELESTIAL_BODY_PARAMETERS
3 changes: 1 addition & 2 deletions src/architecture/msgPayloadDefCpp/CameraModelMsgPayload.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ typedef struct {
double bodyToCameraMrp[3]; //!< [-] MRP defining the orientation of the camera frame relative to the body frame */
double focalLength;
int gaussianPointSpreadFunction; //!< Size of square Gaussian kernel to model point spread function, must be odd
double cosmicRayFrequency; //!< Frequency at which cosmic rays can strike the camera
double exposureTime; //!< [s] Exposure time for each image taken
double readNoise; //!< Read noise standard deviation
double systemGain; //!< Mapping from current to pixel intensity
bool enableStrayLight; //!< Add basic stray light modelling to images
}CameraModelMsgPayload;

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ void CenterOfBrightness::UpdateState(uint64_t CurrentSimNanos)
cobBuffer.valid = true;
cobBuffer.timeTag = this->sensorTimeTag;
cobBuffer.cameraID = imageBuffer.cameraID;
cobBuffer.centerOfBrightness[0] = cobData.first[0];
cobBuffer.centerOfBrightness[1] = cobData.first[1];
cobBuffer.centerOfBrightness[0] = cobData.first[0] + 0.5;
cobBuffer.centerOfBrightness[1] = cobData.first[1] + 0.5;
cobBuffer.pixelsFound = static_cast<int32_t> (locations.size());
}
cobBuffer.rollingAverageBrightness = averageBrightnessNew;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void CobConverter::Reset(uint64_t CurrentSimNanos)
*/
void CobConverter::UpdateState(uint64_t CurrentSimNanos)
{
CameraConfigMsgPayload cameraSpecs = this->cameraConfigInMsg();
CameraModelMsgPayload cameraSpecs = this->cameraConfigInMsg();
OpNavCOBMsgPayload cobMsgBuffer = this->opnavCOBInMsg();
NavAttMsgPayload navAttBuffer = this->navAttInMsg();
EphemerisMsgPayload ephemBuffer = this->ephemInMsg();
Expand All @@ -83,7 +83,7 @@ void CobConverter::UpdateState(uint64_t CurrentSimNanos)
/*! - Extract rotations from relevant messages */
double CB[3][3];
double BN[3][3];
MRP2C(cameraSpecs.sigma_CB, CB);
MRP2C(cameraSpecs.bodyToCameraMrp, CB);
Eigen::Matrix3d dcm_CB = c2DArray2EigenMatrix3d(CB);
MRP2C(navAttBuffer.sigma_BN, BN);
Eigen::Matrix3d dcm_BN = c2DArray2EigenMatrix3d(BN);
Expand All @@ -92,7 +92,7 @@ void CobConverter::UpdateState(uint64_t CurrentSimNanos)

/*! - camera parameters */
double alpha = 0;
double fieldOfView = cameraSpecs.fieldOfView;
double fieldOfView = cameraSpecs.fieldOfView[0];
double resolutionX = cameraSpecs.resolution[0];
double resolutionY = cameraSpecs.resolution[1];
double pX = 2.*tan(fieldOfView/2.0);
Expand Down Expand Up @@ -234,7 +234,7 @@ void CobConverter::UpdateState(uint64_t CurrentSimNanos)
comMsgBuffer.objectPixelRadius = int(Rc);
comMsgBuffer.phaseAngle = alphaPA;
comMsgBuffer.sunDirection = phi;
comMsgBuffer.cameraID = cameraSpecs.cameraID;
comMsgBuffer.cameraID = cameraSpecs.cameraId;
comMsgBuffer.timeTag = cobMsgBuffer.timeTag;
comMsgBuffer.valid = validCOM;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "architecture/utilities/avsEigenSupport.h"
#include "architecture/messaging/messaging.h"

#include "architecture/msgPayloadDefC/CameraConfigMsgPayload.h"
#include "architecture/msgPayloadDefCpp/CameraModelMsgPayload.h"
#include "architecture/msgPayloadDefC/NavAttMsgPayload.h"
#include "architecture/msgPayloadDefC/EphemerisMsgPayload.h"
#include "architecture/msgPayloadDefCpp/OpNavCOBMsgPayload.h"
Expand All @@ -38,6 +38,7 @@
#include "architecture/utilities/linearAlgebra.h"
#include "architecture/utilities/avsEigenMRP.h"
#include "architecture/utilities/bskLogging.h"
#include "architecture/utilities/macroDefinitions.h"

enum class PhaseAngleCorrectionMethod {NoCorrection, Lambertian, Binary};

Expand Down Expand Up @@ -78,7 +79,7 @@ class CobConverter: public SysModel {
Message<OpNavCOMMsgPayload> opnavCOMOutMsg;
ReadFunctor<OpNavCOBMsgPayload> opnavCOBInMsg;
ReadFunctor<FilterMsgPayload> opnavFilterInMsg;
ReadFunctor<CameraConfigMsgPayload> cameraConfigInMsg;
ReadFunctor<CameraModelMsgPayload> cameraConfigInMsg;
ReadFunctor<NavAttMsgPayload> navAttInMsg;
ReadFunctor<EphemerisMsgPayload> ephemInMsg;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,9 @@ from Basilisk.architecture.swig_common_model import *

%include "cobConverter.h"

%include "architecture/msgPayloadDefC/CameraConfigMsgPayload.h"
struct CameraConfigMsg_C;
%include "architecture/msgPayloadDefCpp/CameraModelMsgPayload.h"
%include "architecture/msgPayloadDefC/NavAttMsgPayload.h"
struct NavAttMsg_C;
%include "architecture/msgPayloadDefC/EphemerisMsgPayload.h"
struct EphemerisMsg_C;

%include "architecture/msgPayloadDefCpp/OpNavUnitVecMsgPayload.h"
%include "architecture/msgPayloadDefCpp/OpNavCOBMsgPayload.h"
Expand Down
9 changes: 3 additions & 6 deletions src/simulation/sensors/camera/_UnitTest/test_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,9 @@ def cameraTest(show_plots, image, gauss, darkCurrent, saltPepper, cosmic, blurSi
module.setImageCadence(1)
module.setFocalLength(2.1)
module.setGaussianPointSpreadFunction(3)
module.setCosmicRayFrequency(2.2)
module.setReadNoise(2.3)
module.setSystemGain(3.3)
module.setEnableStrayLight(True)
module.setExposureTime(1.1)

# Noise parameters
module.gaussian = gauss
Expand Down Expand Up @@ -228,14 +227,12 @@ def cameraTest(show_plots, image, gauss, darkCurrent, saltPepper, cosmic, blurSi
"Test failed camera focal length")
np.testing.assert_equal(dataLogCameraModel.gaussianPointSpreadFunction, module.getGaussianPointSpreadFunction(),
"Test failed size of square Gaussian kernel to model point spread function")
np.testing.assert_equal(dataLogCameraModel.cosmicRayFrequency, module.getCosmicRayFrequency(),
"Test failed frequency at which cosmic rays can strike the camera")
np.testing.assert_equal(dataLogCameraModel.readNoise, module.getReadNoise(),
"Test failed read noise standard deviation")
np.testing.assert_equal(dataLogCameraModel.systemGain, module.getSystemGain(),
"System failed mapping from current to pixel intensity")
np.testing.assert_equal(dataLogCameraModel.enableStrayLight, module.getEnableStrayLight(),
"Test failed add basic stray light modelling to images")
np.testing.assert_equal(dataLogCameraModel.exposureTime, module.getExposureTime(),
"System failed exposure time")

# Error check for corruption
err = np.linalg.norm(np.linalg.norm(input_image, axis=2) - np.linalg.norm(output_image, axis=2)) / np.linalg.norm(
Expand Down
38 changes: 10 additions & 28 deletions src/simulation/sensors/camera/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,9 @@ void Camera::UpdateState(uint64_t currentSimNanos)
eigenVector3d2CArray(this->bodyToCameraMrp, cameraModelMsg.bodyToCameraMrp);
cameraModelMsg.focalLength = this->focalLength;
cameraModelMsg.gaussianPointSpreadFunction = this->gaussianPointSpreadFunction;
cameraModelMsg.cosmicRayFrequency = this->cosmicRayFrequency;
cameraModelMsg.readNoise = this->readNoise;
cameraModelMsg.systemGain = this->systemGain;
cameraModelMsg.enableStrayLight = this->enableStrayLight;
cameraModelMsg.exposureTime = this->exposureTime;

/*! - Update the camera config data no matter if an image is present*/
this->cameraConfigOutMsg.write(&cameraMsg, this->moduleID, currentSimNanos);
Expand Down Expand Up @@ -489,7 +488,7 @@ Eigen::Vector2i Camera::getResolution() const {
@return void
*/
void Camera::setImageCadence(const uint64_t& cameraImageCadence) {
this->renderRate = cameraImageCadence;
this->imageCadence = cameraImageCadence;
}

/*! Get the frame time interval at which to capture images in units of nanosecond
Expand Down Expand Up @@ -577,23 +576,6 @@ int Camera::getGaussianPointSpreadFunction() const {
return this->gaussianPointSpreadFunction;
}

/*! Set the frequency at which cosmic rays can strike the camera
@param cameraCosmicRayFrequency double
@return void
*/

void Camera::setCosmicRayFrequency(const double cameraCosmicRayFrequency) {
this->cosmicRayFrequency = cameraCosmicRayFrequency;
}

/*! Get the frequency at which cosmic rays can strike the camera
@return double cosmicRayFrequency
*/

double Camera::getCosmicRayFrequency() const{
return this->cosmicRayFrequency;
}

/*! Set the read noise standard deviation
@param cameraReadNoise double
@return void
Expand Down Expand Up @@ -628,19 +610,19 @@ double Camera::getSystemGain() const {
return this->systemGain;
}

/*! Set the mapping from current to pixel intensity
@param cameraEnableStrayLight bool
/*! Set the camera epxosure time in seconds
@param openExposureTime double
@return void
*/

void Camera::setEnableStrayLight(const bool cameraEnableStrayLight) {
this->enableStrayLight = cameraEnableStrayLight;
void Camera::setExposureTime(const double openExposureTime) {
this->exposureTime = openExposureTime;
}

/*! Set the mapping from current to pixel intensity
@return bool enableStrayLight
/*! Get the mapping from current to pixel intensity
@return double exposureTime
*/

bool Camera::getEnableStrayLight() const {
return this->enableStrayLight;
double Camera::getExposureTime() const {
return this->exposureTime;
}
10 changes: 4 additions & 6 deletions src/simulation/sensors/camera/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,13 @@ class Camera: public SysModel {
double getFocalLength() const;
void setGaussianPointSpreadFunction(int cameraGaussianPointSpreadFunction);
int getGaussianPointSpreadFunction() const;
void setCosmicRayFrequency(double cameraCosmicRayFrequency);
double getCosmicRayFrequency() const;
void setReadNoise(double cameraReadNoise);
double getReadNoise() const;
void setSystemGain(double cameraGain);
double getSystemGain() const;
void setEnableStrayLight(bool cameraEnablesStrayLight);
bool getEnableStrayLight() const;
void setExposureTime(double exposureTime);
double getExposureTime() const;


private:
std::string parentSpacecraftName{}; //!< [-] Name of the parent body to which the camera should be attached
Expand All @@ -96,10 +95,9 @@ class Camera: public SysModel {
Eigen::Vector3d bodyToCameraMrp{}; //!< [-] MRP defining the orientation of the camera frame relative to the body frame
double focalLength{}; //!< Camera focal length
int gaussianPointSpreadFunction{}; //!< Size of square Gaussian kernel to model point spread function, must be odd
double cosmicRayFrequency{}; //!< Frequency at which cosmic rays can strike the camera
double readNoise{}; //!< Read noise standard deviation
double systemGain{}; //!< Mapping from current to pixel intensity
bool enableStrayLight{}; //!< Add basic stray light modelling to images
double exposureTime{1}; //!< Mapping from current to pixel intensity

public:
std::string filename{}; //!< Filename for module to read an image directly
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)
Loading
Loading