SMACC2
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Private Attributes | List of all members
cl_nav2z::CbPureSpinning Struct Reference

#include <cb_pure_spinning.hpp>

Inheritance diagram for cl_nav2z::CbPureSpinning:
Inheritance graph
Collaboration diagram for cl_nav2z::CbPureSpinning:
Collaboration graph

Public Member Functions

 CbPureSpinning (double targetYaw_rads, double max_angular_yaw_speed=0.5)
 
void updateParameters ()
 
void onEntry () override
 
void onExit () override
 
- Public Member Functions inherited from smacc2::SmaccAsyncClientBehavior
template<typename TOrthogonal , typename TSourceObject >
void onOrthogonalAllocation ()
 
virtual ~SmaccAsyncClientBehavior ()
 
template<typename TCallback , typename T >
boost::signals2::connection onSuccess (TCallback callback, T *object)
 
template<typename TCallback , typename T >
boost::signals2::connection onFinished (TCallback callback, T *object)
 
template<typename TCallback , typename T >
boost::signals2::connection onFailure (TCallback callback, T *object)
 
void requestForceFinish ()
 
void executeOnEntry () override
 
void executeOnExit () override
 
void waitOnEntryThread (bool requestFinish)
 
template<typename TCallbackMethod , typename T >
boost::signals2::connection onSuccess (TCallbackMethod callback, T *object)
 
template<typename TCallbackMethod , typename T >
boost::signals2::connection onFinished (TCallbackMethod callback, T *object)
 
template<typename TCallbackMethod , typename T >
boost::signals2::connection onFailure (TCallbackMethod callback, T *object)
 
- Public Member Functions inherited from smacc2::ISmaccClientBehavior
 ISmaccClientBehavior ()
 
virtual ~ISmaccClientBehavior ()
 
ISmaccStateMachinegetStateMachine ()
 
std::string getName () const
 
template<typename SmaccClientType >
void requiresClient (SmaccClientType *&storage)
 
template<typename SmaccComponentType >
void requiresComponent (SmaccComponentType *&storage, bool throwExceptionIfNotExist=false)
 

Public Attributes

double yaw_goal_tolerance_rads_
 

Private Attributes

double targetYaw__rads
 
bool goalReached_
 
double k_betta_
 
double max_angular_yaw_speed_
 
rclcpp::Publisher< geometry_msgs::msg::Twist >::SharedPtr cmd_vel_pub_
 

Additional Inherited Members

- 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 ()
 
ISmaccStategetCurrentState ()
 
virtual rclcpp::Node::SharedPtr getNode () const
 
virtual rclcpp::Logger getLogger () const
 

Detailed Description

Definition at line 28 of file cb_pure_spinning.hpp.

Constructor & Destructor Documentation

◆ CbPureSpinning()

cl_nav2z::CbPureSpinning::CbPureSpinning ( double  targetYaw_rads,
double  max_angular_yaw_speed = 0.5 
)

Definition at line 29 of file cb_pure_spinning.cpp.

30: targetYaw__rads(targetYaw_rads),
31 k_betta_(1.0),
32 max_angular_yaw_speed_(max_angular_yaw_speed),
34{
35}

Member Function Documentation

◆ onEntry()

void cl_nav2z::CbPureSpinning::onEntry ( )
overridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 39 of file cb_pure_spinning.cpp.

40{
41 auto nh = this->getNode();
42 cmd_vel_pub_ = nh->create_publisher<geometry_msgs::msg::Twist>("/cmd_vel", rclcpp::QoS(1));
43
44 cl_nav2z::Pose * pose;
45 this->requiresComponent(pose);
46
47 geometry_msgs::msg::Twist cmd_vel;
48 goalReached_ = false;
49
50 geometry_msgs::msg::Pose currentPose = pose->toPoseMsg();
51
52 rclcpp::Rate loop_rate(10);
53 double countAngle = 0;
54 auto prevyaw = tf2::getYaw(currentPose.orientation);
55 while (rclcpp::ok() && !goalReached_)
56 {
57 tf2::Quaternion q;
58 currentPose = pose->toPoseMsg();
59 tf2::fromMsg(currentPose.orientation, q);
60 auto currentYaw = tf2::getYaw(currentPose.orientation);
61 auto deltaAngle = angles::shortest_angular_distance(prevyaw, currentYaw);
62 countAngle += deltaAngle;
63
64 prevyaw = currentYaw;
65 double angular_error = targetYaw__rads - countAngle;
66
67 auto omega = angular_error * k_betta_;
68 cmd_vel.linear.x = 0;
69 cmd_vel.linear.y = 0;
70 cmd_vel.linear.z = 0;
71 cmd_vel.angular.z =
72 std::min(std::max(omega, -fabs(max_angular_yaw_speed_)), fabs(max_angular_yaw_speed_));
73
74 RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "] delta angle: " << deltaAngle);
75 RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "] cummulated angle: " << countAngle);
76 RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "] k_betta_: " << k_betta_);
77
78 RCLCPP_INFO_STREAM(
79 getLogger(), "[" << getName() << "] angular error: " << angular_error << "("
80 << yaw_goal_tolerance_rads_ << ")");
81 RCLCPP_INFO_STREAM(
82 getLogger(), "[" << getName() << "] command angular speed: " << cmd_vel.angular.z);
83
84 if (fabs(angular_error) < yaw_goal_tolerance_rads_)
85 {
86 RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "] GOAL REACHED. Sending stop command.");
87 goalReached_ = true;
88 cmd_vel.linear.x = 0;
89 cmd_vel.angular.z = 0;
90 break;
91 }
92
93 this->cmd_vel_pub_->publish(cmd_vel);
94
95 loop_rate.sleep();
96 }
97
98 this->postSuccessEvent();
99}
virtual rclcpp::Logger getLogger() const
virtual rclcpp::Node::SharedPtr getNode() const
void requiresComponent(SmaccComponentType *&storage, bool throwExceptionIfNotExist=false)
rclcpp::Publisher< geometry_msgs::msg::Twist >::SharedPtr cmd_vel_pub_

References cmd_vel_pub_, smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getName(), smacc2::ISmaccClientBehavior::getNode(), goalReached_, k_betta_, max_angular_yaw_speed_, smacc2::SmaccAsyncClientBehavior::postSuccessEvent(), smacc2::ISmaccClientBehavior::requiresComponent(), targetYaw__rads, and yaw_goal_tolerance_rads_.

Here is the call graph for this function:

◆ onExit()

void cl_nav2z::CbPureSpinning::onExit ( )
overridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 101 of file cb_pure_spinning.cpp.

101{}

◆ updateParameters()

void cl_nav2z::CbPureSpinning::updateParameters ( )

Definition at line 37 of file cb_pure_spinning.cpp.

37{}

Member Data Documentation

◆ cmd_vel_pub_

rclcpp::Publisher<geometry_msgs::msg::Twist>::SharedPtr cl_nav2z::CbPureSpinning::cmd_vel_pub_
private

Definition at line 36 of file cb_pure_spinning.hpp.

Referenced by onEntry().

◆ goalReached_

bool cl_nav2z::CbPureSpinning::goalReached_
private

Definition at line 32 of file cb_pure_spinning.hpp.

Referenced by onEntry().

◆ k_betta_

double cl_nav2z::CbPureSpinning::k_betta_
private

Definition at line 33 of file cb_pure_spinning.hpp.

Referenced by onEntry().

◆ max_angular_yaw_speed_

double cl_nav2z::CbPureSpinning::max_angular_yaw_speed_
private

Definition at line 34 of file cb_pure_spinning.hpp.

Referenced by onEntry().

◆ targetYaw__rads

double cl_nav2z::CbPureSpinning::targetYaw__rads
private

Definition at line 31 of file cb_pure_spinning.hpp.

Referenced by onEntry().

◆ yaw_goal_tolerance_rads_

double cl_nav2z::CbPureSpinning::yaw_goal_tolerance_rads_

Definition at line 39 of file cb_pure_spinning.hpp.

Referenced by onEntry().


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