SMACC2
Loading...
Searching...
No Matches
cl_px4_mr::CbFigureEight Class Reference

#include <cb_figure_eight.hpp>

Inheritance diagram for cl_px4_mr::CbFigureEight:
Inheritance graph
Collaboration diagram for cl_px4_mr::CbFigureEight:
Collaboration graph

Public Member Functions

 CbFigureEight (const FigureEightParams &params)
 
void setCenter (float centerX, float centerY)
 
void setHeading (float headingRad)
 
void onEntry () override
 
void onExit () override
 
void update () override
 
- Public Member Functions inherited from cl_px4_mr::CbPx4ClientBehaviorBase
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
 ~CbPx4ClientBehaviorBase () override
 
void setTimeout (std::chrono::milliseconds timeout)
 
bool hasTimeout () const
 
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

float centerX_
 
float centerY_
 
float altitude_
 
float size_
 
float speed_
 
int numLoops_
 
float heading_ = 0.0f
 
float t_ = 0.0f
 
std::chrono::steady_clock::time_point lastUpdateTime_
 

Additional Inherited Members

- Protected Member Functions inherited from cl_px4_mr::CbPx4ClientBehaviorBase
virtual void wireCompletionSignals ()
 
void postPx4Success ()
 
void postPx4Failure ()
 
- 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_px4_mr::CbPx4ClientBehaviorBase
CpVehicleCommand * vehicleCommand_ = nullptr
 
CpVehicleStatus * vehicleStatus_ = nullptr
 
CpTrajectorySetpoint * trajectorySetpoint_ = nullptr
 
CpGoalChecker * goalChecker_ = nullptr
 
CpVehicleLocalPosition * localPosition_ = nullptr
 
CpOffboardKeepAlive * offboardKeepAlive_ = nullptr
 

Detailed Description

Definition at line 37 of file cb_figure_eight.hpp.

Constructor & Destructor Documentation

◆ CbFigureEight()

cl_px4_mr::CbFigureEight::CbFigureEight ( const FigureEightParams & params)
explicit

Definition at line 21 of file cb_figure_eight.cpp.

22: centerX_(params.centerX),
23 centerY_(params.centerY),
24 altitude_(params.altitude),
25 size_(params.size),
26 speed_(params.speed),
27 numLoops_(params.numLoops)
28{
29}

Member Function Documentation

◆ onEntry()

void cl_px4_mr::CbFigureEight::onEntry ( )
overridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 31 of file cb_figure_eight.cpp.

32{
33 t_ = 0.0f;
34 lastUpdateTime_ = std::chrono::steady_clock::now();
35
36 // Command initial position (t=0: x=size, y=0 relative to center, rotated by heading_)
37 float x = centerX_ + size_ * std::cos(heading_);
38 float y = centerY_ + size_ * std::sin(heading_);
39 float z = -altitude_; // NED
40
41 RCLCPP_INFO(
42 getLogger(),
43 "CbFigureEight: starting figure-8 center=[%.2f, %.2f] alt=%.2f size=%.2f axis=%.2f rad "
44 "loops=%d",
46
48}
std::chrono::steady_clock::time_point lastUpdateTime_
void setPositionNED(float x, float y, float z, float yaw=std::numeric_limits< float >::quiet_NaN())
virtual rclcpp::Logger getLogger() const

References altitude_, centerX_, centerY_, smacc2::ISmaccClientBehavior::getLogger(), heading_, lastUpdateTime_, numLoops_, cl_px4_mr::CpTrajectorySetpoint::setPositionNED(), size_, t_, and cl_px4_mr::CbPx4ClientBehaviorBase::trajectorySetpoint_.

Here is the call graph for this function:

◆ onExit()

void cl_px4_mr::CbFigureEight::onExit ( )
overridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 50 of file cb_figure_eight.cpp.

50{}

◆ setCenter()

void cl_px4_mr::CbFigureEight::setCenter ( float centerX,
float centerY )
inline

Definition at line 44 of file cb_figure_eight.hpp.

45 {
46 centerX_ = centerX;
47 centerY_ = centerY;
48 }

References centerX_, and centerY_.

◆ setHeading()

void cl_px4_mr::CbFigureEight::setHeading ( float headingRad)
inline

Definition at line 50 of file cb_figure_eight.hpp.

50{ heading_ = headingRad; }

References heading_.

◆ update()

void cl_px4_mr::CbFigureEight::update ( )
overridevirtual

Implements smacc2::ISmaccUpdatable.

Definition at line 52 of file cb_figure_eight.cpp.

53{
55
56 auto now = std::chrono::steady_clock::now();
57 double dt = std::chrono::duration<double>(now - lastUpdateTime_).count();
58 lastUpdateTime_ = now;
59
60 t_ = static_cast<float>(t_ + speed_ * dt);
61
62 // Lemniscate of Bernoulli parametric equations
63 float sinT = std::sin(t_);
64 float cosT = std::cos(t_);
65 float denom = 1.0f + sinT * sinT;
66
67 float localX = size_ * cosT / denom;
68 float localY = size_ * sinT * cosT / denom;
69
70 // rotate the lemniscate so its lobe axis lies along heading_
71 const float ch = std::cos(heading_);
72 const float sh = std::sin(heading_);
73 float x = centerX_ + localX * ch - localY * sh;
74 float y = centerY_ + localX * sh + localY * ch;
75 float z = -altitude_; // NED
76
77 // Compute derivatives for yaw (face direction of travel)
78 float sinT2 = sinT * sinT;
79 float cosT2 = cosT * cosT;
80 float denom2 = denom * denom;
81 float dxdt = size_ * (-sinT * (1.0f + sinT2) - cosT * 2.0f * sinT * cosT) / denom2;
82 float dydt =
83 size_ * ((cosT2 - sinT2) * (1.0f + sinT2) - sinT * cosT * 2.0f * sinT * cosT) / denom2;
84 float yaw = std::atan2(dydt, dxdt) + heading_;
85
87
88 // Check completion
89 float requiredT = static_cast<float>(static_cast<float>(numLoops_) * 2.0f * M_PI);
90 if (t_ >= requiredT)
91 {
92 RCLCPP_INFO(getLogger(), "CbFigureEight: %d loops completed - posting success", numLoops_);
93 this->postPx4Success();
94 }
95}

References altitude_, centerX_, centerY_, smacc2::ISmaccClientBehavior::getLogger(), heading_, lastUpdateTime_, numLoops_, cl_px4_mr::CbPx4ClientBehaviorBase::postPx4Success(), cl_px4_mr::CpTrajectorySetpoint::setPositionNED(), size_, speed_, t_, cl_px4_mr::CbPx4ClientBehaviorBase::trajectorySetpoint_, and cl_px4_mr::CbPx4ClientBehaviorBase::update().

Here is the call graph for this function:

Member Data Documentation

◆ altitude_

float cl_px4_mr::CbFigureEight::altitude_
private

Definition at line 59 of file cb_figure_eight.hpp.

Referenced by onEntry(), and update().

◆ centerX_

float cl_px4_mr::CbFigureEight::centerX_
private

Definition at line 57 of file cb_figure_eight.hpp.

Referenced by onEntry(), setCenter(), and update().

◆ centerY_

float cl_px4_mr::CbFigureEight::centerY_
private

Definition at line 58 of file cb_figure_eight.hpp.

Referenced by onEntry(), setCenter(), and update().

◆ heading_

float cl_px4_mr::CbFigureEight::heading_ = 0.0f
private

Definition at line 63 of file cb_figure_eight.hpp.

Referenced by onEntry(), setHeading(), and update().

◆ lastUpdateTime_

std::chrono::steady_clock::time_point cl_px4_mr::CbFigureEight::lastUpdateTime_
private

Definition at line 66 of file cb_figure_eight.hpp.

Referenced by onEntry(), and update().

◆ numLoops_

int cl_px4_mr::CbFigureEight::numLoops_
private

Definition at line 62 of file cb_figure_eight.hpp.

Referenced by onEntry(), and update().

◆ size_

float cl_px4_mr::CbFigureEight::size_
private

Definition at line 60 of file cb_figure_eight.hpp.

Referenced by onEntry(), and update().

◆ speed_

float cl_px4_mr::CbFigureEight::speed_
private

Definition at line 61 of file cb_figure_eight.hpp.

Referenced by update().

◆ t_

float cl_px4_mr::CbFigureEight::t_ = 0.0f
private

Definition at line 65 of file cb_figure_eight.hpp.

Referenced by onEntry(), and update().


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