SMACC2
Public Member Functions | Public Attributes | Private Attributes | List of all members
sm_dance_bot_warehouse_3::cl_nav2zclient::CbPureSpinning Struct Reference

#include <cb_pure_spinning.hpp>

Inheritance diagram for sm_dance_bot_warehouse_3::cl_nav2zclient::CbPureSpinning:
Inheritance graph
Collaboration diagram for sm_dance_bot_warehouse_3::cl_nav2zclient::CbPureSpinning:
Collaboration graph

Public Member Functions

 CbPureSpinning (double targetYaw, 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)
 
- 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)
 

Public Attributes

double yaw_goal_tolerance_rads_
 

Private Attributes

double targetYaw_
 
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 ()
 
- Protected Member Functions inherited from smacc2::ISmaccClientBehavior
virtual void runtimeConfigure ()
 
virtual void onEntry ()
 
virtual void onExit ()
 
template<typename EventType >
void postEvent (const EventType &ev)
 
template<typename EventType >
void postEvent ()
 
ISmaccStategetCurrentState ()
 
virtual void dispose ()
 
virtual rclcpp::Node::SharedPtr getNode ()
 
virtual rclcpp::Logger getLogger ()
 

Detailed Description

Definition at line 34 of file cb_pure_spinning.hpp.

Constructor & Destructor Documentation

◆ CbPureSpinning()

sm_dance_bot_warehouse_3::cl_nav2zclient::CbPureSpinning::CbPureSpinning ( double  targetYaw,
double  max_angular_yaw_speed = 0.5 
)
inline

Member Function Documentation

◆ onEntry()

void sm_dance_bot_warehouse_3::cl_nav2zclient::CbPureSpinning::onEntry ( )
inlineoverridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 60 of file cb_pure_spinning.hpp.

61 {
62 auto nh = this->getNode();
63 cmd_vel_pub_ = nh->create_publisher<geometry_msgs::msg::Twist>("/cmd_vel", 1);
64
65 cl_nav2z::Pose* pose;
66 this->requiresComponent(pose);
67
68 geometry_msgs::msg::Twist cmd_vel;
69 goalReached_ = false;
70
71 geometry_msgs::msg::PoseStamped currentPose = pose->toPoseStampedMsg();
72
73 rclcpp::Rate loop_rate(10);
74 double countAngle = 0;
75 auto prevyaw = tf2::getYaw(currentPose.pose.orientation);
76 while(rclcpp::ok() && !goalReached_)
77 {
78 tf2::Quaternion q;
79 currentPose = pose->toPoseStampedMsg();
80 tf2::fromMsg(currentPose.pose.orientation, q);
81 auto currentYaw = tf2::getYaw(currentPose.pose.orientation);
82 auto deltaAngle = angles::shortest_angular_distance(prevyaw, currentYaw);
83 countAngle += deltaAngle;
84
85 prevyaw = currentYaw;
86 double angular_error = targetYaw_ - countAngle ;
87
88 auto omega = angular_error * k_betta_;
89 cmd_vel.linear.x = 0;
90 cmd_vel.linear.y = 0;
91 cmd_vel.linear.z = 0;
92 cmd_vel.angular.z =
93 std::min(std::max(omega, -fabs(max_angular_yaw_speed_)), fabs(max_angular_yaw_speed_));
94
95 RCLCPP_INFO_STREAM(getLogger(), "["<<getName() << "] delta angle: " << deltaAngle);
96 RCLCPP_INFO_STREAM(getLogger(), "["<<getName() << "] cummulated angle: " << countAngle);
97 RCLCPP_INFO_STREAM(getLogger(), "["<<getName() << "] k_betta_: " << k_betta_);
98
99 RCLCPP_INFO_STREAM(
100 getLogger(), "["<<getName() << "] angular error: " << angular_error << "("
101 << yaw_goal_tolerance_rads_ << ")");
102 RCLCPP_INFO_STREAM(
103 getLogger(),
104 "["<<getName() << "] command angular speed: " << cmd_vel.angular.z);
105
106 if (fabs(angular_error) < yaw_goal_tolerance_rads_)
107 {
108 RCLCPP_INFO_STREAM(
109 getLogger(), "["<<getName() << "] GOAL REACHED. Sending stop command.");
110 goalReached_ = true;
111 cmd_vel.linear.x = 0;
112 cmd_vel.angular.z = 0;
113 break;
114 }
115
116 this->cmd_vel_pub_->publish(cmd_vel);
117
118 loop_rate.sleep();
119 }
120
121 this->postSuccessEvent();
122 }
virtual rclcpp::Node::SharedPtr getNode()
void requiresComponent(SmaccComponentType *&storage)
rclcpp::Publisher< geometry_msgs::msg::Twist >::SharedPtr cmd_vel_pub_

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

Here is the call graph for this function:

◆ onExit()

void sm_dance_bot_warehouse_3::cl_nav2zclient::CbPureSpinning::onExit ( )
inlineoverridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 124 of file cb_pure_spinning.hpp.

125 {
126 }

◆ updateParameters()

void sm_dance_bot_warehouse_3::cl_nav2zclient::CbPureSpinning::updateParameters ( )
inline

Definition at line 56 of file cb_pure_spinning.hpp.

57 {
58 }

Member Data Documentation

◆ cmd_vel_pub_

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

Definition at line 42 of file cb_pure_spinning.hpp.

◆ goalReached_

bool sm_dance_bot_warehouse_3::cl_nav2zclient::CbPureSpinning::goalReached_
private

Definition at line 38 of file cb_pure_spinning.hpp.

Referenced by onEntry().

◆ k_betta_

double sm_dance_bot_warehouse_3::cl_nav2zclient::CbPureSpinning::k_betta_
private

Definition at line 39 of file cb_pure_spinning.hpp.

Referenced by onEntry().

◆ max_angular_yaw_speed_

double sm_dance_bot_warehouse_3::cl_nav2zclient::CbPureSpinning::max_angular_yaw_speed_
private

Definition at line 40 of file cb_pure_spinning.hpp.

Referenced by onEntry().

◆ targetYaw_

double sm_dance_bot_warehouse_3::cl_nav2zclient::CbPureSpinning::targetYaw_
private

Definition at line 37 of file cb_pure_spinning.hpp.

Referenced by onEntry().

◆ yaw_goal_tolerance_rads_

double sm_dance_bot_warehouse_3::cl_nav2zclient::CbPureSpinning::yaw_goal_tolerance_rads_

Definition at line 45 of file cb_pure_spinning.hpp.

Referenced by onEntry().


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