Skip to main content

WaitForConditionFromGeminiQuery Class

Wait until Gemini answers yes to a question about the latest image from a camera topic. More...

Declaration

class moveit_pro::behaviors::WaitForConditionFromGeminiQuery { ... }

Included Headers

#include <wait_for_condition_from_gemini_query.hpp>

Base class

classAsyncBehaviorBase

A base class for behaviors which need to asynchronously run a function that might take a long time to complete. More...

Public Constructors Index

WaitForConditionFromGeminiQuery (const std::string &name, const BT::NodeConfiguration &config, const std::shared_ptr< BehaviorContext > &shared_resources)
WaitForConditionFromGeminiQuery (const std::string &name, const BT::NodeConfiguration &config, const std::shared_ptr< BehaviorContext > &shared_resources, gemini::GeminiPostFn http_post_fn)

Takes the function that posts to Gemini, so a test can supply the answer without a network. More...

Private Member Functions Index

tl::expected< bool, std::string >doWork () override

User-implemented function which handles executing the potentially-long-running process. More...

tl::expected< void, std::string >doHalt () override

Optionally implement additional work needed to cleanly interrupt the async process. More...

std::shared_future< tl::expected< bool, std::string > > &getFuture () override

Gets the shared future which is used to monitor the progress of the async process. More...

Private Member Attributes Index

gemini::GeminiPostFnhttp_post_fn_
std::shared_future< tl::expected< bool, std::string > >future_
std::stop_sourcestop_source_

Public Static Functions Index

static BT::PortsListprovidedPorts ()
static BT::KeyValueVectormetadata ()

Description

Wait until Gemini answers yes to a question about the latest image from a camera topic.

Sends the newest frame from image_topic and the question to Gemini, at most once per poll_period_sec, until the answer is yes. Returns RUNNING while it waits. On a yes it logs the question and Gemini's reason, then returns SUCCESS. No and uncertain answers count as no. Each question uses a frame newer than the previous one. Returns FAILURE when no new frame arrives within message_timeout_sec, when calls keep failing for that long, or when a frame cannot be converted to a color image. A failed call is logged and retried on the next poll. The calls run on a worker thread, and a halt aborts the call in flight.

Needs GOOGLE_GEMINI_API_KEY and network access. This is task logic, not a safety function. The stop comes after the scene changes by the longer of one poll period and one Gemini round trip, plus one more round trip, and later when a call fails.

Data Port NamePort TypeObject Type
questioninputstd::string
image_topicinputstd::string
poll_period_secinputdouble (optional)
model_nameinputstd::string (optional)
message_timeout_secinputdouble (optional)

Definition at line 45 of file wait_for_condition_from_gemini_query.hpp.

Public Constructors

WaitForConditionFromGeminiQuery()

moveit_pro::behaviors::WaitForConditionFromGeminiQuery::WaitForConditionFromGeminiQuery (const std::string & name, const BT::NodeConfiguration & config, const std::shared_ptr< BehaviorContext > & shared_resources)

Declaration at line 48 of file wait_for_condition_from_gemini_query.hpp, definition at line 172 of file wait_for_condition_from_gemini_query.cpp.

WaitForConditionFromGeminiQuery()

moveit_pro::behaviors::WaitForConditionFromGeminiQuery::WaitForConditionFromGeminiQuery (const std::string & name, const BT::NodeConfiguration & config, const std::shared_ptr< BehaviorContext > & shared_resources, gemini::GeminiPostFn http_post_fn)

Takes the function that posts to Gemini, so a test can supply the answer without a network.

Declaration at line 52 of file wait_for_condition_from_gemini_query.hpp, definition at line 179 of file wait_for_condition_from_gemini_query.cpp.

Private Member Functions

doHalt()

tl::expected< void, std::string > moveit_pro::behaviors::WaitForConditionFromGeminiQuery::doHalt ()
virtual

Optionally implement additional work needed to cleanly interrupt the async process.

The default implementation of this function is a no-op which will not interrupt the async process. This will mean that onHalted will wait until the process finishes before returning.

Returns

Return an empty tl::expected<void, std::string> if the additional work to halt was successful. Return an error message if something failed while doing additional work to halt.

Declaration at line 63 of file wait_for_condition_from_gemini_query.hpp, definition at line 354 of file wait_for_condition_from_gemini_query.cpp.

doWork()

tl::expected< bool, std::string > moveit_pro::behaviors::WaitForConditionFromGeminiQuery::doWork ()
virtual

User-implemented function which handles executing the potentially-long-running process.

This function is called within an async process in a separate thread.

Returns

A tl::expected which contains a bool indicating task success if the process completed successfully or was canceled, or an error message if the process failed unexpectedly.

Declaration at line 61 of file wait_for_condition_from_gemini_query.hpp, definition at line 211 of file wait_for_condition_from_gemini_query.cpp.

getFuture()

std::shared_future< tl::expected< bool, std::string > > & moveit_pro::behaviors::WaitForConditionFromGeminiQuery::getFuture ()
inline virtual

Gets the shared future which is used to monitor the progress of the async process.

Classes derived from AsyncBehaviorBase must implement getFuture() so that it returns a shared_future class member.

This exists to prevent destruction of the derived class while the async process is still in-progress. If the derived class is destroyed, the definitions of the functions used within doWork() will be destroyed too, which will result in the virtual functions in the base class being called instead and cause a fault.

This function will force derived classes to add an instance of this type and return a reference to it. The base class can then use this virtual function to access the shared future in functions like onStart.

By adding this virtual function we're properly demonstrating how this future depends on things from the derived class and the natural flow of object lifetimes will do the hard work for us. The std::shared_future destructor will get the value of the future before the derived class is destructed assuming it's the last reference to the shared state. Doing it this way means neither the base nor derived class should need to implement a destructor which is a nice property to have.

Returns

Returns the shared_future, which should be owned by the child class.

Definition at line 65 of file wait_for_condition_from_gemini_query.hpp.

Private Member Attributes

future_

std::shared_future<tl::expected<bool, std::string> > moveit_pro::behaviors::WaitForConditionFromGeminiQuery::future_

Definition at line 71 of file wait_for_condition_from_gemini_query.hpp.

http_post_fn_

gemini::GeminiPostFn moveit_pro::behaviors::WaitForConditionFromGeminiQuery::http_post_fn_

Definition at line 70 of file wait_for_condition_from_gemini_query.hpp.

stop_source_

std::stop_source moveit_pro::behaviors::WaitForConditionFromGeminiQuery::stop_source_

Definition at line 72 of file wait_for_condition_from_gemini_query.hpp.

Public Static Functions

metadata()

BT::KeyValueVector moveit_pro::behaviors::WaitForConditionFromGeminiQuery::metadata ()
static

Declaration at line 58 of file wait_for_condition_from_gemini_query.hpp, definition at line 205 of file wait_for_condition_from_gemini_query.cpp.

providedPorts()

BT::PortsList moveit_pro::behaviors::WaitForConditionFromGeminiQuery::providedPorts ()
static

Declaration at line 56 of file wait_for_condition_from_gemini_query.hpp, definition at line 186 of file wait_for_condition_from_gemini_query.cpp.


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


Generated via doxygen2docusaurus 2.2.2 by Doxygen 1.9.8.