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 (float amplitude=0.6f, float period=6.0f, float baseHeading=std::numeric_limits< float >::quiet_NaN())
 
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 ()
 
virtual ~CbPx4ClientBehaviorBase ()
 
void setTimeout (std::chrono::milliseconds timeout)
 
bool hasTimeout () const
 
- Public Member Functions inherited from smacc2::SmaccAsyncClientBehavior
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
virtual ~SmaccAsyncClientBehavior ()
 
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 ()
 
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 (std::string name, SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
- Public Member Functions inherited from smacc2::ISmaccUpdatable
 ISmaccUpdatable ()
 
 ISmaccUpdatable (rclcpp::Duration duration)
 
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 ()
 
virtual 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 ()
 
virtual rclcpp::Node::SharedPtr getNode () const
 
virtual rclcpp::Logger getLogger () 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 36 of file cb_yaw_scan.hpp.

Constructor & Destructor Documentation

◆ CbYawScan()

cl_px4_mr::CbYawScan::CbYawScan ( float amplitude = 0.6f,
float period = 6.0f,
float baseHeading = std::numeric_limits<float>::quiet_NaN() )

Definition at line 25 of file cb_yaw_scan.cpp.

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

Member Function Documentation

◆ onEntry()

void cl_px4_mr::CbYawScan::onEntry ( )
overridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 30 of file cb_yaw_scan.cpp.

31{
32 if (localPosition_ == nullptr || !localPosition_->isValid())
33 {
34 RCLCPP_ERROR(getLogger(), "CbYawScan: no valid local position at entry - posting failure");
35 this->postPx4Failure();
36 return;
37 }
38
42
43 if (std::isnan(baseHeading_))
44 {
46 }
48
49 // Peak yaw rate of the commanded sweep; PX4's autonomous yaw rate limit is
50 // ~0.8 rad/s by default and the flown sweep clips beyond it.
51 float peakYawRate = amplitude_ * 2.0f * static_cast<float>(M_PI) / period_;
52 if (peakYawRate > 0.8f)
53 {
54 RCLCPP_WARN(
55 getLogger(),
56 "CbYawScan: commanded peak yaw rate %.2f rad/s exceeds typical PX4 limits - the flown "
57 "sweep will clip",
58 peakYawRate);
59 }
60
61 elapsed_ = 0.0f;
62 lastUpdateTime_ = std::chrono::steady_clock::now();
63
64 RCLCPP_INFO(
65 getLogger(),
66 "CbYawScan: scanning around heading=%.2f rad A=%.2f rad T=%.2f s "
67 "(continuous - exits only on state change)",
69
71 active_ = true;
72}
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 74 of file cb_yaw_scan.cpp.

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

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 85 of file cb_yaw_scan.cpp.

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

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 56 of file cb_yaw_scan.hpp.

56{false};

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

◆ amplitude_

float cl_px4_mr::CbYawScan::amplitude_
private

Definition at line 48 of file cb_yaw_scan.hpp.

Referenced by onEntry(), and update().

◆ baseHeading_

float cl_px4_mr::CbYawScan::baseHeading_
private

Definition at line 50 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 55 of file cb_yaw_scan.hpp.

Referenced by onEntry(), and update().

◆ holdX_

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

Definition at line 52 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 53 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 54 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 57 of file cb_yaw_scan.hpp.

Referenced by onEntry(), and update().

◆ period_

float cl_px4_mr::CbYawScan::period_
private

Definition at line 49 of file cb_yaw_scan.hpp.

Referenced by onEntry(), and update().


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