Galaxis Codebase  1.0.0
Team Galaxis software stack for the Carolo Cup 2023 - ROS2 based software
VCINodeAsync Class Reference

#include <VCINode.hpp>

Inheritance diagram for VCINodeAsync:
Collaboration diagram for VCINodeAsync:

Public Member Functions

 VCINodeAsync ()
 

Private Member Functions

void camera_publish_loop ()
 

Private Attributes

AlviumAsyncCamera m_camera
 
image_transport::Publisher m_laneImagePublisher
 
rclcpp::Publisher< sensor_msgs::msg::Image >::SharedPtr m_imagePublisherNew
 
cv_bridge::CvImage m_imgBridge
 
com::SharedMemory m_sharedMemory
 
size_t m_imageSizeBytes = 512*256*3
 

Additional Inherited Members

- Protected Member Functions inherited from GalaxisNode
 GalaxisNode ()=delete
 
 GalaxisNode (std::string p_name, unsigned int p_heartbeatTimePeriod)
 
 GalaxisNode (std::string p_name)
 
template<typename MsgSPtr >
void tickSub (std::map< galaxis::serviceStates::State, std::function< void(const MsgSPtr)>> const *p_functionMapPtr, MsgSPtr const p_message)
 
template<typename... Args>
void tickPub (std::map< galaxis::serviceStates::State, std::function< void(Args...)>> const *p_functionMapPtr, Args... p_args)
 
void register_callback (std::function< void(galaxis::serviceStates::State)> p_function)
 
void service_state_callback (ServiceStateType::SharedPtr const p_msgSPtr)
 
galaxis::serviceStates::State get_current_service_state () const
 
void enable_parameters (std::function< rcl_interfaces::msg::SetParametersResult(const std::vector< rclcpp::Parameter > &)> callbackFunc)
 
void create_parameters (std::shared_ptr< json > configJsonSPtr)
 
json const & get_global_settings ()
 

Detailed Description

Definition at line 24 of file VCINode.hpp.

Constructor & Destructor Documentation

◆ VCINodeAsync()

VCINodeAsync::VCINodeAsync ( )

Definition at line 21 of file VCINode.cpp.

21  :
22  GalaxisNode("VCINodeAsync"), m_sharedMemory("/galaxis__camera") {
23  m_laneImagePublisher = image_transport::create_publisher(this, galaxis::ros::TOPIC_CAMERA_RAW);
24 
25  // rclcpp::QoS qos_params = get_qos_profile(QOS_BEST_EFFORT);
26  // m_imagePublisherNew = this->create_publisher<sensor_msgs::msg::Image>(galaxis::ros::TOPIC_CAMERA_RAW_BE, qos_params);
27 
28  int maxTries = 3;
29  while(m_sharedMemory.allocate(m_imageSizeBytes) == false && maxTries > 0) {
30  log_warning("Failed to allocate shared memory. Trying again (",maxTries,")");
31  std::this_thread::sleep_for(1000ms);
32  if(maxTries == 1) {
33  std::exit(-1);
34  }
35  maxTries--;
36  }
37 
38  maxTries = 60;
39  while(m_camera.start_grabbing_detached() == false) {
40  log_warning("Failed to initialize camera. Trying again (",maxTries,")");
41  std::this_thread::sleep_for(1000ms);
42  if(maxTries == 1) {
43  std::exit(-1);
44  }
45  maxTries--;
46  }
47 
48  std::thread(&VCINodeAsync::camera_publish_loop, this).detach();
49 }

References com::SharedMemory::allocate(), camera_publish_loop(), galaxis::utils::log_warning(), m_camera, m_imageSizeBytes, m_laneImagePublisher, m_sharedMemory, and AlviumAsyncCamera::start_grabbing_detached().

Here is the call graph for this function:

Member Function Documentation

◆ camera_publish_loop()

void VCINodeAsync::camera_publish_loop ( )
private

Definition at line 51 of file VCINode.cpp.

51  {
52  com::SharedData data;
53 
54  while(1) {
55  auto msg = m_camera.pop_image(true); // blocking
56 
57  if(msg == nullptr) {
58  log_warning("[ASYNC-VCINODE] camera_publish_loop: Image is nullptr.");
59  std::this_thread::sleep_for(1ms); // std::chrono_literals
60  continue;
61  }
62 
63  // write data via shared memory
64  data.tv_sec = msg->header.stamp.sec;
65  data.tv_nsec = msg->header.stamp.nanosec;
66  data.data = msg->data.data();
67  data.dataSize = msg->data.size();
69 
70  // m_imagePublisherNew->publish(*msg);
71  m_laneImagePublisher.publish(msg);
72 
73  log("[ASYNC-VCINODE] camera_publish_loop: Image published via Shared Memory and ROS2.");
74  log_debug("[ASYNC-VCINODE] camera_publish_loop: Timestamp sec.nsec:", msg->header.stamp.sec, ".",msg->header.stamp.nanosec);
75  }
76 }

References com::SharedData::data, com::SharedData::dataSize, galaxis::utils::log(), galaxis::utils::log_debug(), galaxis::utils::log_warning(), m_camera, m_laneImagePublisher, m_sharedMemory, AlviumAsyncCamera::pop_image(), com::SharedData::tv_nsec, com::SharedData::tv_sec, and com::SharedMemory::write_mutexed().

Referenced by VCINodeAsync().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_camera

AlviumAsyncCamera VCINodeAsync::m_camera
private

Definition at line 26 of file VCINode.hpp.

Referenced by camera_publish_loop(), and VCINodeAsync().

◆ m_imagePublisherNew

rclcpp::Publisher<sensor_msgs::msg::Image>::SharedPtr VCINodeAsync::m_imagePublisherNew
private

Definition at line 28 of file VCINode.hpp.

◆ m_imageSizeBytes

size_t VCINodeAsync::m_imageSizeBytes = 512*256*3
private

Definition at line 33 of file VCINode.hpp.

Referenced by VCINodeAsync().

◆ m_imgBridge

cv_bridge::CvImage VCINodeAsync::m_imgBridge
private

Definition at line 30 of file VCINode.hpp.

◆ m_laneImagePublisher

image_transport::Publisher VCINodeAsync::m_laneImagePublisher
private

Definition at line 27 of file VCINode.hpp.

Referenced by camera_publish_loop(), and VCINodeAsync().

◆ m_sharedMemory

com::SharedMemory VCINodeAsync::m_sharedMemory
private

Definition at line 32 of file VCINode.hpp.

Referenced by camera_publish_loop(), and VCINodeAsync().


The documentation for this class was generated from the following files:
galaxis::utils::log_warning
void log_warning(const Args &... args)
Definition: logger.hpp:41
com::SharedData::data
uint8_t * data
Definition: SharedMemory.hpp:20
com::SharedData::dataSize
size_t dataSize
Definition: SharedMemory.hpp:21
VCINodeAsync::m_sharedMemory
com::SharedMemory m_sharedMemory
Definition: VCINode.hpp:32
AlviumAsyncCamera::pop_image
std::shared_ptr< sensor_msgs::msg::Image > pop_image(bool blocking)
Definition: AsyncCamera.cpp:137
com::SharedMemory::write_mutexed
bool write_mutexed(com::SharedData const &data)
Definition: SharedMemory.cpp:126
com::SharedData::tv_sec
int32_t tv_sec
Definition: SharedMemory.hpp:18
com::SharedData::tv_nsec
uint32_t tv_nsec
Definition: SharedMemory.hpp:19
VCINodeAsync::camera_publish_loop
void camera_publish_loop()
Definition: VCINode.cpp:51
com::SharedMemory::allocate
bool allocate(size_t sizeBytes)
Definition: SharedMemory.cpp:34
GalaxisNode::GalaxisNode
GalaxisNode()=delete
VCINodeAsync::m_laneImagePublisher
image_transport::Publisher m_laneImagePublisher
Definition: VCINode.hpp:27
VCINodeAsync::m_imageSizeBytes
size_t m_imageSizeBytes
Definition: VCINode.hpp:33
com::SharedData
Definition: SharedMemory.hpp:17
galaxis::utils::log
void log(const Args &... args)
Definition: logger.hpp:33
galaxis::utils::log_debug
void log_debug(const Args &... args)
Definition: logger.hpp:62
AlviumAsyncCamera::start_grabbing_detached
bool start_grabbing_detached()
Definition: AsyncCamera.cpp:147
VCINodeAsync::m_camera
AlviumAsyncCamera m_camera
Definition: VCINode.hpp:26