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

#include <cb_spiral_pattern.hpp>

Inheritance diagram for cl_px4_mr::CbSpiralPattern:
Inheritance graph
Collaboration diagram for cl_px4_mr::CbSpiralPattern:
Collaboration graph

Public Member Functions

 CbSpiralPattern (const SpiralPatternParams &params)
 
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
 
- 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 maxRadius_
 
float spacing_
 
float speed_
 
float theta_ = 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 39 of file cb_spiral_pattern.hpp.

Constructor & Destructor Documentation

◆ CbSpiralPattern()

cl_px4_mr::CbSpiralPattern::CbSpiralPattern ( const SpiralPatternParams & params)
explicit

Definition at line 22 of file cb_spiral_pattern.cpp.

23: centerX_(params.centerX),
24 centerY_(params.centerY),
25 altitude_(params.altitude),
26 maxRadius_(params.maxRadius),
27 spacing_(params.spacing),
28 speed_(params.speed)
29{
30}

Member Function Documentation

◆ onEntry()

void cl_px4_mr::CbSpiralPattern::onEntry ( )
overridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 32 of file cb_spiral_pattern.cpp.

33{
34 theta_ = 0.0f;
35 lastUpdateTime_ = std::chrono::steady_clock::now();
36
37 // Initial position is the spiral center
38 float z = -altitude_; // NED: up is negative
39
40 RCLCPP_INFO(
41 getLogger(),
42 "CbSpiralPattern: starting spiral center=[%.2f, %.2f] alt=%.2f maxR=%.2f spacing=%.2f "
43 "speed=%.2f",
45
47}
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(), lastUpdateTime_, maxRadius_, cl_px4_mr::CpTrajectorySetpoint::setPositionNED(), spacing_, speed_, theta_, and cl_px4_mr::CbPx4ClientBehaviorBase::trajectorySetpoint_.

Here is the call graph for this function:

◆ onExit()

void cl_px4_mr::CbSpiralPattern::onExit ( )
overridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 49 of file cb_spiral_pattern.cpp.

49{}

◆ update()

void cl_px4_mr::CbSpiralPattern::update ( )
overridevirtual

Reimplemented from cl_px4_mr::CbPx4ClientBehaviorBase.

Definition at line 51 of file cb_spiral_pattern.cpp.

52{
54
55 auto now = std::chrono::steady_clock::now();
56 double dt = std::chrono::duration<double>(now - lastUpdateTime_).count();
57 lastUpdateTime_ = now;
58
59 // Archimedean spiral: r(theta) = a * theta
60 // where a = spacing / (2*PI) so each revolution adds 'spacing' meters of radius
61 float a = static_cast<float>(spacing_ / (2.0f * M_PI));
62
63 // Current radius
64 float r = a * theta_;
65
66 // Adaptive angular velocity to maintain constant linear speed
67 // Arc-length speed: ds/dt = sqrt(r^2 + a^2) * dtheta/dt
68 // Solving for dtheta/dt: omega = speed / sqrt(r^2 + a^2)
69 float omega = speed_ / std::sqrt(r * r + a * a);
70
71 // Advance angle
72 theta_ = static_cast<float>(theta_ + omega * dt);
73
74 // Compute new position
75 float r_new = a * theta_;
76 float x = centerX_ + r_new * std::cos(theta_);
77 float y = centerY_ + r_new * std::sin(theta_);
78 float z = -altitude_; // NED
79
80 // Yaw: face direction of travel (derivatives of Archimedean spiral)
81 // dx/dtheta = a*cos(theta) - r*sin(theta)
82 // dy/dtheta = a*sin(theta) + r*cos(theta)
83 float dxdt = a * std::cos(theta_) - r_new * std::sin(theta_);
84 float dydt = a * std::sin(theta_) + r_new * std::cos(theta_);
85 float yaw = std::atan2(dydt, dxdt);
86
88
89 // Check completion
90 if (r_new >= maxRadius_)
91 {
92 RCLCPP_INFO(
93 getLogger(), "CbSpiralPattern: max radius %.2f reached (r=%.2f) - posting success",
94 maxRadius_, r_new);
95 this->postPx4Success();
96 }
97}

References altitude_, centerX_, centerY_, smacc2::ISmaccClientBehavior::getLogger(), lastUpdateTime_, maxRadius_, cl_px4_mr::CbPx4ClientBehaviorBase::postPx4Success(), cl_px4_mr::CpTrajectorySetpoint::setPositionNED(), spacing_, speed_, theta_, 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::CbSpiralPattern::altitude_
private

Definition at line 51 of file cb_spiral_pattern.hpp.

Referenced by onEntry(), and update().

◆ centerX_

float cl_px4_mr::CbSpiralPattern::centerX_
private

Definition at line 49 of file cb_spiral_pattern.hpp.

Referenced by onEntry(), and update().

◆ centerY_

float cl_px4_mr::CbSpiralPattern::centerY_
private

Definition at line 50 of file cb_spiral_pattern.hpp.

Referenced by onEntry(), and update().

◆ lastUpdateTime_

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

Definition at line 57 of file cb_spiral_pattern.hpp.

Referenced by onEntry(), and update().

◆ maxRadius_

float cl_px4_mr::CbSpiralPattern::maxRadius_
private

Definition at line 52 of file cb_spiral_pattern.hpp.

Referenced by onEntry(), and update().

◆ spacing_

float cl_px4_mr::CbSpiralPattern::spacing_
private

Definition at line 53 of file cb_spiral_pattern.hpp.

Referenced by onEntry(), and update().

◆ speed_

float cl_px4_mr::CbSpiralPattern::speed_
private

Definition at line 54 of file cb_spiral_pattern.hpp.

Referenced by onEntry(), and update().

◆ theta_

float cl_px4_mr::CbSpiralPattern::theta_ = 0.0f
private

Definition at line 56 of file cb_spiral_pattern.hpp.

Referenced by onEntry(), and update().


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