Skip to content

Commit ca36a2f

Browse files
author
tteil
committed
retrieve true COB from interface
1 parent f985a14 commit ca36a2f

File tree

5 files changed

+41
-15
lines changed

5 files changed

+41
-15
lines changed

src/simulation/vizard/cielimInterface/cielimInterface.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ void CielimInterface::writeProtobuffer(uint64_t currentSimNanos) {
288288
/*! - If the camera is requesting periodic images, request them */
289289
if (this->opNavMode != ClosedLoopMode::OPEN_LOOP &&
290290
currentSimNanos % this->cameraModelPayload.renderRate == 0 &&
291-
this->cameraModelPayload.isOn == 1) {
291+
this->cameraModelPayload.renderRate > 0) {
292292
this->requestImage(currentSimNanos);
293293

294294
}
@@ -319,7 +319,7 @@ void CielimInterface::updateState(uint64_t currentSimNanos) {
319319
* */
320320
bool CielimInterface::shouldRequestACameraImage(uint64_t currentSimNanos) const{
321321
if (currentSimNanos % this->cameraModelPayload.renderRate == 0 &&
322-
this->cameraModelPayload.isOn == 1 /*|| this->firstPass < 11*/) {
322+
this->cameraModelPayload.renderRate > 0) {
323323
return true;
324324
}
325325
return false;
@@ -341,6 +341,16 @@ void CielimInterface::requestImage(uint64_t currentSimNanos) {
341341
imagePayload.imageType = 3;
342342
if (imageData.imageBufferLength > 0) { imagePayload.valid = 1; }
343343
this->imageOutMessage.write(&imagePayload, this->moduleID, currentSimNanos);
344+
345+
OpNavCOBMsgPayload centerOfBrightnessPayload = {};
346+
centerOfBrightnessPayload.timeTag = currentSimNanos;
347+
centerOfBrightnessPayload.cameraID = this->cameraModelPayload.cameraId;
348+
if (imageData.centerOfBrightness) {
349+
centerOfBrightnessPayload.valid = true;
350+
centerOfBrightnessPayload.centerOfBrightness[0] = imageData.centerOfBrightness.value()[0] + 0.5;
351+
centerOfBrightnessPayload.centerOfBrightness[1] = imageData.centerOfBrightness.value()[1] + 0.5;
352+
}
353+
this->centerOfBrightnessOutMessage.write(&centerOfBrightnessPayload, this->moduleID, currentSimNanos);
344354
}
345355

346356
/*! Get the communication mode

src/simulation/vizard/cielimInterface/cielimInterface.h

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "architecture/msgPayloadDefC/EpochMsgPayload.h"
2828
#include "architecture/msgPayloadDefC/CelestialBodyParametersMsgPayload.h"
2929
#include "architecture/msgPayloadDefC/CameraRenderingMsgPayload.h"
30+
#include "architecture/msgPayloadDefCpp/OpNavCOBMsgPayload.h"
3031

3132
#include "architecture/utilities/rigidBodyKinematics.hpp"
3233
#include "utilities/vizProtobuffer/cielimMessage.pb.h"
@@ -90,6 +91,7 @@ class CielimInterface : public SysModel {
9091
ReadFunctor<EpochMsgPayload> epochMessage; //!< [-] simulation epoch date/time input msg
9192

9293
Message<CameraImageMsgPayload> imageOutMessage; //!< vector of vizard instrument camera output messages
94+
Message<OpNavCOBMsgPayload> centerOfBrightnessOutMessage; //!< The true image center of brightness output message
9395

9496
private:
9597
void requestImage(uint64_t currentSimNanos); //!< request image and store it in output image message

src/simulation/vizard/cielimInterface/cielimInterface.i

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ from Basilisk.architecture.swig_common_model import *
3333
%include "cielimInterface.h"
3434

3535
%include "architecture/msgPayloadDefCpp/CameraModelMsgPayload.h"
36+
%include "architecture/msgPayloadDefCpp/OpNavCOBMsgPayload.h"
3637
%include "architecture/msgPayloadDefC/SCStatesMsgPayload.h"
3738
%include "architecture/msgPayloadDefC/CameraImageMsgPayload.h"
3839
%include "architecture/msgPayloadDefC/SpicePlanetStateMsgPayload.h"

src/simulation/vizard/cielimInterface/zmqConnector.cpp

+23-12
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,25 @@ void ZmqConnector::message_buffer_deallocate(void *data, void *hint)
7373
free(data);
7474
}
7575

76-
ImageData ZmqConnector::requestImage(size_t cameraId) {
77-
std::string cmdMsg = "REQUEST_IMAGE_";
78-
cmdMsg += std::to_string(cameraId);
79-
void* img_message = malloc(cmdMsg.length() * sizeof(char));
80-
memcpy(img_message, cmdMsg.c_str(), cmdMsg.length());
81-
82-
auto imageRequestMessage = zmq::message_t(img_message,
83-
cmdMsg.length(),
84-
ZmqConnector::message_buffer_deallocate,
85-
nullptr);
86-
this->requesterSocket->send(imageRequestMessage, zmq::send_flags::none);
76+
ImageData ZmqConnector::requestImage(size_t cameraId, bool shouldReturnImage) {
77+
auto cameraIdAsString = std::to_string(cameraId);
78+
zmq::message_t msgCameraId(cameraIdAsString);
79+
zmq::message_t msgShouldReturnImage(std::to_string(shouldReturnImage).c_str(), sizeof(char));
80+
auto res = this->requesterSocket->send(zmq::str_buffer("REQUEST_IMAGE"),
81+
zmq::send_flags::sndmore);
82+
this->requesterSocket->send(msgCameraId, zmq::send_flags::sndmore);
83+
this->requesterSocket->send(msgShouldReturnImage, zmq::send_flags::none);
8784

8885
// SAFETY: it's okay to discard these [[nodiscard]] values because
8986
// 1) the returned optional could only be empty if ZeroMQ fails due to EAGAIN on a non-blocking socket;
9087
// but our socket is not non-blocking
9188
// 2) the returned length in the (present) optional is recoverable from the given message's `.size()` method.
9289
auto imageLengthMessage = zmq::message_t();
9390
auto imageMessage = zmq::message_t();
91+
auto centerOfBrightnessX = zmq::message_t();
92+
auto centerOfBrightnessY = zmq::message_t();
93+
auto cobYMsgSize = this->requesterSocket->recv(centerOfBrightnessY, zmq::recv_flags::none);
94+
auto cobXMsgSize = this->requesterSocket->recv(centerOfBrightnessX, zmq::recv_flags::none);
9495
static_cast<void>(this->requesterSocket->recv(imageLengthMessage, zmq::recv_flags::none));
9596
static_cast<void>(this->requesterSocket->recv(imageMessage, zmq::recv_flags::none));
9697

@@ -100,7 +101,17 @@ ImageData ZmqConnector::requestImage(size_t cameraId) {
100101
void* image = malloc(imageBufferLength*sizeof(char));
101102
memcpy(image, imagePoint, imageBufferLength*sizeof(char));
102103

103-
return ImageData{imageBufferLength, image};
104+
auto returnData = ImageData();
105+
returnData.imageBuffer = image;
106+
returnData.imageBufferLength = imageBufferLength;
107+
returnData.centerOfBrightness = std::nullopt;
108+
109+
if (cobXMsgSize.has_value()) {
110+
returnData.centerOfBrightness = Eigen::Vector2d(*centerOfBrightnessX.data<double>(),
111+
*centerOfBrightnessY.data<double>());
112+
}
113+
114+
return returnData;
104115
}
105116

106117

src/simulation/vizard/cielimInterface/zmqConnector.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222

2323
#include "cielimMessage.pb.h"
2424
#include <zmq.hpp>
25+
#include <Eigen/Core>
2526
#include <string>
2627

2728
struct ImageData{
2829
int32_t imageBufferLength;
2930
void *imageBuffer;
31+
std::optional<Eigen::Vector2d> centerOfBrightness;
3032
};
3133

3234
class ZmqConnector {
@@ -37,7 +39,7 @@ class ZmqConnector {
3739
void connect();
3840
[[nodiscard]] bool isConnected() const;
3941
void send(const cielimMessage::CielimMessage& messagePayload);
40-
ImageData requestImage(size_t cameraId);
42+
ImageData requestImage(size_t cameraId, bool shoudReturnImage=true);
4143
void setComPortNumber(std::string &portNumber);
4244
void ping();
4345

0 commit comments

Comments
 (0)