Heifu_simple_waypoint.cpp
Go to the documentation of this file.
2 
3 using namespace HSW;
4 
6  std::string ns = ros::this_node::getNamespace();
7 
8  // Subscribers
9  subPoseCommander = n.subscribe(ns + "/mission/setpoint", 10, &Heifu_simple_waypoint::cbPoseCommander, this);
10  subOdomUAV = n.subscribe(ns + "/mavros/local_position/pose", 10, &Heifu_simple_waypoint::cbOdomUAV, this);
11 
12  // Publishers
13  pubMissionStart = n.advertise < std_msgs::Empty > (ns + "/mission/start", 10);
14  pubMissionStop = n.advertise < std_msgs::Empty > (ns + "/mission/stop", 10);
15  pubDesiredPosition = n.advertise < geometry_msgs::PoseStamped > (ns + "/mavros/setpoint_position/local", 10);
16 
17  // Parameters
18  n.param<double>("paramNodeRate", paramNodeRate, 100.0);
19 }
20 
21 
23 
25  while (ros::ok()){
26  ros::spinOnce();
27  go.sleep();
28  }
29 }
30 
31 
32 void Heifu_simple_waypoint::cbOdomUAV(const geometry_msgs::PoseStampedConstPtr &msg)
33 {
34  currentPosition = *msg;
35 }
36 
37 //RETIRAR DO MAVROS
38 void Heifu_simple_waypoint::cbPoseCommander(const geometry_msgs::Pose& msg){
40  geometry_msgs::PoseStamped desiredPosition;
42 
43  double distanceRelation, dx, dy, dz, desiredAngle, desiredAngleRaw, desiredW, yawValid, aCat, oCat, positionX, positionY, positionZ;
44 
45  tf::Quaternion angleQuaternion;
46  //Calculate angle rotation to next waypoint
47  aCat = msg.position.x - currentPosition.pose.position.x;
48  oCat = msg.position.y - currentPosition.pose.position.y;
49  desiredAngleRaw = atan(oCat/aCat);
50  if (aCat < 0)
51  desiredAngleRaw = desiredAngleRaw - M_PI;
52 
53  angleQuaternion.setRPY(0, 0, desiredAngleRaw);
54  desiredAngle = angleQuaternion.getZ();
55  desiredW = angleQuaternion.getW();
56  desiredPosition.pose.position = currentPosition.pose.position;
57  desiredPosition.pose.orientation.w = desiredW;
58  desiredPosition.pose.orientation.z = desiredAngle;
59  //Whaiting correct angle to goes to the next point
60  do
61  {
62  ros::spinOnce();
63  pubDesiredPosition.publish(desiredPosition);
64  yawValid = fabs(fabs(currentPosition.pose.orientation.z) - fabs(desiredPosition.pose.orientation.z));
65  go.sleep();
66 
67  } while (yawValid >= 0.1);
68 
69  desiredPosition.pose.position.x = msg.position.x;
70  desiredPosition.pose.position.y = msg.position.y;
71  desiredPosition.pose.position.z = msg.position.z;
72 
73  //Start move the drone to position
74  do
75  {
76  ros::spinOnce();
77  desiredPosition.header.stamp = ros::Time::now();
78  pubDesiredPosition.publish(desiredPosition);
79  positionX = fabs(fabs(currentPosition.pose.position.x) - fabs(desiredPosition.pose.position.x));
80  positionY = fabs(fabs(currentPosition.pose.position.y) - fabs(desiredPosition.pose.position.y));
81  positionZ = fabs(fabs(currentPosition.pose.position.z) - fabs(desiredPosition.pose.position.z));
82  go.sleep();
83 
84  } while (positionX >= 0.1 && positionY >= 0.1 && positionZ >= 0.1);
85 
87 }
void cbPoseCommander(const geometry_msgs::Pose &msg)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void cbOdomUAV(const geometry_msgs::PoseStampedConstPtr &msg)
geometry_msgs::PoseStamped currentPosition
def go()
bool param(const std::string &param_name, T &param_val, const T &default_val) const
void publish(const boost::shared_ptr< M > &message) const
TFSIMD_FORCE_INLINE const tfScalar & getW() const
ROSCPP_DECL const std::string & getNamespace()
INLINE Rall1d< T, V, S > atan(const Rall1d< T, V, S > &x)
void setRPY(const tfScalar &roll, const tfScalar &pitch, const tfScalar &yaw)
ROSCPP_DECL bool ok()
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
bool sleep()
static Time now()
ROSCPP_DECL void spinOnce()


heifu_simple_waypoint
Author(s):
autogenerated on Tue Feb 2 2021 03:56:37