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

#include <cb_sine_altitude_cruise.hpp>

Inheritance diagram for cl_px4_mr::CbSineAltitudeCruise:
Inheritance graph
Collaboration diagram for cl_px4_mr::CbSineAltitudeCruise:
Collaboration graph

Public Member Functions

 CbSineAltitudeCruise (const SineAltitudeCruiseParams &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 groundSpeed_
 
float amplitude_
 
float wavelength_
 
float heading_
 
float startX_ = 0.0f
 
float startY_ = 0.0f
 
float baseZ_ = 0.0f
 
float arcLength_ = 0.0f
 
float lastCmdX_ = 0.0f
 
float lastCmdY_ = 0.0f
 
std::atomic< bool > active_ {false}
 
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 46 of file cb_sine_altitude_cruise.hpp.

Constructor & Destructor Documentation

◆ CbSineAltitudeCruise()

cl_px4_mr::CbSineAltitudeCruise::CbSineAltitudeCruise ( const SineAltitudeCruiseParams & params = {})
explicit

Definition at line 25 of file cb_sine_altitude_cruise.cpp.

26: groundSpeed_(params.groundSpeed),
27 amplitude_(params.amplitude),
28 wavelength_(std::max(params.wavelength, 0.1f)),
29 heading_(params.heading)
30{
31}

Member Function Documentation

◆ onEntry()

void cl_px4_mr::CbSineAltitudeCruise::onEntry ( )
overridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 33 of file cb_sine_altitude_cruise.cpp.

34{
35 if (localPosition_ == nullptr || !localPosition_->isValid())
36 {
37 RCLCPP_ERROR(
38 getLogger(), "CbSineAltitudeCruise: no valid local position at entry - posting failure");
39 this->postPx4Failure();
40 return;
41 }
42
46
47 if (std::isnan(heading_))
48 {
50 }
52
53 // Peak vertical speed of the commanded path; PX4 defaults limit climb/descent
54 // to ~2-3 m/s and the flown sine flattens beyond that.
55 float peakVerticalSpeed =
56 amplitude_ * 2.0f * static_cast<float>(M_PI) * groundSpeed_ / wavelength_;
57 if (peakVerticalSpeed > 2.0f)
58 {
59 RCLCPP_WARN(
60 getLogger(),
61 "CbSineAltitudeCruise: commanded peak vertical speed %.2f m/s exceeds typical PX4 limits - "
62 "the flown path will flatten",
63 peakVerticalSpeed);
64 }
65
66 arcLength_ = 0.0f;
69 lastUpdateTime_ = std::chrono::steady_clock::now();
70
71 RCLCPP_INFO(
72 getLogger(),
73 "CbSineAltitudeCruise: cruising heading=%.2f rad v=%.2f m/s A=%.2f m lambda=%.2f m "
74 "(continuous - exits only on state change)",
76
78 active_ = true;
79}
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
float wrapPi(float angle)

References active_, amplitude_, arcLength_, baseZ_, cl_px4_mr::CpVehicleLocalPosition::getHeading(), smacc2::ISmaccClientBehavior::getLogger(), cl_px4_mr::CpVehicleLocalPosition::getX(), cl_px4_mr::CpVehicleLocalPosition::getY(), cl_px4_mr::CpVehicleLocalPosition::getZ(), groundSpeed_, heading_, cl_px4_mr::CpVehicleLocalPosition::isValid(), lastCmdX_, lastCmdY_, lastUpdateTime_, cl_px4_mr::CbPx4ClientBehaviorBase::localPosition_, cl_px4_mr::CbPx4ClientBehaviorBase::postPx4Failure(), cl_px4_mr::CpTrajectorySetpoint::setPositionNED(), startX_, startY_, cl_px4_mr::CbPx4ClientBehaviorBase::trajectorySetpoint_, wavelength_, and cl_px4_mr::wrapPi().

Here is the call graph for this function:

◆ onExit()

void cl_px4_mr::CbSineAltitudeCruise::onExit ( )
overridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 81 of file cb_sine_altitude_cruise.cpp.

82{
83 if (active_.exchange(false))
84 {
85 // Settle at the entry altitude at the last commanded ground position; the
86 // offboard keep-alive republishes this until the next state commands otherwise.
88 RCLCPP_INFO(
89 getLogger(), "CbSineAltitudeCruise: exiting - settling at base altitude (NED z=%.2f)",
90 baseZ_);
91 }
92}

References active_, baseZ_, smacc2::ISmaccClientBehavior::getLogger(), heading_, lastCmdX_, lastCmdY_, cl_px4_mr::CpTrajectorySetpoint::setPositionNED(), and cl_px4_mr::CbPx4ClientBehaviorBase::trajectorySetpoint_.

Here is the call graph for this function:

◆ update()

void cl_px4_mr::CbSineAltitudeCruise::update ( )
overridevirtual

Reimplemented from cl_px4_mr::CbPx4ClientBehaviorBase.

Definition at line 94 of file cb_sine_altitude_cruise.cpp.

95{
97
98 if (!active_)
99 {
100 return;
101 }
102
103 auto now = std::chrono::steady_clock::now();
104 double dt = std::chrono::duration<double>(now - lastUpdateTime_).count();
105 lastUpdateTime_ = now;
106
107 arcLength_ += groundSpeed_ * static_cast<float>(dt);
108
109 float x = startX_ + arcLength_ * std::cos(heading_);
110 float y = startY_ + arcLength_ * std::sin(heading_);
111 float phase = 2.0f * static_cast<float>(M_PI) * arcLength_ / wavelength_;
112 float z = baseZ_ - amplitude_ * std::sin(phase); // NED: up is negative
113
114 lastCmdX_ = x;
115 lastCmdY_ = y;
117}

References active_, amplitude_, arcLength_, baseZ_, groundSpeed_, heading_, lastCmdX_, lastCmdY_, lastUpdateTime_, cl_px4_mr::CpTrajectorySetpoint::setPositionNED(), startX_, startY_, cl_px4_mr::CbPx4ClientBehaviorBase::trajectorySetpoint_, cl_px4_mr::CbPx4ClientBehaviorBase::update(), and wavelength_.

Here is the call graph for this function:

Member Data Documentation

◆ active_

std::atomic<bool> cl_px4_mr::CbSineAltitudeCruise::active_ {false}
private

Definition at line 67 of file cb_sine_altitude_cruise.hpp.

67{false};

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

◆ amplitude_

float cl_px4_mr::CbSineAltitudeCruise::amplitude_
private

Definition at line 57 of file cb_sine_altitude_cruise.hpp.

Referenced by onEntry(), and update().

◆ arcLength_

float cl_px4_mr::CbSineAltitudeCruise::arcLength_ = 0.0f
private

Definition at line 64 of file cb_sine_altitude_cruise.hpp.

Referenced by onEntry(), and update().

◆ baseZ_

float cl_px4_mr::CbSineAltitudeCruise::baseZ_ = 0.0f
private

Definition at line 63 of file cb_sine_altitude_cruise.hpp.

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

◆ groundSpeed_

float cl_px4_mr::CbSineAltitudeCruise::groundSpeed_
private

Definition at line 56 of file cb_sine_altitude_cruise.hpp.

Referenced by onEntry(), and update().

◆ heading_

float cl_px4_mr::CbSineAltitudeCruise::heading_
private

Definition at line 59 of file cb_sine_altitude_cruise.hpp.

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

◆ lastCmdX_

float cl_px4_mr::CbSineAltitudeCruise::lastCmdX_ = 0.0f
private

Definition at line 65 of file cb_sine_altitude_cruise.hpp.

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

◆ lastCmdY_

float cl_px4_mr::CbSineAltitudeCruise::lastCmdY_ = 0.0f
private

Definition at line 66 of file cb_sine_altitude_cruise.hpp.

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

◆ lastUpdateTime_

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

Definition at line 68 of file cb_sine_altitude_cruise.hpp.

Referenced by onEntry(), and update().

◆ startX_

float cl_px4_mr::CbSineAltitudeCruise::startX_ = 0.0f
private

Definition at line 61 of file cb_sine_altitude_cruise.hpp.

Referenced by onEntry(), and update().

◆ startY_

float cl_px4_mr::CbSineAltitudeCruise::startY_ = 0.0f
private

Definition at line 62 of file cb_sine_altitude_cruise.hpp.

Referenced by onEntry(), and update().

◆ wavelength_

float cl_px4_mr::CbSineAltitudeCruise::wavelength_
private

Definition at line 58 of file cb_sine_altitude_cruise.hpp.

Referenced by onEntry(), and update().


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