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

#include <cb_yaw_scan.hpp>

Inheritance diagram for cl_px4_mr::CbYawScan:
Inheritance graph
Collaboration diagram for cl_px4_mr::CbYawScan:
Collaboration graph

Public Member Functions

 CbYawScan (const YawScanParams &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 amplitude_
 
float period_
 
float baseHeading_
 
float holdX_ = 0.0f
 
float holdY_ = 0.0f
 
float holdZ_ = 0.0f
 
float elapsed_ = 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 44 of file cb_yaw_scan.hpp.

Constructor & Destructor Documentation

◆ CbYawScan()

cl_px4_mr::CbYawScan::CbYawScan ( const YawScanParams & params = {})
explicit

Definition at line 25 of file cb_yaw_scan.cpp.

26: amplitude_(params.amplitude),
27 period_(std::max(params.period, 0.1f)),
28 baseHeading_(params.baseHeading)
29{
30}

Member Function Documentation

◆ onEntry()

void cl_px4_mr::CbYawScan::onEntry ( )
overridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 32 of file cb_yaw_scan.cpp.

33{
34 if (localPosition_ == nullptr || !localPosition_->isValid())
35 {
36 RCLCPP_ERROR(getLogger(), "CbYawScan: no valid local position at entry - posting failure");
37 this->postPx4Failure();
38 return;
39 }
40
44
45 if (std::isnan(baseHeading_))
46 {
48 }
50
51 // Peak yaw rate of the commanded sweep; PX4's autonomous yaw rate limit is
52 // ~0.8 rad/s by default and the flown sweep clips beyond it.
53 float peakYawRate = amplitude_ * 2.0f * static_cast<float>(M_PI) / period_;
54 if (peakYawRate > 0.8f)
55 {
56 RCLCPP_WARN(
57 getLogger(),
58 "CbYawScan: commanded peak yaw rate %.2f rad/s exceeds typical PX4 limits - the flown "
59 "sweep will clip",
60 peakYawRate);
61 }
62
63 elapsed_ = 0.0f;
64 lastUpdateTime_ = std::chrono::steady_clock::now();
65
66 RCLCPP_INFO(
67 getLogger(),
68 "CbYawScan: scanning around heading=%.2f rad A=%.2f rad T=%.2f s "
69 "(continuous - exits only on state change)",
71
73 active_ = true;
74}
std::chrono::steady_clock::time_point lastUpdateTime_
std::atomic< bool > active_
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_, baseHeading_, elapsed_, cl_px4_mr::CpVehicleLocalPosition::getHeading(), smacc2::ISmaccClientBehavior::getLogger(), cl_px4_mr::CpVehicleLocalPosition::getX(), cl_px4_mr::CpVehicleLocalPosition::getY(), cl_px4_mr::CpVehicleLocalPosition::getZ(), holdX_, holdY_, holdZ_, cl_px4_mr::CpVehicleLocalPosition::isValid(), lastUpdateTime_, cl_px4_mr::CbPx4ClientBehaviorBase::localPosition_, period_, cl_px4_mr::CbPx4ClientBehaviorBase::postPx4Failure(), cl_px4_mr::CpTrajectorySetpoint::setPositionNED(), cl_px4_mr::CbPx4ClientBehaviorBase::trajectorySetpoint_, and cl_px4_mr::wrapPi().

Here is the call graph for this function:

◆ onExit()

void cl_px4_mr::CbYawScan::onExit ( )
overridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 76 of file cb_yaw_scan.cpp.

77{
78 if (active_.exchange(false))
79 {
80 // Restore the base heading; the offboard keep-alive republishes this until
81 // the next state commands otherwise.
83 RCLCPP_INFO(getLogger(), "CbYawScan: exiting - restoring base heading %.2f rad", baseHeading_);
84 }
85}

References active_, baseHeading_, smacc2::ISmaccClientBehavior::getLogger(), holdX_, holdY_, holdZ_, cl_px4_mr::CpTrajectorySetpoint::setPositionNED(), and cl_px4_mr::CbPx4ClientBehaviorBase::trajectorySetpoint_.

Here is the call graph for this function:

◆ update()

void cl_px4_mr::CbYawScan::update ( )
overridevirtual

Reimplemented from cl_px4_mr::CbPx4ClientBehaviorBase.

Definition at line 87 of file cb_yaw_scan.cpp.

88{
90
91 if (!active_)
92 {
93 return;
94 }
95
96 auto now = std::chrono::steady_clock::now();
97 double dt = std::chrono::duration<double>(now - lastUpdateTime_).count();
98 lastUpdateTime_ = now;
99
100 elapsed_ += static_cast<float>(dt);
101
102 float phase = 2.0f * static_cast<float>(M_PI) * elapsed_ / period_;
103 float yaw = wrapPi(baseHeading_ + amplitude_ * std::sin(phase));
104
106}

References active_, amplitude_, baseHeading_, elapsed_, holdX_, holdY_, holdZ_, lastUpdateTime_, period_, cl_px4_mr::CpTrajectorySetpoint::setPositionNED(), cl_px4_mr::CbPx4ClientBehaviorBase::trajectorySetpoint_, cl_px4_mr::CbPx4ClientBehaviorBase::update(), and cl_px4_mr::wrapPi().

Here is the call graph for this function:

Member Data Documentation

◆ active_

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

Definition at line 62 of file cb_yaw_scan.hpp.

62{false};

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

◆ amplitude_

float cl_px4_mr::CbYawScan::amplitude_
private

Definition at line 54 of file cb_yaw_scan.hpp.

Referenced by onEntry(), and update().

◆ baseHeading_

float cl_px4_mr::CbYawScan::baseHeading_
private

Definition at line 56 of file cb_yaw_scan.hpp.

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

◆ elapsed_

float cl_px4_mr::CbYawScan::elapsed_ = 0.0f
private

Definition at line 61 of file cb_yaw_scan.hpp.

Referenced by onEntry(), and update().

◆ holdX_

float cl_px4_mr::CbYawScan::holdX_ = 0.0f
private

Definition at line 58 of file cb_yaw_scan.hpp.

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

◆ holdY_

float cl_px4_mr::CbYawScan::holdY_ = 0.0f
private

Definition at line 59 of file cb_yaw_scan.hpp.

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

◆ holdZ_

float cl_px4_mr::CbYawScan::holdZ_ = 0.0f
private

Definition at line 60 of file cb_yaw_scan.hpp.

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

◆ lastUpdateTime_

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

Definition at line 63 of file cb_yaw_scan.hpp.

Referenced by onEntry(), and update().

◆ period_

float cl_px4_mr::CbYawScan::period_
private

Definition at line 55 of file cb_yaw_scan.hpp.

Referenced by onEntry(), and update().


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