Skip to content

Commit 5903f83

Browse files
authored
Merge pull request #48 from AutoModality/BB-424/collision_avoidance
Bb 424/collision avoidance
2 parents 5f16dde + 62596e5 commit 5903f83

File tree

5 files changed

+41
-10
lines changed

5 files changed

+41
-10
lines changed

include/vb_util_lib/topics.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class am_topics
173173
static constexpr char CTRL_VX_RTL_ACTION[] = "/ctrl/vx/rtl_action";
174174
static constexpr char CTRL_VX_TARGET_CURRENT_ENU[] = "/ctrl/vx/target/currentENU";
175175
static constexpr char CTRL_VX_VEHICLE_CURRENTENU[] = "/ctrl/vx/vehicle/currentENU";
176-
static constexpr char CTRL_VX_VELOCITY[] = "/ctrl/vx/velocity";
176+
static constexpr char CTRL_VX_VELOCITY_CMD[] = "/ctrl/vx/velocity_cmd";
177177
static constexpr char CTRL_VX_WAYPOINT_NAV_ACTION [] = "/ctrl/vx/waypoint_nav_action";
178178

179179
static constexpr char CTRL_FEATURE_STATUS_LIST[] = "/ctrl/feature_status_list";

include/vb_util_lib/transformer.h

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@
88
#ifndef VISBOX_PACKAGES_COMMON_UTILS_UTIL_LIB_INCLUDE_VB_UTIL_LIB_TRANSFORMER_H_
99
#define VISBOX_PACKAGES_COMMON_UTILS_UTIL_LIB_INCLUDE_VB_UTIL_LIB_TRANSFORMER_H_
1010

11+
#include <string>
12+
1113
#include <ros/ros.h>
1214
#include <tf2/LinearMath/Quaternion.h>
1315
#include <tf2/LinearMath/Transform.h>
1416
#include <tf2_ros/transform_broadcaster.h>
1517
#include <tf2_ros/transform_listener.h>
1618
#include <geometry_msgs/Quaternion.h>
1719

20+
#include <Eigen/Geometry>
21+
#include <Eigen/StdVector>
22+
1823
namespace am
1924
{
2025
#define DEFAULT_TRANSFORM_WAIT 0.07
@@ -27,21 +32,26 @@ class Transformer
2732

2833
tf2_ros::Buffer& tfBuffer();
2934

30-
// Used to fetch the latest transform between two frames
31-
// Return true if it works and false otherwise
35+
/// Used to fetch the latest transform between two frames
36+
/// Return true if it works and false otherwise
3237
bool getTransform(const std::string target, const std::string source,
3338
geometry_msgs::TransformStamped& transform, double wait = -1.0, bool debug = false);
3439

35-
// Used to fetch the latest transform between two frames
36-
// Checks the initialized flag and will not call the lookup if it is true.
37-
// Otherwise it attempts to lookup the transform and set the initialized flag appropriately.
38-
// Return true if the transform is valid and false otherwise
40+
/// Used to fetch the latest transform between two frames
41+
/// Checks the initialized flag and will not call the lookup if it is true.
42+
/// Otherwise it attempts to lookup the transform and set the initialized flag appropriately.
43+
/// Return true if the transform is valid and false otherwise
3944
bool getTransform(bool& initialized_flag, const std::string target, const std::string source,
4045
geometry_msgs::TransformStamped& transform, double wait = -1.0, bool debug = false);
4146

42-
// Used to rotate the "orientation" coordinates by the "rotation" coordinates
47+
/// Used to rotate the "orientation" coordinates by the "rotation" coordinates
4348
void rotateOrientation(geometry_msgs:: Quaternion& orientation, geometry_msgs:: Quaternion& rotation, bool debug = false);
4449

50+
/// Used to rotate a vector from source frame to target frame.
51+
/// Returns false if failed,
52+
bool rotateVector(const std::string target_frame, const std::string source_frame,
53+
Eigen::Vector3d& target_vector, const Eigen::Vector3d& source_vector, bool debug = false);
54+
4555
private:
4656
// transform buffer management. Use factory creation method to auto create the tfBuffer
4757
// later make this a static to save space and make more efficient

src/vb_util_lib/kinematics.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ void Kinematics::setPosition(const ros::Time& update_time, double x, double y, d
206206
ROS_INFO("Kinematics Velocity standard[%s : %0.3f %0.3f, %0.3f] body[%s : %0.3f %0.3f, %0.3f]",
207207
frame_id_.c_str(), velLinear_[0], velLinear_[1], velLinear_[2],
208208
drone_ENU, vel_debug[0], vel_debug[1], vel_debug[2]);
209-
210209
}
211210
}
212211

src/vb_util_lib/topics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ constexpr char am_topics::CTRL_VX_PROXIMITY[];
103103
constexpr char am_topics::CTRL_VX_RTL_ACTION[];
104104
constexpr char am_topics::CTRL_VX_TARGET_CURRENT_ENU[];
105105
constexpr char am_topics::CTRL_VX_VEHICLE_CURRENTENU[];
106-
constexpr char am_topics::CTRL_VX_VELOCITY[];
106+
constexpr char am_topics::CTRL_VX_VELOCITY_CMD[];
107107
constexpr char am_topics::CTRL_VX_WAYPOINT_NAV_ACTION[];
108108

109109
constexpr char am_topics::CTRL_FEATURE_STATUS_LIST[];

src/vb_util_lib/transformer.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,26 @@ void Transformer::rotateOrientation(geometry_msgs::Quaternion& orientation, geom
9090
}
9191
}
9292

93+
bool Transformer::rotateVector(const std::string target_frame,
94+
const std::string source_frame, Eigen::Vector3d& target_vector,
95+
const Eigen::Vector3d& source_vector, bool debug) {
96+
97+
geometry_msgs::TransformStamped ts;
98+
if (!getTransform(target_frame, source_frame, ts, true))
99+
{
100+
ROS_ERROR("Kinematics::getLinearVelocity : No transform from[%s] to[%s]", source_frame.c_str(), target_frame.c_str());
101+
return false;
102+
}
103+
104+
Eigen::Quaterniond rot;
105+
rot.x() = ts.transform.rotation.x;
106+
rot.y() = ts.transform.rotation.y;
107+
rot.z() = ts.transform.rotation.z;
108+
rot.w() = ts.transform.rotation.w;
109+
110+
target_vector = rot * source_vector;
111+
112+
return true;
113+
}
114+
93115
} /* namespace am */

0 commit comments

Comments
 (0)