Skip to main content

AddCollisionObjectBase Class

Abstract base for Behaviors that add a CollisionObject to the planning scene. More...

Declaration

class moveit_pro::behaviors::AddCollisionObjectBase { ... }

Included Headers

#include <add_collision_object_base.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...

Derived Classes

classAddCollisionBox

Adds a box-shaped CollisionObject to the planning scene. More...

classAddCollisionCylinder

Adds a cylinder-shaped CollisionObject to the planning scene. More...

classAddCollisionMesh

Adds a mesh CollisionObject to the planning scene. More...

classAddCollisionObject

Adds a user-supplied CollisionObject to the planning scene. More...

classAddCollisionSphere

Adds a sphere-shaped CollisionObject to the planning scene. More...

Public Constructors Index

AddCollisionObjectBase (const std::string &name, const BT::NodeConfiguration &config, const std::shared_ptr< BehaviorContext > &shared_resources)
AddCollisionObjectBase (const std::string &name, const BT::NodeConfiguration &config, const std::shared_ptr< BehaviorContext > &shared_resources, std::unique_ptr< PlanningSceneBridge > bridge)

Public Destructor Index

~AddCollisionObjectBase () override=default

Public Member Functions Index

tl::expected< moveit_msgs::msg::CollisionObject, std::string >buildCollisionObject ()=0

Build the CollisionObject to apply to the planning scene. More...

Private Member Functions Index

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

User-implemented function which handles executing the potentially-long-running 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

std::unique_ptr< PlanningSceneBridge >bridge_
std::shared_future< tl::expected< bool, std::string > >future_

Public Static Functions Index

static BT::PortsListcommonPorts ()

Returns the input ports owned by this base class: overwrite and planning_scene. Subclasses concatenate this list into their own providedPorts() so every shape-specific Add inherits the same wiring. More...

Public Static Attributes Index

static constexpr autokPortIDOverwrite = "overwrite"
static constexpr autokPortIDPlanningScene = "planning_scene"

Description

Abstract base for Behaviors that add a CollisionObject to the planning scene.

Subclasses override buildCollisionObject() to produce the CollisionObject. The base class then validates the object (non-empty id, non-empty frame_id, equal-size subframe arrays), enforces operation = ADD, and commits the addition.

The Behavior has two operating modes selected by the planning_scene input port:

  • Live scene mode (port unwired): the Behavior fetches the current planning scene from the /get_planning_scene service, then commits by sending a diff to the /apply_planning_scene service. Service names are hard-coded; they are not exposed as ports. This is the default behavior.
  • Supplied scene mode (port wired): the Behavior modifies the moveit_msgs::PlanningScene message supplied on the port and writes the result back to the same port. No service calls are made.

Before adding the object, the Behavior looks for another entry in the planning scene with the same id. The id can already be present in two places: in the world (world.collision_objects), or attached to the robot (robot_state.attached_collision_objects).

  • If a world entry with the same id already exists, the Behavior fails unless overwrite is true, in which case the existing world entry is replaced.
  • If an attached entry with the same id already exists, the Behavior fails regardless of overwrite, and the caller must detach the object first. This Behavior never modifies the attached list.

Definition at line 53 of file add_collision_object_base.hpp.

Public Constructors

AddCollisionObjectBase()

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

Declaration at line 66 of file add_collision_object_base.hpp, definition at line 84 of file add_collision_object_base.cpp.

AddCollisionObjectBase()

moveit_pro::behaviors::AddCollisionObjectBase::AddCollisionObjectBase (const std::string & name, const BT::NodeConfiguration & config, const std::shared_ptr< BehaviorContext > & shared_resources, std::unique_ptr< PlanningSceneBridge > bridge)

Declaration at line 69 of file add_collision_object_base.hpp, definition at line 91 of file add_collision_object_base.cpp.

Public Destructor

~AddCollisionObjectBase()

moveit_pro::behaviors::AddCollisionObjectBase::~AddCollisionObjectBase ()
default

Definition at line 73 of file add_collision_object_base.hpp.

Public Member Functions

buildCollisionObject()

virtual tl::expected< moveit_msgs::msg::CollisionObject, std::string > moveit_pro::behaviors::AddCollisionObjectBase::buildCollisionObject ()

Build the CollisionObject to apply to the planning scene.

Returns

The CollisionObject on success, or a descriptive error message on failure.

Definition at line 78 of file add_collision_object_base.hpp.

Private Member Functions

doWork()

tl::expected< bool, std::string > moveit_pro::behaviors::AddCollisionObjectBase::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 81 of file add_collision_object_base.hpp, definition at line 114 of file add_collision_object_base.cpp.

getFuture()

std::shared_future< tl::expected< bool, std::string > > & moveit_pro::behaviors::AddCollisionObjectBase::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 83 of file add_collision_object_base.hpp.

Private Member Attributes

bridge_

std::unique_ptr<PlanningSceneBridge> moveit_pro::behaviors::AddCollisionObjectBase::bridge_

Definition at line 91 of file add_collision_object_base.hpp.

future_

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

Definition at line 92 of file add_collision_object_base.hpp.

Public Static Functions

commonPorts()

BT::PortsList moveit_pro::behaviors::AddCollisionObjectBase::commonPorts ()
static

Returns the input ports owned by this base class: overwrite and planning_scene. Subclasses concatenate this list into their own providedPorts() so every shape-specific Add inherits the same wiring.

Declaration at line 64 of file add_collision_object_base.hpp, definition at line 98 of file add_collision_object_base.cpp.

Public Static Attributes

kPortIDOverwrite

constexpr auto moveit_pro::behaviors::AddCollisionObjectBase::kPortIDOverwrite = "overwrite"
constexpr static

Definition at line 56 of file add_collision_object_base.hpp.

kPortIDPlanningScene

constexpr auto moveit_pro::behaviors::AddCollisionObjectBase::kPortIDPlanningScene = "planning_scene"
constexpr static

Definition at line 57 of file add_collision_object_base.hpp.


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


Generated via doxygen2docusaurus 2.2.2 by Doxygen 1.9.8.