SMACC2
Loading...
Searching...
No Matches
cl_rgb::CbSurveyTable Class Reference

#include <cb_survey_table.hpp>

Inheritance diagram for cl_rgb::CbSurveyTable:
Inheritance graph
Collaboration diagram for cl_rgb::CbSurveyTable:
Collaboration graph

Public Member Functions

 CbSurveyTable (const SurveyTableParams &params=SurveyTableParams())
 
void setParams (const SurveyTableParams &params)
 
void onEntry () override
 
void onExit () override
 
- Public Member Functions inherited from cl_rgb::CbRgbClientBehaviorBase
 CbRgbClientBehaviorBase (const std::string &cameraName)
 
 ~CbRgbClientBehaviorBase () override
 
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
void setTimeout (std::chrono::milliseconds timeout)
 
void update () override
 
- Public Member Functions inherited from smacc2::SmaccAsyncClientBehavior
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
 SmaccAsyncClientBehavior ()=default
 
 ~SmaccAsyncClientBehavior () override
 
 SmaccAsyncClientBehavior (const SmaccAsyncClientBehavior &)=delete
 
SmaccAsyncClientBehavior & operator= (const SmaccAsyncClientBehavior &)=delete
 
 SmaccAsyncClientBehavior (SmaccAsyncClientBehavior &&)=delete
 
SmaccAsyncClientBehavior & operator= (SmaccAsyncClientBehavior &&)=delete
 
template<typename TCallback , typename T >
smacc2::SmaccSignalConnection onSuccess (TCallback callback, T *object)
 
template<typename TCallback , typename T >
smacc2::SmaccSignalConnection onFinished (TCallback callback, T *object)
 
template<typename TCallback , typename T >
smacc2::SmaccSignalConnection onFailure (TCallback callback, T *object)
 
void requestForceFinish ()
 
void executeOnEntry () override
 
void executeOnExit () override
 
void waitOnEntryThread (bool requestFinish)
 
template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection onSuccess (TCallbackMethod callback, T *object)
 
template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection onFinished (TCallbackMethod callback, T *object)
 
template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection onFailure (TCallbackMethod callback, T *object)
 
- Public Member Functions inherited from smacc2::ISmaccClientBehavior
 ISmaccClientBehavior ()
 
virtual ~ISmaccClientBehavior ()
 
 ISmaccClientBehavior (const ISmaccClientBehavior &)=delete
 
ISmaccClientBehavior & operator= (const ISmaccClientBehavior &)=delete
 
 ISmaccClientBehavior (ISmaccClientBehavior &&)=delete
 
ISmaccClientBehavior & operator= (ISmaccClientBehavior &&)=delete
 
ISmaccStateMachine * getStateMachine ()
 
std::string getName () const
 
template<typename SmaccClientType >
void requiresClient (SmaccClientType *&storage)
 
template<typename SmaccComponentType >
void requiresComponent (SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
template<typename SmaccComponentType >
void requiresComponent (const std::string &name, SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
- Public Member Functions inherited from smacc2::ISmaccUpdatable
 ISmaccUpdatable ()
 
 ISmaccUpdatable (rclcpp::Duration duration)
 
virtual ~ISmaccUpdatable ()=default
 
 ISmaccUpdatable (const ISmaccUpdatable &)=delete
 
ISmaccUpdatable & operator= (const ISmaccUpdatable &)=delete
 
 ISmaccUpdatable (ISmaccUpdatable &&)=delete
 
ISmaccUpdatable & operator= (ISmaccUpdatable &&)=delete
 
void executeUpdate (rclcpp::Node::SharedPtr node)
 
void setUpdatePeriod (rclcpp::Duration duration)
 

Private Attributes

SurveyTableParams params_
 

Additional Inherited Members

- Protected Member Functions inherited from cl_rgb::CbRgbClientBehaviorBase
virtual void wireCompletionSignals ()
 
void postRgbSuccess ()
 
void postRgbFailure ()
 
bool completed () const
 
- Protected Member Functions inherited from smacc2::SmaccAsyncClientBehavior
void postSuccessEvent ()
 
void postFailureEvent ()
 
void dispose () override
 
bool isShutdownRequested ()
 onEntry is executed in a new thread. However the current state cannot be left until the onEntry thread finishes. This flag can be checked from the onEntry thread to force finishing the thread.
 
- Protected Member Functions inherited from smacc2::ISmaccClientBehavior
virtual void runtimeConfigure ()
 
template<typename EventType >
void postEvent (const EventType &ev)
 
template<typename EventType >
void postEvent ()
 
ISmaccState * getCurrentState ()
 
void postInitializationFailureEvent (const std::string &what)
 
virtual rclcpp::Node::SharedPtr getNode () const
 
virtual rclcpp::Logger getLogger () const
 
std::string getTraceStateName () const
 
std::string getTraceOrthogonalName () const
 
- Protected Member Functions inherited from smacc2::ISmaccUpdatable
- Protected Attributes inherited from cl_rgb::CbRgbClientBehaviorBase
std::string cameraName_
 
CpCamera * camera_ = nullptr
 
CpTablePlane * table_ = nullptr
 
CpTableSegmenter * segmenter_ = nullptr
 
CpSceneSurvey * survey_ = nullptr
 

Detailed Description

Definition at line 36 of file cb_survey_table.hpp.

Constructor & Destructor Documentation

◆ CbSurveyTable()

cl_rgb::CbSurveyTable::CbSurveyTable ( const SurveyTableParams & params = SurveyTableParams())
explicit

Definition at line 23 of file cb_survey_table.cpp.

24: CbRgbClientBehaviorBase(params.camera), params_(params)
25{
26}
CbRgbClientBehaviorBase(const std::string &cameraName)
SurveyTableParams params_

Member Function Documentation

◆ onEntry()

void cl_rgb::CbSurveyTable::onEntry ( )
overridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 28 of file cb_survey_table.cpp.

29{
30 if (camera_ == nullptr || table_ == nullptr || segmenter_ == nullptr || survey_ == nullptr)
31 {
32 RCLCPP_ERROR(
33 getLogger(),
34 "CbSurveyTable: a component is missing (camera '%s' %d, table %d, segmenter %d, survey %d)",
35 params_.camera.c_str(), camera_ != nullptr, table_ != nullptr, segmenter_ != nullptr,
36 survey_ != nullptr);
37 this->postRgbFailure();
38 return;
39 }
40
41 // The latest image, with the camera as it stood when the image was taken.
42 FramePtr frame;
43 std::optional<PinholeCamera> model;
44 const auto deadline =
45 std::chrono::steady_clock::now() + std::chrono::duration<double>(params_.waitS);
46 while (!this->isShutdownRequested())
47 {
48 frame = camera_->latestFrame();
49 if (frame)
50 {
51 model = camera_->model(*frame);
52 if (model)
53 {
54 break;
55 }
56 }
57 if (std::chrono::steady_clock::now() > deadline)
58 {
59 RCLCPP_ERROR(
60 getLogger(),
61 "CbSurveyTable: no usable image of '%s' after %.1f s (image %d, calibration and pose %d)",
62 params_.camera.c_str(), params_.waitS, frame != nullptr, model.has_value());
63 this->postRgbFailure();
64 return;
65 }
66 std::this_thread::sleep_for(std::chrono::milliseconds(20));
67 }
68 if (!frame || !model)
69 {
70 this->postRgbFailure();
71 return;
72 }
73
74 const auto start = std::chrono::steady_clock::now();
75 const cv::Mat region = table_->regionMask(*model, frame->image.size());
76 const cv::Mat foreground = segmenter_->foreground(frame->image, region);
77 auto survey = std::make_shared<Survey>();
78 survey->stamp = frame->stamp;
79 survey->camera = params_.camera;
80 survey->model = *model;
81 survey->sequence = frame->sequence;
82 survey->blobs = findBlobs(frame->image, foreground, *model, table_->params(), params_.blobs);
83 const double ms =
84 std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - start).count();
85
86 RCLCPP_INFO(
87 getLogger(), "CbSurveyTable: %zu blob(s) in image %lu of '%s' (%.1f ms)", survey->blobs.size(),
88 static_cast<unsigned long>(frame->sequence), params_.camera.c_str(), ms);
89 for (const auto & blob : survey->blobs)
90 {
91 RCLCPP_INFO(
92 getLogger(),
93 "CbSurveyTable: blob %d at x %+.3f y %+.3f m, %.0f x %.0f mm, axis %+.0f deg, %d px, "
94 "colour L %.0f a %+.0f b %+.0f",
95 blob.id, blob.tablePoint[0], blob.tablePoint[1], blob.lengthM * 1000.0, blob.widthM * 1000.0,
96 blob.axisRad * 180.0 / CV_PI, blob.areaPx, blob.meanLab[0], blob.meanLab[1], blob.meanLab[2]);
97 }
98
99 const bool enough = static_cast<int>(survey->blobs.size()) >= params_.minBlobs;
100 survey_->store(survey);
101 if (enough)
102 {
103 this->postRgbSuccess();
104 }
105 else
106 {
107 RCLCPP_WARN(
108 getLogger(), "CbSurveyTable: %zu blob(s), %d needed - posting failure", survey->blobs.size(),
110 this->postRgbFailure();
111 }
112}
FramePtr latestFrame() const
Definition cp_camera.cpp:87
std::optional< PinholeCamera > model(const Frame &frame) const
Definition cp_camera.cpp:93
void store(const SurveyPtr &survey)
cv::Mat regionMask(const PinholeCamera &camera, const cv::Size &size) const
const TableParams & params() const
cv::Mat foreground(const cv::Mat &bgr, const cv::Mat &tableMask) const
virtual rclcpp::Logger getLogger() const
bool isShutdownRequested()
onEntry is executed in a new thread. However the current state cannot be left until the onEntry threa...
std::shared_ptr< const Frame > FramePtr
Definition types.hpp:39
std::vector< Blob > findBlobs(const cv::Mat &bgr, const cv::Mat &foreground, const PinholeCamera &camera, const TableParams &table, const BlobParams &params)

References cl_rgb::SurveyTableParams::blobs, cl_rgb::SurveyTableParams::camera, cl_rgb::CbRgbClientBehaviorBase::camera_, cl_rgb::findBlobs(), cl_rgb::CpTableSegmenter::foreground(), smacc2::ISmaccClientBehavior::getLogger(), smacc2::SmaccAsyncClientBehavior::isShutdownRequested(), cl_rgb::CpCamera::latestFrame(), cl_rgb::SurveyTableParams::minBlobs, cl_rgb::CpCamera::model(), cl_rgb::CpTablePlane::params(), params_, cl_rgb::CbRgbClientBehaviorBase::postRgbFailure(), cl_rgb::CbRgbClientBehaviorBase::postRgbSuccess(), cl_rgb::CpTablePlane::regionMask(), cl_rgb::CbRgbClientBehaviorBase::segmenter_, cl_rgb::CpSceneSurvey::store(), cl_rgb::CbRgbClientBehaviorBase::survey_, cl_rgb::CbRgbClientBehaviorBase::table_, and cl_rgb::SurveyTableParams::waitS.

Here is the call graph for this function:

◆ onExit()

void cl_rgb::CbSurveyTable::onExit ( )
inlineoverridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 44 of file cb_survey_table.hpp.

44{}

◆ setParams()

void cl_rgb::CbSurveyTable::setParams ( const SurveyTableParams & params)
inline

Definition at line 41 of file cb_survey_table.hpp.

41{ params_ = params; }

References params_.

Member Data Documentation

◆ params_

SurveyTableParams cl_rgb::CbSurveyTable::params_
private

Definition at line 47 of file cb_survey_table.hpp.

Referenced by onEntry(), and setParams().


The documentation for this class was generated from the following files: